SQL

Sql Server: Check if Exists

In my day job I am always writing sql DDL statements, such as, creating tables, indexes, keys, constraints, store procedures, etc. The problem I have is that I can’t remember which way to test for existence of each object type. Some, like tables and stored procedures, only require adding the IF [NOT] EXISTS to the CREATE statement. But indexes, keys, constraints, schemas, and database require doing a lookup inside of a IF NOT EXISTS ( ) BEGIN ‘create/drop’ END query structure.

Continue reading