View Single Post
Old 12-06-2012, 10:25 PM   PM User | #18
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Look at what I wrote:
Quote:
The syntax there for the foreign keys isn't quite correct for MySQL, but it's a compact form that easy to read for a post like this.
The correct syntax is:
Code:
CREATE TABLE Customers (
    custid INT AUTO_INCREMENT PRIMARY KEY ,
    coid INT,
    custname VARCHAR( 100 ),
    CONSTRAINT FOREIGN KEY fk_customers_coid ( coid ) REFERENCES countries( coid ) 
 );
You don't have to give the foreign key a name (the part in red there). MySQL will create a name for you if you don't, and you can then find the created name by doing
Code:
SHOW CREATE TABLE Customers;
You can see why I prefer the more compact version I use when posting. It's clearer what the intent is, even if the syntax isn't quite right.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote