当前位置:网站首页>sqlserver 数据库之事物使用入门 案例
sqlserver 数据库之事物使用入门 案例
2022-06-28 03:16:00 【济南医疗小程序状元】
1. 开始事务
在 SQL Server 数据库中,通过语句 BEGIN TRANSACTION 来标记一个显示本地事务的起始点;
一个显式事务必须通过 BEGIN TRANSACTION 语句开始,从连接上一个 SQL Server 数据库服务器的那一刻开始,在此连接上执行的所 T-SQL 语句都是事务的一部分,知道事务结束为止,能使用 GEGIN TRANSACTION 语句来开启一个事务;
-- 学生表
select * from Student
--1 显式事务定义
select * from student where ID=1
begin transaction update_0 --定义事物语句
update student set chinesescores=97 where ID=1 --更新指定数据
commit transaction update_0 --结束事物语句
select * from student where ID=1;效果

上述例子中,使用 BEGIN TRANSACTION 语句定义了一个 update_O 的事务,事务执行时对表 O 中的数据进行了更新,使用 COMMIT TRANSACTION 语句指定事务结束;
注意: 执行 BEGIN DISTRIBUTED TRANSACTION 语句的服务器是事务的创建者,并控制事务的完成;当连接发出后续 COMMIT TRANSACTION 或 ROLLBACK TRANSACTION 语句时,主控服务器请求 MS DTC 在所涉及的服务器的管理分布式事务的完成;
边栏推荐
- 指针链表
- Does the applet input box flash?
- Extensible database (Part 2)
- Arrangement of basic electrical knowledge (I)
- No result defined&nbsp…
- 荣耀v8 真机调试时不显示 Logcat 日志的解决办法
- STM32 peripheral SDIO and SD card configuration
- 数字电路学习笔记(一)
- A solution to the inefficiency of setting debug mode in developing flask framework with pychar
- What is the difference between slice and array in go question bank 12?
猜你喜欢

Resource management, high availability and automation (Part 2)

Summary of the use of composition API in the project

"9 No" principle and "5 measurement dimensions" of extensible system

Extensible database (I)

基于 LNMP 搭建个人网站的填坑之旅

开启创客教育造物学的领域

leetcode:单调栈结构(进阶)

MySQL configuration of database Series F5 load balancing

Extensible database (Part 2)

Arrangement of basic electrical knowledge (II)
随机推荐
Custom controls under WPF and adaption of controls in Grid
Go 数据类型篇(四)之浮点型与复数类型
可扩展存储系统(上)
Paging query optimization in MySQL of database Series
[graduation season] graduate summary
测不准原理
TypeError: 'module&#03…
Lost connection repair: make "hide and seek" nowhere to hide
第14章 AC-DC电源前级电路 笔记一
力扣每日一题-第29天-219.存在重复元素Ⅱ
Unity C# 网络学习(十一)——自定义协议生成工具
可扩展数据库(下)
指针链表
使用信号分析器
继承
失联修复:让“躲猫猫”无处可藏
Object floating tool
MySQL 主从复制、分离解析
电子地图坐标系统研究整理
错排兼排列组合公式