T-SQL – Control if a database exists before creating or dropping it

Send Us a Sign! (Contact Us!)
Epub Text

To test if I can drop the [gs database]:

IF db_id('Database1') is not null
DROP DATABASE Database1

[tweet]

On the other case, to test if I can create the database:

IF db_id('Database1') is null
CREATE DATABASE Database1

SOURCE

LINK (dbaspot.com)

LANGUAGE
ENGLISH

1 thought on “T-SQL – Control if a database exists before creating or dropping it”

Comments are closed.