How to update a table from one database to another? [closed] - sql

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have two database like A and B and a common table as TBL where the table TBL from A database has 1555 rows but the table TBL from database has only 1000 rows. I need to update the TBL in B database from A database.
1.How can I do it if these A and B database on same server name
2.what if these both database are on different server names .
Thanks in advance

INSERT INTO YourDbToBeInsertedInto..YourTable
SELECT *
FROM YourDbToBeInsertedFrom..YourTable
WHERE PrimaryKey NOT IN (SELECT PrimaryKey
FROM YourDbToBeInsertedInto..YourTable)
Use linked servers

Related

How can I do 'insert if not exists' in Ms sql server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to move data from table1 to table2 (both the tables have same structure)with condition of comparing their emaild (unquie)in both the tables...if the data of emaild exits in table 2 I should not load that data otherwise I have to insert the record in table 2..these two tables are in two different databases of same sql server instance... Could you please provide me with the syntax.. Thanks in advance
INSERT db2.dbo.table2(key, other cols)
SELECT key, other cols
FROM db1.dbo.table1 AS t1
WHERE NOT EXISTS
(
SELECT 1
FROM db2.dbo.table2 AS t2
WHERE t2.key = t1.key
);
You can double-check you're getting the right rows by commenting out the first line.
Here's an example with a procedure on db<>fiddle.

Subtract two column values and store result in another column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have the one table eg tbl_1 and i have column eg A B C. When I insert into column A and B its result store into C like c=a-b.
If you wish to create virtual/computed columns while creating a table structure, Since you dint specified which RDBMS you are using, please following links (the one that suits you) :
Hope it helps you.
MYSQL
ORACLE 11G
SQL SERVER
CREATE TABLE tbl_1
(
A int,
B int,
C AS A - B
);

Overwriting Values From SQL Table to Another SQL Table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 databases, a live and backup. I want to overwrite the the values in a specific field in the live database from those that are in the backup. The database structure is identical the only difference is there name.
How do I do this?
Try this
UPDATE liveDB
SET column2 = src.column2 -----Whichever column you want
FROM BackupDB.dbo.Table1 AS src
INNER JOIN LiveDB.dbo.Table1 AS dest
ON src.column1 = dest.column1;
Updated
UPDATE live
SET l.ola_m_1= b.ola_m_1
FROM live.dbo.order_line l
JOIN backup.dbo.order_line b
ON --Whatever is Similar column between two

Insert into a backup table based on date [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My table in Oracle 11g has 6 fields. I also have a backup table also with no values. The original table has 2 date values. I need to insert into the backup table from the original table the orders having an order-date 5 months back as of today.
The table has a field names ORDER-DATE and has records entered inside.
insert into backup_table
select * from original_table
where order-data > add_months(sysdate,-5);

Update field with data from another database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Need to update a field with data from another field in a different database
I Have two SQL commercial Databases from the same company, the first Database has one field that is null in the other
I need to update the Field/Database that is null with the data of the first one.
MS SQL Server
Update table1 in current database from table1 in database called "DataBaseName"
update table1
set col2 = T2.col2
from DataBaseName.dbo.table1 as T2
where table1.ID = T2.ID and
table1.col2 is null