Methods for determining the existence of functions, stored procedures, etc. in SQL database

Source: Internet
Author: User

Below you introduce SQL under the use of a variety of resources to determine the existence of the code, the need for friends can refer to, I hope you learn SQL functions and databases can be helpful.
Whether the library exists
if exists (select * from Master.. sysdatabases where name=n ' library name ')
print ' exists '
Else
print ' NOT EXISTS '
---------------
--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)
--Delete Table
drop table [dbo]. [Table 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 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 '

This article transferred from: http://www.bitscn.com/pdb/mssql/201010/191258.html

Methods for determining the existence of functions, stored procedures, etc. in SQL database

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.