SQL Server determines whether a database, table, stored procedure, or function exists

Source: Internet
Author: User

JudgmentDatabaseExist?
If exists (select * From SYS. databases where name = 'database name ')
Drop database [database name]

 

Check whether a table or Column exists in SQL Server to check whether the table exists.

1. Use System View: SYS. Tables

Select name from SYS. tables where name = 'tablaname' and type = 'U'

Type = 'U' is used to exclude stored procedures, views, and system tables. It refers to the user table user_table.

2. Use the System View: sysobjects
Select * From sysobjects where id = object_id ('usersubsyscenthistory _ null') and xtype = 'U'

Xtype = 'U' is used to exclude stored procedures, views, and system tables. It refers to the user table user_table.

 

Determine whether a stored procedure exists
If exists (select * From sysobjects where id = object_id (n' [stored procedure name] ') and objectproperty (ID, n' isprocedure') = 1)
Drop procedure [stored procedure name]

Determine whether a function exists
If object_id (n' function name') is not null
Drop function dnt_split

Determine whether full-text search is enabled for the database
Select databaseproperty ('database name', 'isfulltextenabled ')

Determine whether the full-text directory exists
Select * From sysfulltextcatalogs where name = 'full-text directory name'

Related Article

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.