存在 INNER JOIN 时锁定语句将无法编译
我正在 SQL Server 2008 中编写一个存储过程。以下代码:
SELECT @LastAccessed = cs.LastAccessed
FROM [int].ClientSessions AS cs INNER JOIN
dbo.Profiles AS p ON cs.ProfileID = p.ProfileID
WITH (XLOCK, ROWLOCK)
WHERE (p.ClientID = @ClientID)
...不会编译,在 XLOCK 处声明语法错误。
如果我删除 INNER JOIN 语句(这是不可能的,因为我需要连接),那么 XLOCK 就可以了。我不明白问题是什么。
注意:我只想锁定 [int].ClientSessions 表,所以我意识到这可能不是最好的方法。
I'm writing a stored proc in SQL Server 2008. The following code:
SELECT @LastAccessed = cs.LastAccessed
FROM [int].ClientSessions AS cs INNER JOIN
dbo.Profiles AS p ON cs.ProfileID = p.ProfileID
WITH (XLOCK, ROWLOCK)
WHERE (p.ClientID = @ClientID)
...won't compile, stating a syntax error at XLOCK.
If I remove the INNER JOIN statement (which is impossible because I need the join), then it's fine with the XLOCK. I don't see what the issue is.
Note: I only want to lock the [int].ClientSessions table, so I realize this may not be the best approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
WITH (XLOCK, ROWLOCK)
放在as cs
/as p
语句之后。类似
查看表提示 (Transact-SQL)
You have to put the
WITH (XLOCK, ROWLOCK)
after theas cs
/as p
statement.Something like
Have a look at Table Hints (Transact-SQL)