当前位置: 数据库>sqlserver
sql脚本添加、删除表中字段的例子
来源: 互联网 发布时间:2014-08-29
本文导语: 用sql脚本添加删除表里面字段,代码: 代码示例: use asm ——–删除字段 if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN1′) ALTER TABLE [tb_log ] DROP COLUMN [COLUMN1] if exists (select * f...
用sql脚本添加删除表里面字段,代码:
代码示例:
use asm
——–删除字段
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN1′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN1]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN2′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN2]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN3′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN3]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN4′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN4]
———添加字段
alter table tb_log
add COLUMN5 nvarchar(200),
COLUMN6 int
——–删除字段
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN1′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN1]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN2′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN2]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN3′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN3]
if exists (select * from syscolumns where id =object_id(‘tb_log’) and name=‘COLUMN4′)
ALTER TABLE [tb_log ] DROP COLUMN [COLUMN4]
———添加字段
alter table tb_log
add COLUMN5 nvarchar(200),
COLUMN6 int