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
 SQL Server Development (2000)
 Can you have varchar primary keys?

Author  Topic 

token
Posting Yak Master

133 Posts

Posted - 2007-08-03 : 08:54:11
I seem to have a problem with a table called PRODUCTS.

There are four columns in this table which are: ProductID, Manufacturer, Partno, Model.

At the moment ProductID is the primary key, but I also need Manufacturer and Partno to be joined together as a unique identifier.

Basically when someone searches for a Sony AR41S, then it MUST match in the Manufacturer and Partno fields as ONE identifier. This is because different manufacturers can use the same Partno to name their products.

e.g. Toshiba E95
Sharp E95

So the search critera that is entered e.g. Toshiba E95 should match correctly with the unique identifier of Manufacturer and Partno combined.

I tried to make Manufacturer and Partno primary keys in SQL Server, but it says they're the wrong data type. They are varchar(MAX) data types and I can't change them to int values for obvious reasons.

Any help would be immensley appreciated.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-03 : 11:24:46
Can you put unique constraint on them?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-08-03 : 11:50:07
Yeah, you can't index VARCHAR(MAX) columns. I'm not sure why you'd create them as VARCHAR(MAX), but if you can, I'd suggest you change the length of the columns. Then, as rmiao suggested, you can add a unique constraint.
Go to Top of Page
   

- Advertisement -