Wasabi Posted May 27, 2011 Share Posted May 27, 2011 Hi, Is the an advantage to declaring foreign keys with the following syntax? CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) ) Many Thanks! Link to comment Share on other sites More sharing options...
Larry Posted May 27, 2011 Share Posted May 27, 2011 Perhaps, depending upon the version of MySQL and the storage engine in use, neither of which do you mention. Link to comment Share on other sites More sharing options...
Wasabi Posted May 28, 2011 Author Share Posted May 28, 2011 Perhaps, depending upon the version of MySQL and the storage engine in use, neither of which do you mention. MySQL 5.5.9 With A myISAM Storage engine. Just saw the syntax at W3 Schools and was applying the question to the book examples. As always Many Thanks! Link to comment Share on other sites More sharing options...
HartleySan Posted May 30, 2011 Share Posted May 30, 2011 When you say syntax, do you mean the statements used, or perhaps the order of declarations, or perhaps the actual names used? Please let us know. Link to comment Share on other sites More sharing options...
Wasabi Posted May 31, 2011 Author Share Posted May 31, 2011 Please pardon the vagueness. I'm interested in grasping the advantage, if any, in using these statements. CONSTRAINT fk_PerOrders FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) Link to comment Share on other sites More sharing options...
Larry Posted June 1, 2011 Share Posted June 1, 2011 If you're using a MyISAM table, there is no advantage as MyISAM does not support foreign key constraints. Link to comment Share on other sites More sharing options...
Wasabi Posted June 2, 2011 Author Share Posted June 2, 2011 Thanks Larry, That bit of information, using foreign key constraints with a myISAM engine was omitted from the example at W3Schools. Link to comment Share on other sites More sharing options...
Larry Posted June 3, 2011 Share Posted June 3, 2011 And that, of course, is why it's important to include all the relevant details when you ask a question here. A note I've given you on several occasions, I believe. Link to comment Share on other sites More sharing options...
Wasabi Posted June 4, 2011 Author Share Posted June 4, 2011 Correct, you have. I also reviewed that suggestion in the chapter on Debugging, and Will include PHP Version mySQL Version Engine Information OS Version In all future post. Link to comment Share on other sites More sharing options...
Recommended Posts