当前位置:网站首页>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 在所涉及的服务器的管理分布式事务的完成;
边栏推荐
- 可扩展系统的“9不”原则和“5个”衡量维度
- "Five layer" architecture of cloud applications and services
- Documentation issues
- 以自动化赋能转型,飞鹤乳业加速迈向数字化!
- Several ways of sharing printers in LAN
- 解决跨域
- Scalable storage system (I)
- How the uni app automatically switches the requested address according to the environment
- Cannot edit in read-only editor if it appears in vscode
- 几个重要的物理概念
猜你喜欢

ambari SSLError: Failed to connect. Please check openssl library versions.

Custom controls under WPF and adaption of controls in Grid

Pycharm setting pseudo sublime color scheme

applicationContext.getBeansOfType 获取一个接口下所有实现类 执行方法或者获取实现类对象等 操作应用场景学习总结

以自动化赋能转型,飞鹤乳业加速迈向数字化!

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

KVM常用命令详解

How does the open-ended Hall current sensor help the transformation of DC power distribution?

资源管理、高可用与自动化(下)

错排兼排列组合公式
随机推荐
TypeError: 'module&#03…
Adder - Notes
Anaconda command usage
云应用、服务的“5层”架构
以自动化赋能转型,飞鹤乳业加速迈向数字化!
Does the applet image component not display pictures?
Typescript union type
黑体辐射初探
黑體輻射初探
MySQL 数据库的自动备份操作
图片的懒加载和预加载
大咖说·计算讲谈社|什么是东数西算要解决的核心问题?
机器人编程教育的市场竞争力
可扩展数据库(上)
leetcode:494.数组中添加加减运算符得到指定值的所有方法
开启创客教育造物学的领域
Simple implementation of cool GUI window based on WPF
A pit filling trip based on LNMP to build a personal website
「运维有小邓」监控文件及文件夹变更
Establishment of SSH Framework (Part I)