Go to MSSQL statements used to determine whether a database object exists

Source: Internet
Author: User
1: -- determines whether the specified database exists. If yes, the database is deleted.

 
2:If Exists(SelectNameFromMaster.. sysdatabasesWhereNameIn('Db _ name'))
 
3:Drop DatabaseDb_name
 
4:Go 
 
5: 
 
6:-- Determines whether the specified stored procedure exists and deletes it if it exists.
7:If Exists(Select*FromSysobjectsWhereObjectproperty (object_id ('Proc _ name'),'Isprocedure') = 1)
 
8:Drop ProcedureProc_name
 
9:Go 
 
10: 
 
11:-- Determines whether the specified table exists. If yes, the table is deleted.
12:If Exists(Select*FromSysobjectsWhereObjectproperty (object_id ('Table _ name'),'Istable') = 1)
 
13:Drop TableTable_name
 
14:Go
 
15: 
 
16:-- Determines whether the specified custom function exists. If yes, delete it.
17:If Exists(Select*FromSysobjectsWhereObjectproperty (object_id ('Dbo. func_name'),'Isansinullson') = 1)
 
18:Drop FunctionDBO. func_name
 
19:Go 
 
20: 
 
21:-- Determines whether the specified temporary table exists and deletes it if it exists.
22:If Exists(Select*FromTempdb .. sysobjectsWhereNameLike '# Table_name %')

23:Drop Table# Table_name

 
24:Go
 
25: 

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.