Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreign Key support in sqlite 3

Tags:

sqlite

I wanted to use foreign key mechanism for database. But, the tables are not following the integrity constraints. How can I be sure that, my sqlite3 db has Foreign key support ?

like image 630
Abi Avatar asked Jan 10 '11 12:01

Abi


People also ask

Does SQLite support foreign keys?

SQLite has supported foreign key constraint since version 3.6. 19. The SQLite library must also be compiled with neither SQLITE_OMIT_FOREIGN_KEY nor SQLITE_OMIT_TRIGGER. To check whether your current version of SQLite supports foreign key constraints or not, you use the following command.

Can I have 3 foreign keys?

A table can have multiple foreign keys based on the requirement.

How do foreign keys work in SQLite?

A foreign key is a way to enforce referential integrity within your SQLite database. A foreign key means that values in one table must also appear in another table. The referenced table is called the parent table while the table with the foreign key is called the child table.


1 Answers

Type the command "PRAGMA foreign_keys" in the sqlite3 prompt and if returns no data instead of a single row containing "0" or "1", then the version of SQLite you are using does not support foreign keys (either because it is older than 3.6.19 or because it was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined)

More info is available in the link below: http://www.sqlite.org/foreignkeys.html

like image 179
aTJ Avatar answered Sep 28 '22 07:09

aTJ