SQL Server transaction backup and restoration instance code (mandatory), SQL Server transaction
Let's just talk about the code.
Create database mydbuse mydbgocreate table account (id varchar (16), name varchar (16), balance float) goselect * from accountinsert into account (id, name, balance) values ('000000', 'liyun', 620101) insert into account (id, name, balance) values ('000000', 'mali', 300) -- insert into account (id, name, balance) values ('000000', 'chenying ', 620009) insert into account (id, name, balance) values ('20140901 ', 'chening', 800) -- delete from account where id = '000000' goupdate account set balance = balance-620009 where id = '000000' update account set balance = balance + 1000 where id = '000000' -- message 547, level 16, status 0, and 1st rows -- the UPDATE statement conflicts with the CHECK constraint "CK_Blance. This conflict occurs in the Database "mydb", table "dbo. account", column 'balance '. -- The statement has been terminated. Go -- alter table account -- alter COlumn balance intgoalter table accountadd constraint CK_Blance check (balance> = 0) goalter table accountdrop constraint CK_Blance -- set a transaction -- deduct money from liyong to add money to mali begin transactionupdate account set balance = balance-1000 where id = '20160301' if (select balance output from account where id = '000000 ') <0) beginPRINT ('Insufficient balance! '); ROLLBACK; endelsebegin update account set balance = balance + 1000 where id = '000000' commit; PRINT ('transfer successful! '); Endgosp_help -- backup device sp_addumpdevice 'disk', 'xk _ Bak', 'd: \ xk_bak '-- backup database mydbto xk_bak -- restore database mydb from disk = 'd: \ xk_bak' with replace; -- Overwrite
The above SQL Server transaction backup and restoration instance code (required) is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support for the customer's house.