http://sqlhints.com/2014/04/13/how-to-check-if-a-table-exists-in-sql-server/
DECLARE @dbname nvarchar(128) SET @dbname = N'database_name' IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE ('[' + name + ']' = @dbname OR name = @dbname)) BEGIN CREATE DATABASE TuoTuo; END GO
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'TheSchema' AND TABLE_NAME = 'TheTable')) BEGIN --Do Stuff END
IF EXISTS (SELECT name from sys.indexes WHERE name = N'ux_stations_station_name') DROP INDEX ux_stations_station_name ON stations; GO -- Create a unique index called ux_stations_station_name -- on the stations_staging.station_name table using the Name column. CREATE UNIQUE INDEX ux_stations_station_name ON stations (station_name); GO