What is a Constraint
A constraint is a rule that’s applied to a column or set of columns in a database table with the goal of preserving the data integrity. Constraints enforce limits on the data type and the range of values that can be used within columns. If any action violates a constraint, that action is aborted.
| Constraint | _Description_ |
|---|---|
| NOT NULL | Ensures that a column cannot have NULL value |
| DEFAULT | Provides a default value for a column when none is specified |
| UNIQUE | Ensures that all values in a column are unique |
| PRIMARY KEY | A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table |
| CHECK | Ensures that all values in a column satisfies certain conditions |
sqlite> CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name TEXT NOT NULL,
Age INT CHECK(Age >= 18),
Email TEXT UNIQUE,
City TEXT DEFAULT 'Unknown'
);Crow’s Foot Notation






Insert Into
-- Add one row
INSERT INTO table (column1,column2 ,..)
VALUES( value1, value2 ,...);
-- Add multiple rows
INSERT INTO table1 (column1,column2 ,..)
VALUES
(value1,value2 ,...),
(value1,value2 ,...),
...
(value1,value2 ,...);Update
UPDATE table
SET column_1 = new_value_1,
column_2 = new_value_2
WHERE
search_condition Delete
DELETE
FROM customers
WHERE customer_id = 2;Drop Table
The DROP TABLE statement removes a table added with the CREATE TABLE statement.
DROP TABLE customers;
Leave a Reply