2

Well, in SQLLite there is not exist the possibility to delete on cascade, or I don't know how.

Imagine that I have two tables, Table A and Table B. The table B has the IDtableA field, because is a child, and imagine that I have the following situation:

1.- user A load record 1 from TableA and load it in the context. 2.- user A load all the child records from table B. 3.- user B add a new record to table B that is child of table A. 4.- user A save changes and delete record 1 and all the childs that he loaded in the first time, but not include the new child add by the user B.

So in SqlLite I don't have a model, neither realationships between tables, when user B add a new child, not check if the parent exists.

is it posible ensure reference integrity in Sqlite?

Thanks.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193

1 Answers1

3

SQLite supports foreign keys and "on delete cascade", but in the new versions.

You can see this article in official SQLite website:

sqlite.org/foreignkeys.html

The say:

This document describes the support for SQL foreign key constraints introduced in SQLite version 3.6.19.

Also, you have to explicitly enable foreign keys for every connection.

this question may help you: Enabling Foreign key constraints in SQLite

You can do it by changing the connection string and add:

foreign keys=true; 
Community
  • 1
  • 1
Saw
  • 6,199
  • 11
  • 53
  • 104