2

Possible Duplicate:
What is MySQL's default ON DELETE behavior?

Hi all just want to know what the on delete and on update are set to on a foreign key if you dont specify what they are on a MYSQL database. I've been searching and cant really find out the answer. Like if I just create a foreign key what are they set too. Thanks.

Community
  • 1
  • 1
Dom
  • 1,018
  • 2
  • 11
  • 20
  • possible duplicate of [What is MySQL's default ON DELETE behavior?](http://stackoverflow.com/questions/1027656/what-is-mysqls-default-on-delete-behavior) (via a.stgeorge) – BoltClock Mar 01 '11 at 21:02
  • @BoltClock I came across the question and I couldn't get the answer to the question "what is the default on delete and on update?". I got the answer from here. The only thing I feel this question will useful to users than the original question. A normal computer programmers feel the SO is only for brilliant programmers if moderators keep Closing this type of questions. – Mohammed H Jul 17 '13 at 08:00

3 Answers3

2

the default action is RESTRICT.

via http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

Nanne
  • 64,065
  • 16
  • 119
  • 163
0

As stated in the MySQL docs:

If ON DELETE or ON UPDATE are not specified, the default action is RESTRICT. 

http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

The default is to disallow any update or delete of a parent row if it would orphan one or more child rows.

In this case the error looks like this:

ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
Ike Walker
  • 64,401
  • 14
  • 110
  • 109