SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Reading
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How would I define a foreign key in MySQL.

    Defining foreign keys!
    What I am trying to do is take information from two tables and put them into a new table.

    For Example:

    members table:
    id int not null auto_increment primary key
    fname.........
    lname........
    email varchar (150)

    books table:
    id int not null auto_increment primary key
    title............

    New table:
    mebers_id
    email
    books_id

    How would I define these if they are defined as above in there original tables.

    Also can I take information from tables in one database and add to another database?

    Atia

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    "take information from two tables and put them into a new table"

    you have to supply the data values for the new table yourself -- unless you're thinking of using a CROSS JOIN to populate it with allpossible combinations of members and books?

    as far as foreign keys are concerned, if you want the database to enforce foreign keys, you need to declare these tables as InnoDB, and make sure they have indexes
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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