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 |
|
slboytoy
Starting Member
30 Posts |
Posted - 2005-09-08 : 00:24:10
|
| I have a question..Say I have a simple table with just CustomerNumber and CustomerName. CustomerNumber will always be unique and I'll always be linking to this table by CustomerNumber to find out the CustomerName..1. Should I make both fields the primary keys? 2. Make CustomerNumber the primary field a)CustomerName an index fields, b)make both the CustomerNumber and CustomerName an index field? |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2005-09-08 : 00:45:32
|
| If CustomerNumber is always unique then it should be the primary key by itself. If your doing exact match searches based on CustomerName then this column should probably be indexed.Dustin Michaels |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-08 : 06:56:00
|
If you have other columns in the Customer table, but frequently do a lookup involving only Number and Name - e.g.SELECT CustomerNameFROM CustomerTableWHERE CustomerNumber = 1234(or an equivalent JOIN) then having an index on CustomerNumber, CustomerName would "cover" the query - SQL Server will only use the index to get the answer (it will not bother going to the actual table).Probably only worth bothering about if the CustomerTable will be "big" Kristen |
 |
|
|
slboytoy
Starting Member
30 Posts |
Posted - 2005-09-09 : 00:32:01
|
| Well I know the Primary Key should be CustomerNumber, I'm just really wondering about the index.So my primary key is CustomerNumber, now when I set the index....Should it include customernumber and customername, or just customername ?Since those are the only two main columns that will be used 95% of the time in that table, I am putting them in memory (index), so there is less harddrive access = faster results. |
 |
|
|
|
|
|