A view
Views are SQL statements that are stored in queries in the database.
A view is a table that is exported from one or more tables or views, and is a virtual table that can only be queried on the views and cannot be added, deleted, or changed.
Modify the view to be modified in the corresponding base table, and the modifications will automatically react to the views
To create a view:
Create View view name
as
SQL query statements--duplicate columns cannot appear in a view
Usage of the View:
SELECT * FROM view name
Two-business
Guarantee the complete implementation of the process, like the bank to take money, first in your account to deduct money, and then deposited in other people's account, but from your account to deduct money, suddenly the network broke, the other party did not receive the money, then your money is not, and other people's money did not add, business in order to prevent such a situation.
Format
BEGIN Tran--where the process begins
----------
If @ @error > 0
Begin
Rollback TRAN--rollback TRANSACTION, to begin TRAN position, as never happened
End
Else
Begin
Commit Tran-Commit a transaction, no problem, then just commit
End
Examples
BEGIN Tran--Open Transaction Declare @tran_errorint; --Storage ErrorSet@tran_error =0; --default no error update FruitSetNumbers = numbers-1 whereids='k002'Set@tran_error = @tran_error +@ @ERROR; update LoginSetaccount=account-1 whereUsername='Wangwu'Set@tran_error = @tran_error +@ @ERROR; insert into Orders values ('d002','Wangwu','2016-8-7')Set@tran_error = @tran_error +@ @ERROR; insert into OrderDetails values ('d002','k002',Ten)Set@tran_error = @tran_error +@ @ERROR;if@tran_error >0begin rollback Tran--Roll back the transaction, to the position of Begin Tran, when it never happened. EndElseBegin commit Tran--commit the transaction, no problem, then just commit to submit end
View Code
SQL Server T-SQL view transactions