Foreign Keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • b b

    #1

    Foreign Keys


    I am using MYSQL 4. I understand that it allows for
    foreign keys. Could someone show me an example of how
    to declare a foriegn key. I tried a combination of
    statements but I always got a syntax error.

    Here is what I am trying for example ...

    Create table x (
    ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    whatever int

    )Type=Innodb;


    Create table y (
    IDTr INT NOT NULL,
    constraint FOREIGN KEY IDTr REFERENCES x(ID)
    )Type=Innodb;

    How would I create a foreign key linking IDTr to
    x(ID)?

    Cheers.

    _______________ _______________ ____
    Do you Yahoo!?
    Yahoo! SiteBuilder - Free, easy-to-use web site design software


    --
    MySQL General Mailing List
    For list archives: http://lists.mysql.com/mysql
    To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw

Working...