SQL Server transaction backup and restoration instance code (mandatory), SQL Server transaction

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.