Solved

concatenated keys in Sybase SQLANYwhere

Posted on 1998-03-17
3
382 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now