SqlServer判断表、列不存在则创建
SqlServer判断表、列不存在则创建
一、表不存在则创建:
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)
SqlServer判断表、列不存在则创建
https://www.dearcloud.cn/2017/02/07/20200310-cnblogs-old-posts/20170207-SqlServer判断表、列不存在则创建/