1.SELECT * FROM SYSOBJECTS WHERE TYPE='U' AND NAME='你要找的表名'
2.alter table 你的表名 drop COLUMN 你要刪除的字段(如果該字段有約束應該先刪除約束再刪除字段)

解决方案 »

  1.   

    sp_msforeachtable 'if exists(select 1 from syscolumns where object_id(''?'')=id and name=''要删除的字段名'')
    alter table ? drop column 要删除的字段名'
      

  2.   

    --或者用游标declare tb cursor for 
    select 'alter table ['+object_name(id)+'] drop column ['+name+']'
    from syscolumns
    where objectproperty(id,'IsUserTable')=1
    and object_name(id)<>'dtproperties' 
    and name='id'
    declare @s varchar(1000)
    open tb
    fetch next from tb into @s
    while @@fetch_status=0
    begin
    exec(@s)
    fetch next from tb into @s
    end
    close tb
    deallocate tb
      

  3.   

    declare tb cursor for 
    select 'alter table ['+object_name(id)+'] drop column ['+name+']'
    from syscolumns
    where objectproperty(id,'IsUserTable')=1
    and object_name(id)<>'dtproperties' 
    and name='id'  --id为你的删除的字段名
    declare @s varchar(1000)
    open tb
    fetch next from tb into @s
    while @@fetch_status=0
    begin
    exec(@s)
    fetch next from tb into @s
    end
    close tb
    deallocate tb
      

  4.   

    这个简单declare @TableName char(100)
    select @TableName=Table_Name from information_schema.columns where column_name='字段名'
    exec('alter table '+ @TableName + ' drop column 字段名')
      

  5.   

    declare @TableName varchar(100)
    while exists(select * from syscolumns a,sysobjects b where a.id=b.id and a.name='字段名')
    begin
      select @TableName=b.name from syscolumns a,sysobjects b where a.id=b.id and a.name='字段名'
      exec('alter table '+ @TableName + ' drop column 字段名')
    end