Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    4

    newbie to database design

    Hello all!

    How does one design a table that will for example store information about members. These members can only be a member of one club or another club, but not both.
    How does one implement such a control into a table.

    Thanks in advance

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    CREATE TABLE clubs
    ( club_id INTEGER NOT NULL PRIMARY KEY
    , club_name VARCHAR(255)
    );
    CREATE TABLE members
    ( member_id INTEGER NOT NULL PRIMARY KEY
    , club_id INTEGER NULL
    , CONSTRAINT member_club_fk FOREIGN KEY ( club_id ) REFERENCES clubs (club_id)
    , member_name VARCHAR(127)
    );
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2007
    Location
    London, UK
    Posts
    741
    By giving the table a key (uniqueness constraint). If you are serious about learning then I suggest you read a decent introduction and study some basic principles rather than jump straight into design problems. If you have a particular example in mind then post that example.

Posting Permissions

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