--whether the database existsIF exists(SELECT * fromMaster.. sysdatabasesWHEREName=N'Library name')PRINT 'exists'ELSE PRINT 'Not exists'-----------------determine if the name of the table to be created existsIF exists(SELECT * fromDbo.sysobjectsWHEREId= object_id(N'[dbo]. [Table name]') and ObjectProperty(ID, N'isusertable')= 1)--Delete a tableDROP TABLE [dbo].[Table name]GO-----------------determine if you want to create a temporary table for existenceIF object_id('tempdb.dbo. #Test') is not NullBegin PRINT 'exist'EndElseBegin PRINT 'does not exist'END-----------------determine if the stored procedure name to be created existsIF exists(SELECT * fromDbo.sysobjectsWHEREId= object_id(N'[dbo]. [Stored procedure name]') and ObjectProperty(ID, N'isprocedure')= 1)--To Delete a stored procedureDROP procedure [dbo].[Stored Procedure name]GO-----------------determine if the name of the view you want to create existsIF exists(SELECT * fromDbo.sysobjectsWHEREId= object_id(N'[dbo]. [View name]') and ObjectProperty(ID, N'Isview')= 1)--Delete a viewDROP VIEW [dbo].[View name]GO-----------------determine if the name of the function to be created existsIF exists(SELECT * fromDbo.sysobjectsWHEREId= object_id(N'[dbo]. [function name]') andXtypeinch(N'FN'N'IF'N'TF'))--Delete a functionDROP FUNCTION [dbo].[Name of function]GOIF col_length('Table name','Column Name') is NULLPRINT 'does not exist'SELECT 1 fromsysobjectsWHEREIdinch(SELECTId fromsyscolumnsWHEREName='Column Name') andName='Table name'
Reprint: http://www.bitscn.com/pdb/mssql/201010/191258.html
SQL judgment function exists, SQL judgment table exists, SQL determines if stored procedure exists, SQL Judge view exists