SQL Server 和可能的竞争条件
假设我使用 ASP.NET 编写一个使用 SQL Server 数据库的网站。我的脚本执行如下操作:
-- The meaning of the SQL doesn't matter
UPDATE t1 SET [c1]=1 WHERE [id]=3;
UPDATE t1 SET [c2]=0 WHERE [id]=4;
UPDATE t1 SET [c1]=2 WHERE [id]=7;
当上面的 SQL 运行时,另一个用户登录到同一页面并同时运行相同的 SQL 脚本。 SQL Server 是否确保多个同时执行的 SQL 命令不会混合在一起并导致竞争条件?
Say, if I write a web site using ASP.NET that uses the SQL Server database. My script executes something like this:
-- The meaning of the SQL doesn't matter
UPDATE t1 SET [c1]=1 WHERE [id]=3;
UPDATE t1 SET [c2]=0 WHERE [id]=4;
UPDATE t1 SET [c1]=2 WHERE [id]=7;
And while the SQL above is running another user logs in to the same page and runs the same SQL script at the same time. Does SQL Server ensure that multiple simultaneous SQL execute commands won't get mixed together and cause a race condition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,除非您包装交易:
No, not unless you wrap in a transaction:
除非你明确锁定桌子,否则我不会这么认为。
Unless you explicetly lock the tables I won't think so.