Composite key usage..........

  • I have 2 Fk from other table..i want to combine them and make a PK for tht table.how to do tht??

    for example.... i have created a table

    create table StudentClass

    (

    std_id int foreign key references Student

    class_id int foreign key references Class

    )

    so i want to make a PK "std_classid " for the table StudentClass by combining these two FKs.........how to do that?

  • CREATE TABLE StudentClass (

    std_id INT FOREIGN KEY REFERENCES Student (std_id),

    class_id INT FOREIGN KEY REFERENCES Class (class_id),

    CONSTRAINT pk_StudentClass PRIMARY KEY (std_id, class_id)

    )

    (I also fixed your foreign key references)

    Why not student_id? Not saving much typing and losing much in clarity by a non-standard abbreviation

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply