In the SQL name, if not exists is if not present, if exists is if present.
Below you learn the use of both.
A to determine if the database does not exist
code example: If NOT EXISTS (SELECT * from sys.databases WHERE name = ' database_name ')
b, when the judgment table does not exist
code example: If NOT EXISTS (SELECT * from sysobjects where id = object_id (' table_name ') and OBJECTPROPERTY (ID, ' isusertable ') = 1)
C, the Judgment column does not exist
code example: If NOT EXISTS (SELECT * from syscolumns where id=object_id (' table_name ') and Name= ' column_name ')
if exists (SELECT * from syscolumns where id=object_id (' table name ') and name= ' column name ')
ALTER TABLE name drop column name if exists (SELECT * from syscolumns where id=object_id (' table name ') and name= ' column name ')
ALTER TABLE table name drop column name
When the table is not saved, I can do the creation of the database, create the table, add columns, you can execute the corresponding SQL statements;
And if exists the same judgment, first of all to determine whether the query results exist, if there is execution judgment after the statement, query database, table, column method is the same;
If exists and if not EXISTS keyword usage