We hope that this EDUCBA information on “SQLite foreign key” was beneficial to you. From this article we saw how and when we use SQLite foreign key. We also saw the rules of foreign key constraint. Set Default: In SQLite the set default value worked, in which that foreign key set default value in the table, if default value of foreign key is not available then SQLite shows error message.įrom this article we saw the basic syntax of foreign key and we also seen different examples of foreign key for implementation.No Action: It works same as limit work as referenced previously. Restrict: if reference rows is updated from parent table then related rows from child table is restricted.Set Null: When we delete reference rows from parent table then related rows from child table are null.Cascade: When we make some changes that means update or delete records in parent table then corresponding rows from child table automatically update or delete.We can make foreign keys at the time of table creation or we can utilize an adjust order to add foreign keys into the predetermined table.Īt the point when we use reference_option in foreign key, the reference_option acknowledges the following five unique qualities as follows. Rules and Regulations for foreign keyīasically foreign keys are used as referential integrity constraints in SQLite and it is work between parent table and child table. SQLite supports the different actions as follows.Īs per our requirement we can use any action. Mainly there are two constraints as follows. SQLite foreign key constraint or we can say action as follows.When we try to insert the above records at that time it shows an error message because common_id 4 does not exist in the dist_unit table.Now try to insert another record as follows.Ĭode: Insert into distributor (dist_name, common_id) values ("LG", 4) Now insert some records into the dist_unit table by using insert into statement as follows. We successfully created a booth table as shown in the below screenshot as follows. Here common_id id foreign key reference from dist_units.In the above example we use a create table statement to create a new table name as distributor with attributes such as dist_id with integer data type and also have a primary key constraint, dist_name with text data type and common_id with integer data type as shown in above statement.Now create a distributor table with different attributes by using the following statement.Ĭode: create table distributor (dist_id integer primary key, dist_name text not null, common_id integer not null, foreign key (common_id) references dist_units (common_id)) Now first create two tables to implement foreign keys as follows.įirst create a dist_unit with different attributes by using the following statement as follows.Ĭode: create table dist_unit (common_id integer primary key, unit_name text not null) In the event that any current key is refreshed from the parent table, the exchange comes up short toward the finish of the inquiry.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |