例: if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) CREATE TABLE t (...) GOif not exists (select * from dbo.syscolumns where id = object_id(N'[dbo].[t]') and name = 'col') ALTER TABLE t ADD col varchar(10) null GO
alter table tablename add colname1 字段类型 alter table tablename add colname2 字段类型 alter table tablename add colname3 字段类型 . . . . . alter table tablename add colnameN 字段类型
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE t (...)
GOif not exists (select * from dbo.syscolumns where id = object_id(N'[dbo].[t]') and name = 'col')
ALTER TABLE t ADD col varchar(10) null
GO
alter table tablename add colname2 字段类型
alter table tablename add colname3 字段类型
.
.
.
.
.
alter table tablename add colnameN 字段类型
如果非要not null,就先插入值,再改成not null。
具体咋做,看联机帮助吧。