create  proc [dbo].[add_column] @table varchar(100),--表名 
@columns varchar(100),--字段名 
@type varchar(100)--数据类型(如不设置,默认为varchar(100)) as 
declare @sql varchar(3000),@type_code varchar(100) if @type='' 
    set @type_code='varchar(100)' 
else
    set @type_code=@type
set @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+' 
PRINT ''字段!'+@columns+'添加成功'' 
END 
ELSE 
BEGIN 
PRINT ''字段'+@columns+'已经存在!'' 
END '
--print @sql 
exec(@sql) 
go
select * from ta
exec [add_column] 'ta','col','int'
select * from ta
drop proc [add_column]
ID          列1
----------- -----
1           1,3
2           1,2,3
3           2,4,5
4           3,4,5
5           ,3,,4字段!col添加成功
ID          列1    col
----------- ----- -----------
1           1,3   NULL
2           1,2,3 NULL
3           2,4,5 NULL
4           3,4,5 NULL
5           ,3,,4 NULL