Use SQL commands in Navicat to add foreign key constraints to ensure data consistency: Command structure: ALTER TABLE child_table ADD FOREIGN KEY (child_column) REFERENCES parent_table (parent_column) [ON DELETE action] [ON UPDATE action] Parameter explanation: child_table: child table; child_column: child table refers to the column of parent table column; parent_table: parent table; parent_column: parent table is referenced
Add foreign key constraints command in Navicat
Add foreign key constraints in Navicat to ensure data consistency and integrity. The following is how to add foreign key constraints in Navicat using SQL commands:
Command structure:
<code class="sql">ALTER TABLE child_table ADD FOREIGN KEY (child_column) REFERENCES parent_table (parent_column) [ON DELETE action] [ON UPDATE action];</code>
Parameter explanation:
ON DELETE action: Optional, specify the operation to be performed on related records in the child table when the records in the parent table are deleted. Possible values include:
ON UPDATE action: Optional, specify the operation to be performed on related records in the child table when the records in the parent table are updated. Possible values include:
Example:
The following command adds a foreign key constraint in the subtable named "orders" that refers to "customer_id" column in the parent table named "customers":
<code class="sql">ALTER TABLE orders ADD FOREIGN KEY (customer_id) REFERENCES customers (customer_id) ON DELETE CASCADE ON UPDATE CASCADE;</code>
Tips:
The above is the detailed content of How to add foreign key constraint command in navicat. For more information, please follow other related articles on the PHP Chinese website!