ALTER TABLE
If the
FOREIGN KEY
refer to that name to drop the foreign key. Otherwise, the
when the foreign key is created. To find out the symbol value when you want to drop a foreign key, use
a
SHOW CREATE TABLE
mysql>
SHOW CREATE TABLE ibtest11c\G
*************************** 1. row ***************************
Table: ibtest11c
Create Table: CREATE TABLE `ibtest11c` (
`A` int(11) NOT NULL auto_increment,
`D` int(11) NOT NULL default '0',
`B` varchar(200) NOT NULL default '',
`C` varchar(175) default NULL,
PRIMARY KEY
KEY `B` (`B`,`C`),
KEY `C` (`C`),
CONSTRAINT `0_38775` FOREIGN KEY (`A`, `D`)
REFERENCES `ibtest11a` (`A`, `D`)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `0_38776` FOREIGN KEY (`B`, `C`)
REFERENCES `ibtest11a` (`B`, `C`)
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB CHARSET=latin1
1 row in set (0.01 sec)
mysql>
ALTER TABLE ibtest11c DROP FOREIGN KEY `0_38775`;
You cannot add a foreign key and drop a foreign key in the same
statements is required for each operation.
If an
ALTER TABLE
is truncated), MySQL's foreign key constraint checks do not notice possible violations caused by
changing the values.
Foreign Keys and Other MySQL Statements
Table and column identifiers in a
backticks (`). Alternatively, double quotation marks (") can be used if the
mode is enabled. The setting of the
into account.
You can view a child table's foreign key definitions as part of the output of the
statement:
SHOW CREATE TABLE tbl_name;
You can also obtain information about foreign keys by querying the
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
mysqldump
tables.
To make it easier to reload dump files for tables that have foreign key relationships,
automatically includes a statement in the dump output to set
avoids problems with tables having to be reloaded in a particular order when the dump is reloaded. It is
also possible to set this variable manually:
mysql>
SET foreign_key_checks = 0;
mysql>
SOURCE dump_file_name;
mysql>
SET foreign_key_checks = 1;
This enables you to import the tables in any order if the dump file contains tables that are not correctly
ordered for foreign keys. It also speeds up the import operation. Setting
to 0 can also be useful for ignoring foreign key constraints during
CREATE TABLE
tbl_name
DROP FOREIGN KEY fk_symbol;
clause included a
statement, as shown here:
(`A`,`D`,`B`),
statement results in changes to column values (for example, because a column
FOREIGN KEY ... REFERENCES ...
produces correct definitions of tables in the dump file, including the foreign keys for child
Syntax
name when you created the foreign key, you can
CONSTRAINT
fk_symbol
lower_case_table_names
table.
1044
value is generated internally
statement. A separate
ALTER TABLE
clause can be quoted within
ANSI_QUOTES
[466]
system variable is also taken
SHOW CREATE TABLE
foreign_key_checks
foreign_key_checks
and
LOAD DATA
ALTER TABLE
[535]
SQL
mysqldump
[451]
to 0. This
[451]
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers