Site icon TestingDocs.com

SQLite PRIMARY KEY

Overview

Let’s understand the SQLite PRIMARY KEY constraint in this tutorial. Primary keys uniquely identify each row in the table.

SQLite PRIMARY KEY

The PRIMARY KEY constraint uniquely identifies each record in a database table. The primary key is a combination of one or more columns that uniquely identify each record in the table. There can be only one PRIMARY KEY in a table.

Syntax

The general syntax of the constraint is as follows:

CREATE TABLE table_name (
column1 datatype PRIMARY KEY,
column2 datatype,

);

In this syntax, the single column column1 is the PRIMARY KEY. When a column is defined as a primary key, it automatically implies the NOT NULL constraint.

You can also define a composite primary key using multiple columns in the table.

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
   column3 datatype,
    …
    PRIMARY KEY (column1, column2)
);

 

SQLite Tutorials

SQLite tutorials on this website:

https://www.testingdocs.com/sqlite-database-tutorials/

For more information on SQLite, visit the official website:

https://www.sqlite.org/

Exit mobile version