Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

concatenated keys in Sybase SQLANYwhere

Posted on 1998-03-17
3
Medium Priority
?
433 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 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