
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) 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. On update: This is default parameter in foreign key. If any existing related key is deleted at that time all ongoing executions end. On delete: This is the default parameter in foreign keys.
When we use foreign key in table at that time we can control the operation by using different parameter as follows. If we need to disable foreign key at that time we can use the following command as follows. So when we need to enable foreign key at that time we can use the following command as follows. Basically foreign key constraints compile with SQLite library, so that purpose SQLite uses PRAGMA foreign_keys command to enable or disable the foreign key constraint at the run time.