一、表不存在则创建:
if not exists (select * from sysobjects where id = object_id('mytab')
and OBJECTPROPERTY(id, 'IsUserTable') = 1)
create table mytab
(
id int,
age int ,
name varchar(max),
primary key (id,age)
)
go
二、列不存在则创建。
if not exists (select * from syscolumns where id=object_id('mytab') and name='columnname') alter table [mytab] add columnname nvarchar(max)