涉及多个表的UPDATE查询

时间:2012-08-28 16:42:54

标签: sql-server-2008

我有两张桌子..

人:

  empid(primary key)
  firstname
  lastname
  email

详细说明:

  Did(primary key)
  salary
  designation
  empid

现在我需要更新姓名为' abc'的员工的电子邮件。 AND指定为经理。(假设有多个员工姓名abc,因此需要检查指定) 我正在使用sql server 2008

2 个答案:

答案 0 :(得分:7)

UPDATE p
  SET email = 'newemail@wherever.com'
  FROM dbo.Persons AS p
  INNER JOIN dbo.Details AS d
  ON p.empid = d.empid
  WHERE p.firstname = 'abc'
  AND d.Designation = 'manager';

答案 1 :(得分:0)

试试这个:

UPDATE 
  [Persons] 
SET 
  [Persons].[email]='###@###.###'
FROM 
  [Persons] 
  INNER JOIN [Persons].[empid] 
  ON [Details].[empid] = [Persons].[empid] 
WHERE 
  [Persons].[firstname]='abc' AND 
  [Details].[designation]='Manager'