在 SQL Server Management Studio 2008 中编辑数据行时是否会锁定数据行?

发布于 2024-12-22 14:19:51 字数 178 浏览 3 评论 0原文

当我右键单击 SQL Server Management Studio 中的表并选择“编辑前 200 行”时,我正在查看的数据在什么时候(如果有的话)会被锁定?

我的一位同事表示,以这种方式查看数据时,可以锁定数据行(我想当他说如果将光标放在一行上并开始编辑数据时)。

这是在此上下文中唯一一次可以锁定数据吗?

When I right-click on a table in SQL Server Management Studio and choose 'Edit top 200 rows', at what point, if ever, would the data that I'm looking at be locked?

A colleague of mine stated that when viewing data in this way, the data rows can be locked (I think when he said if you put a cursor on a row and start editing data).

Is this the only time the data can be locked in this context?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往事随风而去 2024-12-29 14:19:51

这不是真的。在一个窗口中运行此脚本(并保持其运行):

create table Tx (
    ID int not null,
    Val1 varchar(20) not null
)
go
insert into Tx (ID,Val1)
select 1,'abc'
go
set nocount on
while 1=1
begin
    update Tx set Val1 = CASE WHEN Val1='abc' then 'def' else 'abc' end
    RAISERROR('Updated',10,1) WITH NOWAIT
    WAITFOR DELAY '00:00:05'
end

每 5 秒,它会翻转 Val1 列的值,并在消息选项卡中打印 Updated(假设您设置为“网格中的结果”)。

然后,在 SSMS 的另一个实例中,打开 Tx 表并开始编辑其中的单行。观察脚本继续执行更新。

It's not true. Run this script in one window (and leave it running):

create table Tx (
    ID int not null,
    Val1 varchar(20) not null
)
go
insert into Tx (ID,Val1)
select 1,'abc'
go
set nocount on
while 1=1
begin
    update Tx set Val1 = CASE WHEN Val1='abc' then 'def' else 'abc' end
    RAISERROR('Updated',10,1) WITH NOWAIT
    WAITFOR DELAY '00:00:05'
end

Every 5 seconds, it flips the value of the Val1 column, and prints Updated in the messages tab (assuming you're set to "results in grid").

Then, in another instance of SSMS, open the Tx table and start editing the single row in there. Observe that the script continues to perform updates.

泡沫很甜 2024-12-29 14:19:51

它可以被锁定。在编辑面板中,尝试插入一行并违反主键约束。您将收到一条错误对话框弹出消息。当您阅读该消息时,该表将被锁定。如果您在未确认消息的情况下离开,该桌子将被无限期锁定。我刚刚通过 SSMS 2008R2 和 SSMS 2012 确认了这一点。

It can be locked. In the Edit Panel, try to insert a row and violate the Primary Key constraint. You will get an error dialog popup message. The table will now be locked while you are reading that message. If you walk away without confirming the message, that table will be locked indefinitely. I just confirmed this with both SSMS 2008R2 and SSMS 2012.

梦旅人picnic 2024-12-29 14:19:51

默认情况下,SSMS GUI 编辑器中的数据不会被锁定。

如果您进行更改并尝试保存,您将收到覆盖/丢弃等错误/警告。抱歉,我现在无法测试以查看确切的消息。

The data won't be locked by default in the SSMS GUI editor.

If you make changes and try to save, you'll get errors/warning ato overwrite/discard etc. I can't test right now to see the exact messages, sorry.

初雪 2024-12-29 14:19:51

事实并非如此。许多人会试图告诉你确实如此,但事实并非如此。经测试并确认。

It does not. Many people will try to tell you it does, however it does not. Tested and confirmed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文