/*----------------------------------------*/ --@filename: target bak name --@path: target restore directory end by '/' /*----------------------------------------*/
declare @pathnvarchar(200) declare @filename nvarchar(400) SET @path='D:\backup\' SET @filename=@path+'\MobileSaleStatMain.bak'
RESTOREDATABASE MobileSaleStatMain FROM DISK = @filename withreplace, move'MobileSaleStatMain'to'D:\MSSQL\Data\MobileSaleStatMain\MobileSaleStatMain.mdf', move'MobileSaleStatMain_log'to'D:\MSSQL\Data\MobileSaleStatMain\MobileSaleStatMain_log.ldf', recovery GO
USE [MobileSaleStatMain] GO IFEXISTS (SELECT * FROM sys.database_principals WHEREname = N'mobilesalestatmain') DROPUSER [mobilesalestatmain] GO
USE [MobileSaleStatMain] SELECT s.name FROM sys.schemas s WHERE s.principal_id = USER_ID('mobilesalestatmain'); --modidy user ALTER AUTHORIZATION ONSCHEMA::db_owner TO dbo; GO