Thread: Storing prices
View Single Post
Old 11-08-2012, 08:20 PM   PM User | #17
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 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
When in doubt, RTFM.

I'd much rather trust the documentation than google for what somebody else may or may not have done right.

http://dev.mysql.com/doc/refman/5.5/...ate-table.html

Samples from that page:
Code:
  | [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...) reference_definition
...
reference_definition:
    REFERENCES tbl_name (index_col_name,...)
      [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
      [ON DELETE reference_option]
      [ON UPDATE reference_option]

reference_option:
    RESTRICT | CASCADE | SET NULL | NO ACTION
...
Which means, for example, you can write:
Code:
    ....
    CONSTRAINT FOREIGN KEY productid REFERENCES products(productid) ON DELETE CASCADE 
    ...
but it also means you could write
Code:
    ....
    FOREIGN KEY productid REFERENCES products(productid) ON DELETE CASCADE 
    ...
or you could write
Code:
    ....
    CONSTRAINT fk_img_prodid FOREIGN KEY productid REFERENCES products(productid) ON DELETE CASCADE 
    ...
By giving the constraint a name, you could later remove or alter it by name. Not a likely thing to do with a foreign key, which is why I seldom bother, but it just gives you more options.

So...MUCH better to get the *FULL* documentation with all possible options rather than just what one person chose to use.
__________________
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.

Last edited by Old Pedant; 11-08-2012 at 08:25 PM..
Old Pedant is offline   Reply With Quote