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)
 Use natural key as primary key to avoid join?

Author  Topic 

mani
Starting Member

2 Posts

Posted - 2005-07-06 : 22:31:09
I have the following design.

Group Table
Stock Group Id(tinyint) PK, Stock Group Name varchar(30) not null unique, and other few columns

-Maximum 10 rows

Category Table
Group Id tinyint, Category Id smallint (composite pk), Category Name vatrchar(30) and other few colums
-maximum-200 rows

Sub Category Table
group id tinyint, category smallint, subcategory id smallint (composite key), sub category name, and other few colums
-maximum -1000 rows

product table

product id int,productname, group id,category id, subcategory id and other columns
-maximum 20,000 rows


90%of the time when I query product details i need group name , category name, sub category name along with it not any other details of other tables

SO i have to join four tables. Although keys are very small, i was wondering woudl it be good idea to do away with ids and have names as pk so that when i need produt details i always get stock group name, category name and sub actegory name with out having to join four tables

If I have names as PK, FK in product table will be 90 bytes varying length

What do you think will give me best performance?

Regards
mani



byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2005-07-06 : 23:42:13
The only "con" for the natural key in this case (IMO) is stability. An updateable key would require cascading RI..

90 bytes is not much to worry about over 20,000 rows...(~1.8Mb vs 100Kb).. 20 million rows is a different sad story...

DavidM

A front-end is something that tries to violate a back-end.
Go to Top of Page

mani
Starting Member

2 Posts

Posted - 2005-07-07 : 02:05:56
These tables do not get updated very often.
I would be having 3 indexes on product table like this to search for products by any combination of stock group, category and sub category

non clustered index 1: stock group , category ,sub category
non clustered index 2: category,sub category
non clustered index 3: sub category

Dont you think SQL server traversing 1.8MB of index will take more time than
just traversing 100 Kb of index and fetching the name from stock group, cat, sub cat tables even though it involves 4 table join.

Application will bring large amount of other data too from transaction table . So buffer pool wont be free enough to say performance difference is too small to differentiate between above two methods

It's a desk top application using MSDE 7 or 2000, BUt very data intensive application

I want to be very sure about this cause it will affect my entire database design.


Go to Top of Page
   

- Advertisement -