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 |
|
tradingpassion
Starting Member
24 Posts |
Posted - 2005-07-31 : 20:56:53
|
| I was wondering how can I use 4 columns together as a key.So for example if I can column A, B, C, D and I want to perform a task when a new entry is added based on the values of all 4 columns together.Basically if I just use one of these or two of these(A or A&B) then it's not unique. It is unique only if I combine all 4 together???Thanks |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2005-07-31 : 21:36:43
|
| Yes you can. It's called a composite index. I don't know what the limit is, but you can certainly have 4 columns as your PK/Unique keyHTH,Tim |
 |
|
|
tradingpassion
Starting Member
24 Posts |
Posted - 2005-07-31 : 22:58:33
|
| Thanks for your reply!I searched in Transact SQL to see how it works.Is this how it works???CREATE INDEX XYZON TABLE1(ColA, ColB, ColC, ColD) |
 |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2005-08-01 : 00:18:23
|
| Looks about right, but BOL has a few good examples for your perusal... |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-08-01 : 01:42:18
|
| "I want to perform a task when a new entry is added"What sort of task?"It is unique only if I combine all 4 together"Do you need to make the Index UNIQUE then?CREATE UNIQUE INDEX MyIndexName ON MyTableName (ColA, ColB, ColC, ColD)Kristen |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2005-08-01 : 11:35:29
|
| FYI: From BOL (Maximum Capacity Specifications)Maximum Columns per Index = 16Maximum Bytes per Index = 900HTH=================================================================The most tyrannical of governments are those which make crimes of opinions, for everyone has an inalienable right to his thoughts. -Baruch Spinoza, philosopher (1632-1677) |
 |
|
|
|
|
|
|
|