Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
5152d903
Commit
5152d903
authored
Apr 22, 2002
by
heikki@hundin.mysql.fi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manual.texi:
Update manual on ON DELETE CASCADE
parent
49a188f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
17 deletions
+34
-17
Docs/manual.texi
Docs/manual.texi
+34
-17
No files found.
Docs/manual.texi
View file @
5152d903
...
@@ -38066,22 +38066,49 @@ constraints to guard the integrity of your data.
...
@@ -38066,22 +38066,49 @@ constraints to guard the integrity of your data.
The syntax of a foreign key constraint definition in InnoDB:
The syntax of a foreign key constraint definition in InnoDB:
@example
@example
FOREIGN KEY (index_col_name, ...)
FOREIGN KEY (index_col_name, ...)
REFERENCES table_name (index_col_name, ...)
REFERENCES table_name (index_col_name, ...)
[ON DELETE CASCADE | ON DELETE SET NULL]
@end example
@end example
Both tables have to be InnoDB type and @strong{there must be an index
where the foreign key and the referenced key are listed as the first
columns}. InnoDB does not auto-create indexes on foreign keys or
referenced keys: you have to create them explicitly.
Corresponding columns in the foreign key
and the referenced key must have similar internal data types
inside InnoDB so that they can be compared without a type
conversion.
The size and the signedness of integer types has to be the same.
The length of string types need not be the same.
Starting from version 3.23.50 you can also associate the
@code{ON DELETE CASCADE} or @code{ON DELETE SET NULL}
clause with the foreign key constraint.
If @code{ON DELETE CASCADE} is specified, and a row in the parent
table is deleted, then InnoDB automatically deletes also all those rows
in the child table whose foreign key values are equal to
the referenced key value in the parent row. If @code{ON DELETE SET NULL}
is specified, the child rows are automatiaclly updated so that the
columns in the foreign key are set to the SQL NULL value.
Starting from version 3.23.50, InnoDB does not check foreign key
constraints on those foreign key or referenced key values
which contain a NULL column.
Starting from version 3.23.50 the InnoDB parser allows you to
Starting from version 3.23.50 the InnoDB parser allows you to
use backquotes (`) around table and column names in the above
use backquotes (`) around table and column names in the above
definition.
definition but the InnoDB parser is not yet aware of possible
variable @code{lower_case_table_names} you give in @file{my.cnf}.
An example:
An example:
@example
@example
CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB;
CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id)) TYPE=INNODB;
CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id),
CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id),
FOREIGN KEY (parent_id) REFERENCES parent(id)) TYPE=INNODB;
FOREIGN KEY (parent_id) REFERENCES parent(id)
ON DELETE SET NULL
) TYPE=INNODB;
@end example
@end example
Both tables have to be InnoDB type and @strong{there must be an index
where the foreign key and the referenced key are listed as the first
columns}. InnoDB does not auto-create indexes on foreign keys or
referenced keys: you have to create them explicitly.
If MySQL gives the error number 1005 from a @code{CREATE TABLE}
If MySQL gives the error number 1005 from a @code{CREATE TABLE}
statement, and the error message string refers to errno 150, then
statement, and the error message string refers to errno 150, then
...
@@ -38099,10 +38126,6 @@ ALTER TABLE yourtablename
...
@@ -38099,10 +38126,6 @@ ALTER TABLE yourtablename
@end example
@end example
Remember to create the required indexes first, though.
Remember to create the required indexes first, though.
Starting from version 3.23.50, InnoDB does not check foreign key
constraints on those foreign key or referenced key values
which contain a NULL column.
In InnoDB versions < 3.23.50 @code{ALTER TABLE}
In InnoDB versions < 3.23.50 @code{ALTER TABLE}
or @code{CREATE INDEX}
or @code{CREATE INDEX}
should not be used in connection with tables which have foreign
should not be used in connection with tables which have foreign
...
@@ -38118,12 +38141,6 @@ A @code{CREATE INDEX} statement is in MySQL
...
@@ -38118,12 +38141,6 @@ A @code{CREATE INDEX} statement is in MySQL
processed as an @code{ALTER TABLE}, and these
processed as an @code{ALTER TABLE}, and these
restrictions apply also to it.
restrictions apply also to it.
Corresponding columns in the foreign key
and the referenced key must have similar internal data types
inside InnoDB so that they can be compared without a type
conversion. The length of string types need not be the same.
The size and the signedness of integer types has to be the same.
When doing foreign key checks InnoDB sets shared row
When doing foreign key checks InnoDB sets shared row
level locks on child or parent records it has to look at.
level locks on child or parent records it has to look at.
InnoDB checks foreign key constraints immediately: the check
InnoDB checks foreign key constraints immediately: the check
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment