Question:

Question about foreign key?

by  |  earlier

0 LIKES UnLike

Table1

.............

name nvarchar(20)

rollnumber int primary key

Table2

-----------

empno int foreign key

Here I use different names "rollnumber" and "empno" for the two tables instead of giving rollnumber in the second table. How can I refer 'rollnumber' using the foreign key 'empno'?

 Tags:

   Report

2 ANSWERS


  1. First off, what database product are you using? Always include the OS, language, product, etc in your questions so you can get an accurate answer.

    If I am not mistaken, you can define a foreign key using any column name you want - I don't really think that is an issue. It may be problematic in MS Access - that's why it's always good to include the name of the product you are working with.

    Really, I think it boils down more to good practice. It could be confusing to have a column named one thing in one table, and another thing in another table. I would suggest standardizing your naming.

    But as far as using a different column name, I don't think there are any restrictions in SQL.

    EXAMPLE :

    Foreign Key (Customer_SID) references CUSTOMER(SID));

    In this example, the column is named 'Customer_SID' in one table, and just 'SID' in the other one.


  2. what is it actually are u trying to do??.. is it programming??..

    if not.. (if it's written)

    if ur allowed to add another table then u can create fro example table 3.. then make empno as the foreign key and rollnumber as the public.. in that way you could be able to create such connections..

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.