declare @id int
declare @nob int
declare @tname nvarchar(100)
select id=identity(int,1,1),name into #t from dbname..sysobjects where xtype='U'
set @id=1
set @nob=(select max(id) from #t)
set @tname=(select name from #t where id=@id)
while @id<=@nob
begin
exec('alter table '+@tname+' drop column rowguid')
set @id=@id+1
set @tname=(select name from #t where id=@id)
end
exec sp_msforeachtable @command1=N'
declare @s nvarchar(4000),@tbname sysname
select @s=N'''',@tbname=N''?''
if exists(select 1 from syscolumns where id=object_id(@tbname) and name=''ddd'')
if exists(select 1 from (select count(*) as tcount from syscolumns
where id=object_id(@tbname)) a where a.tcount>1)
exec(N''alter table ''+@tbname+'' drop column ddd '')
else
exec(N''drop table ''+@tbname)'
ALTER procedure dropCol
@strcol varchar(100)
as
declare cur_opentab cursor
for
select a.name from sysobjects a,syscolumns b where a.id=b.id and OBJECTPROPERTY(a.id,'IsUserTable')=1 and b.name=@strcol
declare @strtab varchar(100),@str varchar(100)
set @str=''
set @strtab=''
open cur_opentab
fetch next from cur_opentab into @strtab
while @@fetch_status=0
begin
set @str='alter table '+@strtab+' drop column '+@strcol
print @str
exec(@str)
set @str=''
fetch next from cur_opentab into @strtab
end
close cur_opentab
deallocate cur_opentab
SELECT top 100 PERCENT
TABLE_CODE=d.name,
COLUMNS_CODE=a.name
FROM syscolumns a
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
where a.name='字段名'
order by a.id,a.colorder
得到所有的表名,再执行删除字段
declare @name varchar(20),@s varchar(1000)
declare kk cursor for
select bb=object_name(id) from syscolumns where objectproperty(id,'isUserTable')=1
and object_name(id)<>'dtproperties' and name='rowguid'
open kk
fetch next from kk into @name
while @@fetch_status=0
begin
set @s='alter table '+@name+' drop column rowguid '
exec(@s)
fetch next from kk into @name
end
close kk
deallocate kk
declare @id int
declare @nob int
declare @tname nvarchar(100)
select id=identity(int,1,1),name into #t from dbname..sysobjects where xtype='U'
set @id=1
set @nob=(select max(id) from #t)
set @tname=(select name from #t where id=@id)
while @id<=@nob
begin
exec('alter table '+@tname+' drop column rowguid')
set @id=@id+1
set @tname=(select name from #t where id=@id)
end