Solved

concatenated keys in Sybase SQLANYwhere

Posted on 1998-03-17
3
406 Views
Last Modified: 2008-03-10
CREATE TABLE emp_skill(
emp_id INTEGER NOT NULL,
skill_id INTEGER NOT NULL,
"skill level" INTEGER NOT NULL,
PRIMARY KEY( emp_id, skill_id ),
FOREIGN KEY REFERENCES employee,
FOREIGN KEY REFERENCES skill
)
----------------------------------
how does a "concatenated" key work in the above example? if you want to link to it from another table -- u have gotta have a 'concatenated' key there too? u obviously can't join to the above table if u got only emp-id..

if i use SQLCentral i can't get to see/define if the combination of both is unique or not.

if this concatenated key is a foreign key somewhere else - how is it implemented?
0
Comment
Question by:hunchback
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
jbiswas earned 50 total points
ID: 1098366
The proper term for a primary key consisting of two or more fields is a composite key. I assume we are talking about the same thing. When you set something as a primary key it has to be unique. So by default it will not allow any duplicate values. In isql you can do a duplicate check(which you will not find in case of a primary key) with a queruy of the following format:
select count(*), field_name1, field_name2 from table_name group by field_name1, field_name2 having count(*)>1
To make this a foreign key for some table, that table should have these two fields and under that table , go to foreign key, add foreign key and when it asks for the talename and column_names, give the appropriate table name and the name of the two columns. That should make this composite key a foreign key.
0
 

Author Comment

by:hunchback
ID: 1098367
thanks very much ,Jbiswas, if u can made a comment:
when we have 2 fields like above example: is it normal/necessary in the sybaseDB realm or from your experience to create an additional/new  field call EmpSkillID (size=both fields added up)
and call a trigger to add both fields (empID, skillID) in order to define the value. Also making EmpSkillID the primary key.
0
 
LVL 2

Expert Comment

by:jbiswas
ID: 1098368
Nope you do not have to do that. A composite key works just fine. The data is stored as per the composite key, so it doesn't make any sense to concatenate the two fields.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audiā€¦

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question