通过SQL脚本增加现有数据库中的字段

作者在 2008-10-10 10:49:34 发布以下内容
方法一:语句:alter table a add fieldname int;
说明:a 表示要增加到哪个数据表中的那个数据表的名字;fieldname是要增加的字段  int 增加字段的数据类型.
已经测试成功!
方法二:要在AA数据表中增加 class int(类型) 0(默认值)  和 admin  int 0 语法实现如下:
 
if not exists (select 1 from syscolumns where id=object_id('AA') and name='class')
alter table aa add class int default(0)
 
if not exists (select 1 from syscolumns where id=object_id('AA') and name='admin')
alter table aa add admin int default
 
此方法是先查询是否存在要增加的字段。不存在就增加。
数据库操作 | 阅读 5308 次
文章评论,共0条
游客请输入验证码