雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網!

MsSql

當前位置:主頁 > 數(shù)據(jù)庫 > MsSql >

Sqlserver事務備份和還原的實例代碼(必看)

來源:本站原創(chuàng)|時間:2020-01-10|欄目:MsSql|點擊:

廢話不多說,直接上代碼

create database mydb
use mydb
go
create table account(
  id varchar(16),
  name varchar(16),
  balance float
)
go
select * from account

insert into account(id, name, balance) values('620101', 'liyong', 300)
insert into account(id, name, balance) values('620106', 'mali', 400)
--insert into account(id, name, balance) values('620009', 'chenying', 800)
insert into account(id, name, balance) values('646009', 'chenying', 800)
--delete from account where id = '620009'
go
update account set balance = balance - 1000 where id = '620101'
update account set balance = balance + 1000 where id = '620106'
--消息 547,級別 16,狀態(tài) 0,第 1 行
--UPDATE 語句與 CHECK 約束"CK_Blance"沖突。該沖突發(fā)生于數(shù)據(jù)庫"mydb",表"dbo.account", column 'balance'。
--語句已終止。

go
--alter table account
--alter COlumn balance int
go
alter table account
add constraint CK_Blance check(balance >= 0)
go
alter table account
drop constraint CK_Blance
--定一個事務
--從liyong扣錢往mali加錢
begin transaction
update account set balance = balance - 1000 where id = '620101'
if((select balance output from account where id = '620101') < 0)
begin
PRINT('余額不足!');
ROLLBACK;
end
else
begin
  update account set balance = balance + 1000 where id = '620106'
  commit;
  PRINT('轉賬成功!');
end
go
sp_help
--備份設備
sp_addumpdevice 'disk', 'xk_bak' ,'d:\xk_bak'
--備份數(shù)據(jù)庫
backup database mydb
to xk_bak
--還原數(shù)據(jù)庫
restore database mydb from disk = 'd:\xk_bak'
with replace; --覆蓋

以上這篇Sqlserver事務備份和還原的實例代碼(必看)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持我們。

上一篇:sql server 2008 數(shù)據(jù)庫管理系統(tǒng)使用SQL語句創(chuàng)建登錄用戶步驟詳解

欄    目:MsSql

下一篇:SQL Server 公用表表達式(CTE)實現(xiàn)遞歸的方法

本文標題:Sqlserver事務備份和還原的實例代碼(必看)

本文地址:http://www.jygsgssxh.com/a1/MsSql/10482.html

網頁制作CMS教程網絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有