判断常见的数据库数据结构对象是否存在

判断常见的数据对象是否存在
1判断表是否存在
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ms_ItemData_Select1]') AND type in (N'U'))
BEGIN
Drop table [ms_ItemData_Select1]
END
2判断视图是否存在
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cust_vwItemData_HR]') AND type in (N'V'))
BEGIN
Drop VIEW [cust_vwItemData_HR]
END
3判断存储过程是否存在
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ms_cust_PrepareSurvProp]') AND type in (N'P', N'PC'))
BEGIN
DROP PROCEDURE [dbo].[ms_cust_PrepareSurvProp] 
END
4判断索引是否存在
IF  EXISTS (SELECT name FROM sysindexes WHERE [name]='IX_cust_Hse_CaseFieldInterviewer')
BEGIN
DROP INDEX [IX_cust_Hse_CaseFieldInterviewer]  ON [dbo].[cust_Hse_Cases] 
END

5判断触发器是否存在
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[trig_bj_metadata_cust_Hse_Respondents_INS]') AND type in (N'TR'))
BEGIN
Drop TRIGGER [trig_bj_metadata_cust_Hse_Respondents_INS]
END

你可能感兴趣的:(数据结构,数据库,object,table,存储)