【发布时间】:2014-09-16 14:44:09
【问题描述】:
我有以下疑问:
SELECT UsersAccountLink.UserId, Customer.Account.AccountNumber, Web.Customer.Name, Web.Customer.Street, UsersAccountLink.AccountId
FROM UsersAccountLink INNER JOIN
Web.Customer ON UsersAccountLink.AccountId = Web.Customer.AccountId LEFT OUTER JOIN
Customer.Account ON UsersAccountLink.AccountId = Customer.Account.AccountId
WHERE (Customer.Account.AccountNumber IS NULL)
Order by Name
我需要将选择更改为并更新。如果 Customer.Account.AcountNumber 为 NULL,我需要将 UsersAccountLink.UserId 设置为空 guid。
我怀疑我有这个权利,所以这就是我想出的:
UPDATE
UsersAccountLink
SET
UsersAccountLink.AccountId = '00000000-0000-0000-0000-000000000000'
FROM
UsersAccountLink
INNER JOIN
Web.Customer ON UsersAccountLink.AccountId = Web.Customer.AccountId
LEFT OUTER JOIN
Customer.Account ON UsersAccountLink.AccountId = Customer.Account.AccountId
WHERE
(Customer.Account.AccountNumber IS NULL)
我基于这篇帖子How do I UPDATE from a SELECT in SQL Server?
UPDATE
Table
SET
Table.col1 = other_table.col1,
Table.col2 = other_table.col2
FROM
Table
INNER JOIN
other_table
ON
Table.id = other_table.id
两个问题:
- 有没有办法在实际运行之前测试运行查询,例如更新或删除?
- 我是否正确地将其转换为更新?
谢谢!
【问题讨论】:
-
在不运行的情况下测试代码?我不知道.. 你不能为了测试目的复制数据库并运行它吗?
-
在不实际更新或删除记录的情况下运行。该数据库很大,位于托管服务器上。我需要很长时间才能在本地下拉并运行它。也就是说,如果我被授予拉取整个数据库的权限。 :)
标签: tsql sql-server-2012-express