?
Solved

concatenated keys in Sybase SQLANYwhere

Posted on 1998-03-17
3
Medium Priority
?
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
jbiswas earned 200 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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