这个不会整啊 举个例子吧 我忘数据库名字是aaa的数据库中的每个表添加一个字段bbb int类型如何写啊
追答use aaa
go
declare @obj_name varchar(128)
declare @sql varchar(2000)
declare cur_obj cursor for
select name from sys.objects where type = 'U'
open cur_obj
fetch cur_obj into @obj_name
while @@fetch_status = 0
begin
exec ( ' alter table ' + @obj_name + ' add bbb int ')
fetch cur_obj into @obj_name
end
close cur_obj
deallocate cur_obj