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