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)