SQLiteDatabase.SetForeignKeyConstraintsEnabled(Boolean) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets whether foreign key constraints are enabled for the database.
[Android.Runtime.Register("setForeignKeyConstraintsEnabled", "(Z)V", "GetSetForeignKeyConstraintsEnabled_ZHandler")]
public virtual void SetForeignKeyConstraintsEnabled (bool enable);
[<Android.Runtime.Register("setForeignKeyConstraintsEnabled", "(Z)V", "GetSetForeignKeyConstraintsEnabled_ZHandler")>]
abstract member SetForeignKeyConstraintsEnabled : bool -> unit
override this.SetForeignKeyConstraintsEnabled : bool -> unit
Parameters
- enable
- Boolean
True to enable foreign key constraints, false to disable them.
- Attributes
Exceptions
if the are transactions is in progress when this method is called.
Remarks
Sets whether foreign key constraints are enabled for the database.
By default, foreign key constraints are not enforced by the database. This method allows an application to enable foreign key constraints. It must be called each time the database is opened to ensure that foreign key constraints are enabled for the session.
A good time to call this method is right after calling #openOrCreateDatabase
or in the SQLiteOpenHelper#onConfigure
callback.
When foreign key constraints are disabled, the database does not check whether changes to the database will violate foreign key constraints. Likewise, when foreign key constraints are disabled, the database will not execute cascade delete or update triggers. As a result, it is possible for the database state to become inconsistent. To perform a database integrity check, call #isDatabaseIntegrityOk
.
This method must not be called while a transaction is in progress.
See also SQLite Foreign Key Constraints for more details about foreign key constraint support.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.