Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Insert Into not in the table

Author  Topic 

Zul
Starting Member

17 Posts

Posted - 2009-06-16 : 03:51:01
Hi all,
i have 2 database. 1 db master, 2 db client.
i db master there alaot of table, i make view to take a few table in db master.
the result of this view i migration into db client.
in other hand 1 table in db client has same data in view db master.
now that i want to ask is how can i make a query how can insert into db client from dm master that the data is not obtain in db client?
untethered i want to insert into db client from db master that data is not in the db client.
if i use insert statment the data will be duplicate
can any body help me

Regards

Zul

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-16 : 07:12:32
something like this:

insert db_client..destination_table(col1, col2, ...)
select
col1,
col2,
...
from db_master..source_table as srce
where not exists (select * from dest_table where KeyCol = srce.Keycol)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Zul
Starting Member

17 Posts

Posted - 2009-06-17 : 22:55:18
yes someting like this.
i've we use this query can data in the DB master and has same in Db cient cannot duplicate?
in othere hand only new data in Db master who can insert into Db client, so old data in db matster not include insert inti db client if we use this query?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-18 : 03:31:10
If there are no duplicates in source_table itself then there are no duplicates in destination_table with the given query.
Old data in source_table is not included in the given insert if the data already exists in destination_table.

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Zul
Starting Member

17 Posts

Posted - 2009-06-18 : 23:17:47
Oke, thanks.
i will try the query
Go to Top of Page

Zul
Starting Member

17 Posts

Posted - 2009-06-18 : 23:19:36
oke thanks.

i will try this query

Regards
Zul
Go to Top of Page
   

- Advertisement -