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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Use 4 columns as a key

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 key

HTH,

Tim
Go to Top of Page

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 XYZ
ON TABLE1(ColA, ColB, ColC, ColD)

Go to Top of Page

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...

Go to Top of Page

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
Go to Top of Page

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 = 16
Maximum Bytes per Index = 900

HTH

=================================================================
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)
Go to Top of Page
   

- Advertisement -