SQLTeam.com | Weblogs | Forums

Auto Increment ID's


#1

Hi All,
I want to create a table called Label with the following columns:
Label_ID (Auto Increment Primary Key), LabelName, LabelValue

I want to Create another table called Feat with the following Columns:
Feat_ID(Auto Increment Primary Key), Feat_Label_ID(Foreign key, it is just the Label_ID from previous table), FeatName,FeatValue

I want to know how I can create auto increment random ID's primary keys for each of my tables like 54DA90C0 and also How can I make an auto incremental primary key of one table as foreign key of another table.

Please help!!
Thanks in advance.


#2

"auto increment" is a MySQL term. In MSSQL we use identity - have a look here


#3

The easiest way is to use the Label_ID as the foreign key in Feat_Label_ID. Auto incrementing the second table makes for a lot of difficult handling for it to work as a foreign key.
At the point where you know the relationship between a feat and it's label, assign a feat row using the Label_ID as the foreign key.


#4

It can be done, but requires a third table as a "link" table with the primary keys from the other two tables as columns in the third table.