1.添加默认约束
---1.设置默认值约束CRM_Personas_DataSourceAmount if exists(select * from sysobjects where name='DF_TestTable_FIM_Amount') alter table TestDB.[dbo].TestTable drop constraint DF_TestTable_FIM_Amount; go --给指定列添加默认约束 alter table TestDB.[dbo].TestTable add constraint DF_TestTable_FIM_Amount default(0) for FIM_Amount; go
2.执行带参数的存储过程pro_test
EXEC Pro_test 2021,1;
3.判断存储过程pro_test是否存在,存在则删除
if Exists(select name from sysobjects where NAME = 'Pro_test' and type='P') drop procedure Pro_test
4.判断触发器是否存在,存在则删除
if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Test]') and OBJECTPROPERTY(id, N'IsTrigger') = 1) drop trigger T_Test
5.判断试图是否存在,存在则删除
IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'v_test') DROP View v_test
7.判断函数是否存在,存在则删除
(注意此处的type 有两种,分别是'TF'-Table-valued Function 表值函数 或'FN'-Scalar-valued Function 标量值函数) if exists(select * from dbo.sysobjects where id = object_id(N'[dbo].[test_Fun]') and (type = 'FN' or type = 'TF')) DROP FUNCTION test_Fun
8.判断表t_table是否存在,存在删除
if (exists (SELECT * FROM dbo.sysobjects where id = object_id(N't_test')and OBJECTPROPERTY(id, N'IsUserTable') = 1)) DROP TABLE t_test
9.判断库testdb是否存在
if exists( select * from master.dbo.sysdatabases where dbid=db_ID( 'testdb' ) ) drop database testdb else print 'no exist testdb'
标签:TestTable,常用,exists,dbo,sql,test,where,id From: https://www.cnblogs.com/yanghongyan/p/17039672.html