SQL Server transactional backup and restore instances

Source: Internet
Author: User

1 Create DatabaseMyDB2  UseMyDB3 Go4 Create TableAccount (5Idvarchar( -),6Namevarchar( -),7Balancefloat8 )9 GoTen Select *  from Account One  A Insert  intoAccount (ID, name, balance)Values('620101','Liyong', -) - Insert  intoAccount (ID, name, balance)Values('620106','Mali', -) - --INSERT into account (ID, name, balance) VALUES (' 620009 ', ' chenying ', +) the Insert  intoAccount (ID, name, balance)Values('646009','chenying', -) - --Delete from account where id = ' 620009 ' - Go - UpdateAccountSetBalance=Balance-  + whereId= '620101' + UpdateAccountSetBalance=Balance+  + whereId= '620106' - --msg 547, Level 16, State 0, line 1th + --The UPDATE statement conflicts with the CHECK constraint "Ck_blance". The conflict occurred in the database "MyDB", table "Dbo.account", column ' balance '.  A --statement has been terminated.  at  - Go - --ALTER TABLE account - --alter COlumn balance int - Go - Alter Table Account in Add constraintCk_blanceCheck(Balance>= 0) - Go to Alter Table Account + Drop constraintck_blance - --Set a transaction the --from Liyong to Mali and money . * begin Transaction $ UpdateAccountSetBalance=Balance-  + whereId= '620101'Panax Notoginseng if((SelectBalance output fromAccountwhereId= '620101')< 0) - begin the PRINT('Insufficient balance! '); + ROLLBACK; A End the Else + begin -     UpdateAccountSetBalance=Balance+  + whereId= '620106' $     Commit; $     PRINT('Transfer Success! '); - End - Go the sp_help - --Backup DeviceWuyiSp_addumpdevice'Disk','Xk_bak','D:\xk_bak' the --backing up the database - Backup DatabaseMyDB Wu  toXk_bak - --Restoring a database About Restore DatabaseMyDB from Disk = 'D:\xk_bak' $  with Replace;--cover

SQL Server transactional backup and restore instances

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.