Results 1 to 5 of 5

Thread: 2 keys

  1. #1
    Join Date
    Nov 2009
    Posts
    18

    Unanswered: 2 keys

    I want 2 keys. But i can make in mssql 1 primary key.

    example:
    i want primary key for school and class,

    Code:
    school      class    Name
    1             1           a
    1             2           b
    1             3           c
    1             5           d
    2             3           e
    2             4           f
    how can i make thst ind mssql?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by tchiloh View Post
    how can i make thst ind mssql?
    Code:
    CREATE TABLE students
    ( school INTEGER NOT NULL 
    , class  INTEGER NOT NULL 
    , PRIMARY KEY ( school , class )
    , name VARCHAR(99)
    );
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Mebbe even:
    Code:
    CREATE TABLE students
    ( school INTEGER NOT NULL 
    , class  INTEGER NOT NULL 
    , PRIMARY KEY ( school , class )
    , name VARCHAR(99) UNIQUE
    );
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    uh, mebbe not

    it's not unusual to have two guys named tom jones (heh)

    your UNIQUE constraint would not allow bofadem to attend the same school

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Mebbe, mebbe not. The functional dependencies were not specified but name is unique in the data. Better in my mind to offer it as option for for the OP to reject than say nowt at all; but you are right, likely it is not suitable for the real scenario.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •