SQL Sever-t-sql determine if there are (databases, tables, stored procedures, constraints ...) and columns)

Source: Internet
Author: User
Tags scalar

If db_id (N ' DATABASENAME ') is not null
Use databasename--jump to the specified database
Go
If OBJECT_ID (n ' a ', n ' U ') is not null
drop Table A
Go
Note: A is a table and U represents a data table type
Type code similar to U, as shown below
Object type:
AF = aggregate function (CLR)
C = CHECK Constraint
D = DEFAULT (constrained or standalone)
F = FOREIGN KEY constraint
PK = PRIMARY KEY constraint
P = SQL Stored Procedure
PC = assembly (CLR) stored procedure
FN = SQL scalar function
FS = assembly (CLR) scalar functions
FT = assembly (CLR) table-valued function
R = Rule (Legacy, standalone)
RF = Replication filtering process
SN = synonym
TR = SQL DML Trigger
IF = SQL Inline Table-valued function
TF = SQL Table-valued function
U = table (user-defined type)
UQ = UNIQUE Constraint
V = view
X = Extended Stored Procedure
IT = Internal table

I've introduced sysobjects this system table before. Custom tables, stored procedures ..... will be stored in this form. So.....

  If col_length (,  C ' )  is not null              
Note: A is a table name
    C is the column  name
Or:
Select*from   syscolumns       id=object_id ( table name ' )    and   name= column name '              
Note: A description record of this column is returned, and there is no return null;

SQL Sever-t-sql determine if there are (databases, tables, stored procedures, constraints ...) and columns)

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.