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 2000 Forums
 SQL Server Development (2000)
 delete identically rows from two tables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-09 : 12:28:33
hesham writes "hi, We have two tables with the same structure some users insert data in the first table and the others insert the same data into the another table the all users can duplicate insert the data again by mistak .. there is no uniqe index , no foreign key ,no primary key ..

So I want to delete the identically rows which inserted into two tables and display the records which inserted in one table and didn't insert in the another as this example :

table A , table B
1 , 1
1 , 1
2 , 1
2 , 2
2 , 2
3 , 4
5 , 6
7 , 5
and the result will be :
table A , table B
2 , 1
3 , 4
7 , 6
thanks."

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-09 : 14:33:53
1. Insert the identical rows into a temp table.
2. Delete the rows from both tables that are left.
3. Do a select using a FULL OUTER JOIN. (This will be nasty.)
4. Create a table that just has an identity column.
--Use this to drive the insert for now on so you don't have to worry about this.
5. Put a primary key on these tables.
6. Put a foreign key on the tables from the new table you make to produce this. (It would be better if you could just combine the tables and put a type on there or something.)

***Before you do any of the above, could you explain what the tables are for? Why are they two different tables? What is their function?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -