SQL judgment function exists, SQL judgment table exists, SQL determines if stored procedure exists, SQL Judge view exists

Source: Internet
Author: User

--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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.