In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "introduction of affairs in Sql Server". In daily operation, I believe many people have doubts about the introduction of affairs in Sql Server. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "introduction of affairs in Sql Server"! Next, please follow the editor to study!
1. What is a transaction: a transaction is an indivisible working logic unit, and it is used as the smallest control unit when performing concurrent operations on a database system.
All the database operation commands he contains are submitted or undone to the department as a whole, and this set of database operation commands are either executed or not executed.
Transaction is an indivisible working logic unit.
two。 The classification of transactions. According to the way transactions start and execute, transactions can be divided into three categories: ① display transactions: also known as user-defined or user-specified transactions, that is, transactions that can be explicitly defined to start and end. Distributed transactions belong to the display transaction ② autocommit transaction: the default transaction management mode. If a statement completes successfully, the statement is committed; if an error is encountered, the statement is rolled back. ③ implicit transaction: when the connection operates in this mode, sql automatically starts a new transaction after the current transaction is committed or rolled back. There is no need to describe the beginning of the transaction, just commit or roll back each transaction. It generates a continuous chain of transactions.
3. Statement beginning of transaction: BEGIN TRANSACTION (tran) commit thing: COMMIT TRANSACTION rollback transaction: ROLLBACK TRANSACTION
Note: once the transaction is committed or rolled back, the transaction ends
4. Four characteristics of a transaction: ① atomicity (Atomicity): all elements in a transaction are committed or rolled back as a whole, which is unbreakable, and the transaction is a complete operation. ② consistency (Consistemcy): when a thing is completed, the data must be consistent, that is, the data in the data store must be consistent with the data in the data store before the thing begins. Ensure that the data is intact. ③ isolation (Isolation): multiple transactions that modify data are isolated from each other. This indicates that transactions must be independent and should not affect other transactions in any way. ④ persistence (Durability): after the transaction is completed, its impact on the system is permanent, and the change is retained even in the event of a system failure, actually modifying the database.
5. Example
@ @ error: global variable, record the error number, and accumulate the error copy code as follows: begin tran-- start transaction declare @ errorsum int-- defines the number of errors recorded by variables set @ errorsum=0-- the number of errors defaults to 0update dbo.OfficeRent set CreateTime=GETDATE () where Id=2-- whether there are cumulative errors in the persistent Sql statement set @ errorsum+=@@ERROR--
Update dbo.OfficeRent set Hits+=1 where Id=2-whether there are cumulative errors in the persistent Sql statement set @ errorsum+=@@ERROR--
If @ errorsum0-- to determine whether there is an error begin
Print 'there is an error, rollback'
Error occurred in rollback tran--, roll back endelsebegin
Print 'successful, commit' commit tran-- commit transaction end
6. Transactions are not available for the following operations
Create database create database modify database alter database delete database drop database restore database restore database load database load database backup log file backup log recovery log file restore log update statistics update statitics authorization operation grant replication transaction log dump tran disk initialization disk init update system configuration reconfigure after using sp_configure
At this point, the study of "introduction to affairs in Sql Server" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.