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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unique field to set the primary key

Status
Not open for further replies.

deejayAr

Technical User
Mar 20, 2008
126
US
I need to index the database but there is not a unique field to set the primary key on. All fields have duplicate values in them. If I do not index the database then trying to move around in the database is very slow. . All of the fields have duplicated data.
any one has ideas how to do it
thanks
 
Let's assume yopu mean "table(s)" instead of "database", and "columns" instead of "fields". It would be a simple matter to add an autonumber column to you tables to accomplish this, although normalizing your tables would be better practice.

Beir bua agus beannacht!
 
A primary key can also be multiple columns. You do not need to have a primary key to create an index, however, best practice is to have a primary key.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Before you create an index, you should review what columns are normally used in the queries. For example, let us say you have a table with first name, middle initial, last name, phone number.

Most of your queries are to find out a person's phone number, so the phone number is rarely searched on. No need to have an index on that.

Most of the queries will normally use the last name, so that is a good column to index. A few queries may use include the first name, so you might consider an index on last name that includes the first name.

Sure the columns don't have unique data in them, but neither does the phone book (remember those?). But the phone book is still 'indexed' and you can quickly find information as the 'index' narrows down the amount of data you need to look at.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top