views:

64

answers:

3

how to set anything in database then he not allow duplicate rows in a table means

name abc name abc means some row sames as each other then i need to take one copy of it and remove each other

A: 

Make most important data field (like name) as unique key .

Riho
If you can't add indexes to database, then before inserting new record you should do select:SELECT name from mytable where name='abc'If you get record back then skip the INSERT.
Riho
A: 

Create a Unique Key on the table that includes all the columns.

Doobi
A: 

Are you perhaps asking how to identify one in a series of duplicate rows to keep (or delete)? Can you do a group by query of the original table, keeping one record (either the min or max, probably does not matter), and store the result in a new table. Then compare the record counts in the new table, to make sure you have what you want. Finally, you can delete the contents of the original table and replace it with the new table. Of course, keep a backup, etc.

This is also made more complicated if you have other foreign keys that would prevent you from deleting the original records. If that is the case, then you might have to create a cursor and delete all but the first of the matching records, and let the database delete the related children as you encounter them.

MJB