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  

 

相关文章:

  • 2021-12-08
  • 2021-12-28
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-10-27
猜你喜欢
  • 2022-12-23
  • 2021-08-10
  • 2021-12-07
  • 2021-06-13
  • 2021-11-11
相关资源
相似解决方案