判断表和列是否存在

判断表和列是否存在

   C = CHECK 约束 
   D = 默认值或 DEFAULT 约束 
   F = FOREIGN KEY 约束 
   L = 日志 
   FN = 标量函数 
   IF = 内嵌表函数 
   P = 存储过程 
   PK = PRIMARY KEY 约束(类型是 K) 
   RF = 复制筛选存储过程 
   S = 系统表 
   TF = 表函数 
   TR = 触发器 
   U = 用户表 
   UQ = UNIQUE 约束(类型是 K) 
   V = 视图 
   X = 扩展存储过程 

临时表

if object_id('tempdb..#tempTable') is not null   

--判断某个表或对象是否存在
if (not exists (select 1 from sys.objects where object_id = object_id('student') and xtype='u'))
if (not exists (select 1 from sysobjects where name = 'classes' and xtype='u'))
if (object_id('student', 'U') is null)
 
--判断该列名是否存在,如果不存在就添加
if (not exists (select 1 from information_schema.columns where table_name = 'student' and column_name = 'tel'))
if (not exists (select 1 from sys.columns where object_id = object_id('ICSubContract') and name = 'FIsSecond'))
	alter table ICSubContract add FIsSecond int NOT NULL DEFAULT ((0))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值