SET DEFAULT: This action is recognized by the MySQL parser, but InnoDB rejects table definitions containing ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT clauses.įor an ON DELETE or ON UPDATE that is not specified, the default action is always RESTRICT. In MySQL, foreign key constraints are checked immediately, so NO ACTION is the same as RESTRICT. Implementing dropdown menu in phpMyAdmin. I have set up a Foreign Key in my mysql database with: ALTER TABLE gameplayers ADD CONSTRAINT FKGAMENUMBER FOREIGN KEY (GameNumber) REFERENCES games (GameNumber) ON UPDATE CASCADE ON DELETE CASCADE However, I am not sure I want the ON UPDATE and ON DELETE anymore. where sql is the SQL string, and params is the list or tuple of query. Some database systems have deferred checks, and NO ACTION is a deferred check. When referencing relational fields such as ForeignKey, F() returns the primary. The MySQL Server rejects the delete or update operation for the parent table if there is a related foreign key value in the referenced table. Specifying RESTRICT (or NO ACTION) is the same as omitting the ON DELETE or ON UPDATE clause. RESTRICT: Rejects the delete or update operation for the parent table. If you specify a SET NULL action, make sure that you have not declared the columns in the child table as NOT NULL. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported. SET NULL: Delete or update the row from the parent table, and set the foreign key column or columns in the child table to NULL. Between two tables, do not define several ON UPDATE CASCADE clauses that act on the same column in the parent table or in the child table. Connect to a database server with username and password Select an existing database or create a new one List fields, indexes, foreign keys and triggers of. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. MySQL supports five options regarding the action to be taken, listed here:ĬASCADE: Delete or update the row from the parent table, and automatically delete or update the matching rows in the child table. When an UPDATE or DELETE operation affects a key value in the parent table that has matching rows in the child table, the result depends on the referential action specified using ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |