1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Foreign Key Complexity

Discussion in 'General' started by ankit.mca.aaidu, Sep 14, 2013.

  1. ankit.mca.aaidu

    ankit.mca.aaidu Active Member

    Likes Received:
    Trophy Points:
    Why we use Foreign key ?

    how we can implement this ??

    it can also be achieved by making same field as primary key in two table ??

    if not then what we say this kind of relation in table.??
  2. prashant

    prashant Forum Advisor

    Likes Received:
    Trophy Points:
    New Delhi, India
    Foreign Keys are used to enforce Referential integrity Constrains at the Database Side. Essentially it is a column in one table that uniquely identifies the column of another table.

    A popular example would be Employee Table and Department Table.

    Here Dept table will have say 2 columns - Deptno and DeptName. Here Deptno will be unique across the table and will essentially be the Primary Key.

    Emp table on the other hand will have a deptno column along with other Employee details column. Since there could be many employees in the same department, one cannot have deptno as Primary key in EMP table.

    So what we say here is EMP table References DEPT table and every deptno in EMP table uniquely identifies a department in DEPT table.

    In Oracle, we will make deptno in DEPT table as Primary key and deptno in EMP table as Foreign key referencing DEPT table.

    Hope this clarifies.

    Best Regards,