1/23/2024 0 Comments Sqlite foreign key clausesRESTRICTION – this action means that you cannot delete rows or modify the values of a parent key when there are one or more child keys associated with it. The default action or if no action is specified, then it is NO ACTION. The ON UPDATE clause is used when modifying the values of the parent key for one or more rows.įor ON DELETE and ON UPDATE clauses, SQLite supports the following actions: NO ACTION, RESTRICT, SET NULL, SET DEFAULT or CASCADE. The ON DELETE clause is used when deleting one or more rows from the parent table. ON DELETE and ON UPDATE clauses can be added to a foreign key constraint. REFERENCES parent_table (column_name1, column_name2. CREATE TABLE child_nameĬolumn_name1 datatype ,Ĭolumn_name2 datatype ,Ĭolumn_name3 datatype ,įOREIGN KEY (column_name1, column_name2. Second, the child table is created, it will contain the foreign key to the parent table. CREATE TABLE parent_table(Ĭolumn_name1 datatype PRIMARY KEY AUTOINCREMENT, Here is the syntax of SQLite FOREIGN KEY constraint:įirst, the parent table is created. PRAGMA foreign_keys = ON ĭisable foreign key constraints. In the SQLite database, foreign key constraints are disabled by default, so foreign key constraints must be enabled for eachdatabase connection.Įnable foreign key constraints. A foreign key uses to enforce the relationships between two or more tables in SQLite database. A foreign key is a primary key from another table. A SQLite FOREIGN KEY is a constraint used to link two tables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |