Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • FOREIGN KEY

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 345
    Comment on it

    FOREIGN KEY

    Foreign key is used to setup relation between two tables in a database. A foreign key is a values that appear in both the tables in database system. The table which contain foreign key is called the child table while the table to which foreign key is referred is called parent table. Foreign key mainly reference a primary key in the parent table.

    we can create a foreign key by using a CREATE TABLE statement or by ALTER TABLE statement.

    Syntax

    Below is the syntax for creating a foreign key by an CREATE TABLE statement :-

    CREATE TABLE child-table
    (
      column1 datatype [ NULL | NOT NULL ],
      column2 datatype [ NULL | NOT NULL ],
    
       FOREIGN KEY (child-column-name(s))
        REFERENCES parent table (parent-column-name(s))
    
    );
    

    Below is the syntax for creating a foreign key by an ALTER TABLE statement

    ALTER TABLE child-table
    (
        FOREIGN KEY (child-column-name(s))
        REFERENCES parent-table (parent-column-name(s)
    );
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: