USE master;
GO
--查看数据库文件属性
select * from sys.database_files
--创建数据库
CREATE DATABASE SSBMonitor_GDEV
ON
( NAME = SSBMonitor_GDEV_Data,
FILENAME = 'D:\SSBMonitor_GDEV_Data.mdf',
SIZE = 100mB)
LOG ON
( NAME = SSBMonitor_GDEV_Log,
FILENAME = 'D:\SSBMonitor_GDEV_Log.ldf',
SIZE = 10mb) ;
go
--
--drop database SSBMonitor_GDEV
---------------备份覆盖数据库---------------------------
backup database SSBMonitor_GQC to disk='D:\DBA User\Jy85\SSBMonitor_GQC.bak' with init
-----------强制还原------------------------------------
use master
go
RESTORE DATABASE SSBMonitor_GDEV FROM DISK='D:\DBA User\Jy85\SSBMonitor_GQC.bak'
WITH MOVE 'SSBMonitor_QC_data' TO 'D:\DATA\SSBMonitor_GDEV\SQL\SSBMonitor_GDEV_Data.mdf',
MOVE 'SSBMonitor_QC_Log' to 'D:\DATA\SSBMonitor_GDEV\LOG\SSBMonitor_GDEV_Log.ldf',
REPLACE
----强制还原
RESTORE DATABASE SSB FROM DISK='D:\DBA\jy85\kk\SSB.bak'
WITH REPLACE
--BYDBA 1 参照嵌套事务模板 TRANSACTION
/*
BEGIN TRY
SET @TranCounter = @@TRANCOUNT
IF @TranCounter > 0
BEGIN
SAVE TRANSACTION preSavePoint;
END
ELSE
BEGIN
BEGIN TRANSACTION;
END
......
IF @TranCounter = 0 AND XACT_STATE() = 1
BEGIN
COMMIT TRANSACTION
END
END TRY
BEGIN CATCH
IF XACT_STATE() <> 0
BEGIN
IF @TranCounter = 0
BEGIN
ROLLBACK TRANSACTION
End
ELSE IF XACT_STATE() = 1
BEGIN
ROLLBACK TRANSACTION preSavePoint
End
END
END CATCH
*/
---游标使用模板
DECLARE @name NVARCHAR (4000)
DECLARE MyCur CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT top 10 name
from sys.tables
OPEN MyCur
FETCH NEXT FROM mycur INTO @name
WHILE @@fetch_status=0
BEGIN
print @name