简体   繁体   English

将一列从数据库表复制到另一数据库表sql server中的另一列

[英]Copy one column from a database table to another column in another database table sql server

I had two databases (A and B), both were identical until I messed up one column in Table T1 on database A... basically set all records in that column to NULL. 我有两个数据库(A和B),直到我弄乱了数据库A的表T1中的一列为止,两个数据库都是相同的...基本上将该列中的所有记录都设置为NULL。 How do I update that incorrect column in T1 on database A with the correct data from its equivalent column from database B? 如何用数据库B中等效列中的正确数据更新数据库A中T1中的不正确列?

My insert command did not work as there are more columns in T1 on database A which do not allow null values to be inserted. 我的插入命令不起作用,因为数据库A的T1中有更多列,不允许插入空值。

insert into A.dbo.finance (finishdate)
select finishdate 
from B.dbo.finance

I tired to do an inner join, but it says "multi-part identifier could not be bound". 我厌倦了进行内部联接,但是它说“无法绑定多部分标识符”。 Unfortunately the data in the other tables in database A has since changed hence simply using database B is not an option :-) 不幸的是,数据库A中其他表中的数据此后发生了变化,因此仅使用数据库B是不可行的:-)

Could someone please assist? 有人可以帮忙吗?

If ID is the id column of both tables, you should join them and update the one you want: 如果ID是两个表的id列,则应将它们加入并更新所需的表:

UPDATE A.dbo.finance
SET    finishdate = B.finishdate 
FROM   A.dbo.finance A
       JOIN B.dbo.finance B
           ON A.ID = B.ID

DATABASE B 数据库B

Select finishdate into ##temp from dbo.finance B where 1 = 1

DataBase A 数据库A

    insert into dbo.finance(finishdate)
    select * from ##temp t where NOT EXISTS
(Select 1 from dbo.finance WHERE finishdate <> t.finishdate  )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL Server:将列数据值从一个表复制到同一数据库中的另一表 - SQL Server: copy column data values from one table to another table in the same database 如何将列从一个表复制到 SQL 服务器中的另一个表 - How to copy column from one table into another table in SQL Server 在 SQL 服务器中将 Partial Table 从一个数据库复制到另一个数据库 - Copy Partial Table from one database to another in SQL Server SQL Server将数据从一个数据库表复制到另一数据库表 - Sql Server copy data from one database table to another 将特定表数据从一个数据库复制到SQL Server中的另一个数据库 - Copy specific table data from one database to another in SQL Server SQL - 将数据从一个表列复制到另一个表列 - SQL - copy data from one table column to another table column 我可以将数据从一个数据库表复制到另一个已经存在的数据库表sql服务器吗? - Can i copy data from one database table to another already existing database table sql server? 将表数据从一个数据库复制到另一个数据库SQL - Copy a table data from one database to another database SQL Sql 将表从一个数据库复制到另一个数据库 - Sql Copy table from One Database to Another Database SQL复制数据从一列到另一个表指定列 - SQL copy data from one column to another table specified column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM