--exec add_column 'net_code','dddr',''
create proc add_column
@table varchar(100),--表名
@columns varchar(100),--欄位名
@type varchar(100)--資料型別(如不設定,預設為varchar(100))
as declare @sql varchar(3000),@type_code varchar(100)
if @type=''
begin
set @type_code='varchar(100)'
endset @sql='if not exists (select a.name as columnname
from syscolumns as a , sysobjects as b where a.id=b.id
and b.name='''+@table+'''
and a.name='''+@columns+''')
begin
alter table '+@table+' add '+@columns+'
'+@type_code+'
select a.name as columnname
from syscolumns as a , sysobjects as b where a.id=b.id
and b.name='''+@table+'''
end
else
begin
print ''字段已經存在!''
end '
exec(@sql)
在表中新增列
rel file list href file c 5cdocume 7e1 5cadmini 7e1 5clocals 7e1 5ctemp 5cmsohtml1 5c01 5cclip filelist.xml rel file list href file c 5cdocume 7e1 5ca...
sql新增 刪除表中的列
新增沒有預設值 alter table test add bazaartype char 1 有預設值的新增列 alter table test add bazaartype char 1 default 0 刪除沒有預設值的列 alter table test drop column bazaar...
sql新增 刪除表中的列
新增沒有預設值 alter table test add bazaartype char 1 有預設值的新增列 alter table test add bazaartype char 1 default 0 刪除沒有預設值的列 alter table test drop column bazaar...