将数据库表从一个 SQL Server 数据库表更新到另一个? [英] Update database table from one SQL Server database table to another?
问题描述
我正在尝试将数据库字段从一个 SQL Server 表更新到另一个.
I am trying to update database fields from one SQL Server table to another.
我们的生产 SQL Server 是 [spdbprod.test.com\spprod]
,我们的 QA 服务器是 [spdbQA.test.com\spQA]
.
Our production SQL Server is [spdbprod.test.com\spprod]
, our QA server is [spdbQA.test.com\spQA]
.
我需要从 QA 表更新生产中的表.我使用这个 SQL 语句,但是,它给出了一个错误.
I need to update table in production from QA table. I using this SQL statement but, it is giving an error.
UPDATE
[spdbprod.test.com\spprod].[aspnetdb].[dbo].[Communities_Groups] as t1
SET
t1.Show = (Select t2.show from [spdbQA.test.com\spQA].[aspnetdb].[dbo].
[Communities_Groups] as t2 where t1.GroupID = t2.GroupdID)
我在这里缺少什么?错误:更新.(关键字'as'附近的语法不正确.")
推荐答案
您以错误的方式使用了表别名.你不能做UPDATE table1 t SET field1=val
,你必须写UPDATE table1 SET field=val
(或者UPDATE table1 SET field=val FROM table1 t代码>).因此,将您的查询更改为
You are using table alias in a wrong way. You cannot do UPDATE table1 t SET field1=val
, you have to write UPDATE table1 SET field=val
(Or UPDATE table1 SET field=val FROM table1 t
). So change your query to
UPDATE [spdbprod.test.com\spprod].[aspnetdb].[dbo].[Communities_Groups]
SET Show = t2.show
FROM [spdbprod.test.com\spprod].[aspnetdb].[dbo].[Communities_Groups] t1
INNER JOIN [spdbQA.test.com\spQA].[aspnetdb].[dbo].
[Communities_Groups] t2 ON (t1.GroupID = t2.GroupID)
这篇关于将数据库表从一个 SQL Server 数据库表更新到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!