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.
| Author |
Topic |
|
joytwo0708
Starting Member
5 Posts |
Posted - 2009-01-07 : 17:34:00
|
| I have two same structure tables in SQL server 2005, I know tablediff.exe can tell the difference. But I want to save the diff result into a SQL table which should have the complete row from those two tables.Like windiff, if open the diff result table, I can easily tell which row is new or updated or deleted.How to do that? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-08 : 02:57:40
|
| Insert into target_table(columns)select columns from table1exceptselect columns from table2Insert into target_table(columns)select columns from table2exceptselect columns from table1MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-08 : 03:01:45
|
| if below sql 2005, use left join or not existsInsert into target_table(columns)select t1.columns from table1 t1left join table2 t2on t2.pk=t1.pkwhere t2.pk is nullInsert into target_table(columns)select t1.columns from table1 t1where not exists (select 1 from table2 where pk=t1.pk) |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2009-01-08 : 03:04:27
|
| if you are working In Sql 2005 then use the queries as Madhi Sir stated above like...Insert into target_table(columns)select columns from table1exceptselect columns from table2Insert into target_table(columns)select columns from table2exceptselect columns from table1and if you are using Sql 2000 den you do it as,,,,insert into target_table(columns)SELECT column1 , column2....FROM( SELECT A.column1 , A.column2... FROM Tbl_1 A UNION ALL SELECT B.column1 , B.column2 FROM Tbl_2 B) tmpGROUP BY column1, column2HAVING COUNT(*) = 1Thanks..... |
 |
|
|
|
|
|
|
|