SQL SERVER可重复执行建表、建字段语句

/*
问题:type in (N'U') 中的N和U是什么意思?

答案:N是指Unicode编码,防止乱码;U是指用户表
*/
IF NOT EXISTS (SELECT * FROM sys.objects WHERE
object_id = OBJECT_ID(N'[dbo].[EVADELSECURITYPROJECT]') AND type in (N'U'))
BEGIN
CREATE TABLE EVADELSECURITYPROJECT
(
OID nvarchar(40) PRIMARY KEY,
DEALSECURITYID nvarchar(40) not null,
PROJECTID nvarchar(40) not null,
LASTUPDATETIME nvarchar(23)
)
END
else
BEGIN
print '系统中已存在EVADELSECURITYPROJECT,请检查!'
END
--判断表中列是否存在,不存在添加
IF NOT EXISTS (select * from sys.columns where object_id=OBJECT_ID(N'[dbo].[EVAASSPROJECT]') and name='CREATEUSERID')
BEGIN
alter table EVAASSPROJECT add CREATEUSERID NVARCHAR(40)
END
else
BEGIN
print 'EVAASSPROJECT表中已存在CREATEUSERID列,请检查!'
END

posted @ 2019-10-30 20:38  凌心缘  阅读(719)  评论(0编辑  收藏  举报