--whether the library exists
if exists (select * from Master.. sysdatabases where Name=n ')
print ' exists '
Else
print ' NOT EXISTS '
--Determine if the name of the table to be created exists, delete it
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Table name] ') and OBJECTPROPERTY (ID, N ' isusertable ') = 1)
--Delete Table
drop table [dbo]. [Table name]
GO
--Determine if a table's columns exist
IF col_length (' table name ', ' column name ') is NULL
PRINT ' NOT EXISTS '
ELSE
PRINT ' exists '
ALTER TABLE name DROP constraint default value name
Go
ALTER TABLE table name drop column name
Go
--Determine if you want to create a temporary table exists
If object_id (' tempdb.dbo. #Test ') is not Null
Begin
print ' exists '
End
Else
Begin
print ' does not exist '
End
--Determine if the stored procedure name to be created exists
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Stored procedure name] ') and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
--Delete stored procedures
drop procedure [dbo]. [Stored procedure name]
GO
--Determine if the name of the view you want to create exists
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ View name] ') and OBJECTPROPERTY (ID, N ' isview ') = 1)
--Delete View
Drop view [dbo]. [View name]
GO
--Determine if the name of the function to be created exists
if exists (select * from sysobjects where xtype= ' fn ' and name= ' function name ')
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Function name] ') and xtype in (n ' FN ', n ' IF ', n ' TF '))
--delete function
Drop function [dbo]. [function name]
GO
/*
If Col_length (' Table name ', ' column name ') is null
print ' does not exist '
Select 1 from sysobjects where ID in (select ID from syscolumns where name= ' column name ') and name= ' table name '
*/
If Col_length (' Biu8_gl_accvouch ', ' iperiod ') is null
print ' does not exist '
Select 1 from sysobjects where ID in (select ID from syscolumns where name= ' Iperiod ') and name= ' Biu8_gl_accvouch '
IF EXISTS (SELECT * from sys.check_constraints WHERE object_id = object_id (N ' [dbo].[ Ck_ constraint name] ') and parent_object_id = object_id (N ' [dbo].[ Table name])
ALTER TABLE [dbo]. [Table name] DROP CONSTRAINT [ck_ constraint name]
Summary of methods for determining whether an object exists in a SQL Server database