Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating primary key on the existing table with data

Status
Not open for further replies.

ahlone

Programmer
Jun 16, 2005
12
US
Hi,

Currently, I have a table with no primary key, but, data are already loaded. So, I am trying to create the primary key on one of the columns with Enterprise Manager, but, no luck. Right now, it's allowing duplicate records to be inserted to the table.

Thanks
 
You can't create primary key if you have duplicateed info in the field you want to use as PK. First you must delete/Change records with duplicated info.
Check for duplicate:
Code:
SELECT Field1, field2, Count(*) AS Cnt FROM MyTable
GROUP BY Field1, field2
HAVING Cnt > 1
where field1 and field2 are fields PK based on.

Borislav Borissov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top