Code:
-whether the library exists if exists (SELECT * from Master ...). sysdatabases where name=n ' library name ') print ' exists ' else print ' not EXISTS '-----------------to determine if the name of the table to be created exists if exists (SELECT * From dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Table name] and OBJECTPROPERTY (ID, N ' isusertable ') = 1)--Deletes table drop table [dbo].
[Table name] Go--------------------column exists 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 name drop column Row-------determine if a temporary table exists if object_id (' tempdb.dbo. #Test ') is not Nul L begin print ' exists ' end Else Begin print ' does not exist ' end-----------------determine whether the stored procedure name to be created exists if exists (SELECT * from Dbo.sysobjec TS WHERE id = object_id (N ' [dbo].[ Stored procedure name] and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)--Deletes the stored procedure drop procedure [dbo].
[Stored procedure name] Go-----------------Determine whether the name of the view to be created exists if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ View name] and OBJECTPROPERTY (ID, N ' isview ') = 1)--Deletes view drop view [dbo].
[View name] Go-----------------determine if the name of the function you want to create exists
if exists (select * from sysobjects where xtype= ' fn ' and name= ' function name ') if exists (SELECT * from dbo.sysobjects where id = o bject_id (N ' [dbo].[ Function name] and xtype in (n ' FN ', n ' IF ', n ' "TF '))--delete function drop functions [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 nam E= ' column name ') and name= ' table name '
SQL Judge exists
--Determine if the database exists if exists (SELECT * from Master. sysdatabases where name=n ' library name ') print ' exists ' else print ' not exists '-----------------determine whether the table name to be created exists if exists (SE Lect * FROM dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Table name] and OBJECTPROPERTY (ID, N ' isusertable ') = 1)--Deletes table drop table [dbo].
[Table name] Go-----------------to determine if a temporary table exists if object_id (' tempdb.dbo. #Test ') is not Null Begin print ' exists ' end Else begin p Rint ' does not exist '-----------------determines whether 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 procedure drop procedure [dbo].
[Stored procedure name] Go-----------------determine whether the name of the view to be created exists if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ View name] and OBJECTPROPERTY (ID, N ' isview ') = 1)--Deletes view drop view [dbo].
[View name] Go-----------------determine whether the function name to be created exists 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 wher e name= ' column name ') and name= ' table name '