question

sqlrookie avatar image
sqlrookie asked

insert data into table column

Hi, I have two databases A and B. Database B is replica of A. Database A has a table tab1(id,name,address). Database B has a table tab2(id,name,address) but tab2(address) in database B is null. How to insert data from database A tab1(address) into database B tab2(address). name and address data can be irrelevant. There is no need to have a specific address for specific name, Just need to insert data into the address column. Thanks in advance
insertcolumn
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
If there's no keys to relate the two tables, then there's no way to guarantee what data you're going to get. However, you can just write an INSERT... SELECT statement to move the data between the databases.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sqlrookie avatar image sqlrookie commented ·
HI Grant, Thanks for the suggestion. Let me explain you the scenario.We have created few employees name in emp table with few columns as null.There is an another table similar to emp say emp1 which has data in the null columns. I just want to replace emp null column with emp1 table column. Also if i add more employees i need to again use the same data from emp1 to emp null column. We dont have any constraint to exact data for paticular employee name it can random data.
0 Likes 0 ·
Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
If there is no way to match like to like, how can you update the NULL values? If you can match one to another, you just need to do an UPDATE... SELECT statement in combination with the INSERT ... SELECT statement or even a MERGE... SELECT, and move the data that IS NULL between the two tables. But you have to have the JOIN criteria, a mechanism for matching like to like. If it's just random stuff to random stuff, there's no way to match anything to anything. It has to be 'abc' to 'abc' and '42' to '42', etc.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.