SQLite Constraints

  Total Views : 15
  Comments : 0
 
  Keywords : Constraints in sqlite with examples, SQLite not null / default / check constraints with examples, SQLite primary key / foreign key / unique constraints with examples

Here we will learn SQLite constraints with examples and different types of sqlite constraints (primary key, foreign key, unique, default, Not Null, Check Constraint) with examples

SQLite Constraints

In SQLite CONSTRAINTS are used to define conditions on table columns to stop performing insert / update / delete data operations on column without satisfying defined conditions.

 

Generally, we can define Constraints on table during creation using CREATE TABLE statement or at the time of modifying existing table structure using ALTER TABLE statement.

 

SQLite constraints are used to define the rules for data in table. In case if there is any violation between defined constraint and the action on data, the respective action is aborted by the constraint.

 

In SQLite constraints are divided into four classes of integrities those are 

 

  • Domain Integrity
  • Entity Integrity
  • Referential Integrity
  • User-defined Integrity

We will learn each constraint integrity in detailed manner.

Domain Integrity

In SQLite domain integrity constraints are used to validate data in table columns and these constraints will make sure that the data in column falls within the specified range of valid values.

 

Suppose if we have one column userid and we don't want to allow users to enter null or empty values in that case by using domain integrity constraints we can set restrictions on column and it will raise exception whenever invalid data operations performed on column.

 

In SQLite we have different type of Domain integrity contraints available those are

 

  • Foreign key constraints
  • Check constraints
  • Default constraints 
  • NOT NULL

We will learn more about these contraints in detailed manner with examples in next chapters.

Entity Integrity

In SQLite entity integrity constraints are used to make sure that table rows are identified uniquely and these constraints will help us to identify and get records uniquely based on our requirements.

 

In SQLite we have different type of Entity Integrity constraints available those are

 

  • Indexes
  • UNIQUE constraints
  • PRIMARY KEY constraints

We will learn all these SQLite constraints in-detailed in next chapters.

Referential Integrity

In SQLite referential integrity constraints are used to maintain the relationship between the tables and these constraints will make sure that the value in one table referenced to value in another table like foreign key relationship.

 

In SQLite we have different type of Referential Integrity constraints available those are 

 

  • Foreign key constraints
  • Check constraints

We will learn all these SQLite constraints in-detailed in next chapters.

User-defined Integrity

In SQLite user-defined integrity constraints are used to implement custom logic which is not possible to achieve by using system constraints. By using stored procedures, functions and triggers we can create user-defined integrity constraints.

 

We will learn more about these constraints in detailed in next chapters.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User