用于asp.net还原与恢复SqlServer数据库的KillSpid存储过程
CREATE PROCEDURE KillSpid(@dbName varchar(20)) AS BEGIN DECLARE @sql nvarchar(500) DECLARE @spid int SET @sql=‘DECLARE getspid CURSOR FOR SELECT spid FROM sysprocesses WHERE dbid=db_id(‘‘‘[email protected]+‘‘‘)‘ EXEC (@sql) OPEN getspid FETCH next FROM getspid INTO @spid WHILE @@fetch_status<>-1 BEGIN EXEC(‘kill ‘[email protected]) FETCH next FROM getspid INTO @spid END CLOSE getspid DEALLOCATE getspid END GO
恢复数据库:
关键字://Alter Database 被恢复的数据库名 Set Offline with Rollback immediate;
restore database 被恢复的数据库名 from disk = ‘备份文件路径‘;
//Alter Database 被恢复的数据库名 Set OnLine With rollback Immediate;
时间: 2024-10-13 01:08:18