Unix Technical Forum

unique keys

This is a discussion on unique keys within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I plan to create a table with 3 unique keys. Combination of three fields has to be unique ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:24 PM
reneeccwest
 
Posts: n/a
Default unique keys

Hello,



I plan to create a table with 3 unique keys.

Combination of three fields has to be unique for each row in a table that
are vendor ID (char 8), vendor name (char 40), and vendor office (5).



Will it be okay to have a unique key which has a long character such as
vendor name?

How should I index those three fields? Those fields will be searched many
times.



RCW


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:24 PM
Mystery Man
 
Posts: n/a
Default Re: unique keys

You would need to have three seperate non-unique indexes for id, name
and office respectively. (in your posting you say that these are
unique - this sounds strange given your later statement)

You should add a unique index that is a composite of the above.

Index names that long are no problem (assuming of course that you dont
have millions of rows).

Some additionals notes:

(1) If this database table contains vendors, I would have expected
that vendor id would be the unique primary key??? If it cannot be
unique, I would consider adding another column that is the unique
primary key (if you have not already done so).

(2) Consider making vendor name a varchar(40) rather than a char(40)

(3) You will need to investigate the types of queries that users make.
This may result in additional indexes (or removing some of the above)


"reneeccwest" <reneeccwest@hotmail.com> wrote in message news:<xdkYa.9323$ug.144@lakeread01>...
> Hello,
>
>
>
> I plan to create a table with 3 unique keys.
>
> Combination of three fields has to be unique for each row in a table that
> are vendor ID (char 8), vendor name (char 40), and vendor office (5).
>
>
>
> Will it be okay to have a unique key which has a long character such as
> vendor name?
>
> How should I index those three fields? Those fields will be searched many
> times.
>
>
>
> RCW

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 05:25 PM
Erland Sommarskog
 
Posts: n/a
Default Re: unique keys

reneeccwest (reneeccwest@hotmail.com) writes:
> I plan to create a table with 3 unique keys.
>
> Combination of three fields has to be unique for each row in a table that
> are vendor ID (char 8), vendor name (char 40), and vendor office (5).


It sounds funny to me that the vendor ID alone would not be unique.
OK, I can envision that a vendor has several offices, but several
names?

And if a vendor can have several offices, you should probably have the
offices in a subtable.

And as "Mystery Man" said, make that vendor name varchar(40).


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:49 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com