数据库分离 ALTER DATABASE DB SET SINGLE_USER WITH ROLLBACK IMMEDIATE EXEC sp_detach_db DB 附加 EXEC sp_attach_db @dbname = 'DB', @filename1 = 'H:\Medinice\DB.mdf',@filename2='H:\Medinice\DB_log.ldf' 查询是否存在DB数据库 SELE
数据库分离
ALTER DATABASE DB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC sp_detach_db DB
附加
EXEC sp_attach_db @dbname = 'DB', @filename1 = 'H:\Medinice\DB.mdf',@filename2='H:\Medinice\DB_log.ldf'
查询是否存在DB数据库
SELECT COUNT(*) FROM sys.databases WHERE NAME='DB'