xxxxxxxxxx
NOT NULL # Ensures a column cannot have a NULL value
UNIQUE # Ensures all values in a column are unique
PRIMARY KEY # Identifies a record in a table, is NOT NULL & UNIQUE
FOREIGN KEY # References a unique record from another table
CHECK # Ensures all column values satisfy a condition
DEFAULT # Set a default value for a column if none is entered
INDEX # Quick way of retrieving records from database
xxxxxxxxxx
RULES ABOUT THE COLUMNS IN TABLE
NOT NULL # Ensures a column cannot have a NULL value
UNIQUE # Ensures all values in a column are unique
PRIMARY KEY # Identifies a record in a table, is NOT NULL & UNIQUE
FOREIGN KEY # References a unique record from another table
CHECK # Ensures all column values satisfy a condition
DEFAULT # Set a default value for a column if none is entered
INDEX # Quick way of retrieving records from database
xxxxxxxxxx
# Constraints Keywords in a table
NOT NULL # Ensures a column cannot have a NULL value
UNIQUE # Ensures all values in a column are unique
PRIMARY KEY # Identifies a record in a table, is NOT NULL & UNIQUE
FOREIGN KEY # References a unique record from another table
CHECK # Ensures all column values satisfy a condition
DEFAULT # Set a default value for a column if none is entered
INDEX # Quick way of retrieving records from database
# Names of constraints:
# Entity integrity constraint : Makes sure that records are unique
# Referential integrity constraint : Defines relationships between tables
# Domain constraint : Permissible values (You cannot enter char in boolean column)
# Semantic integrity constraint : Correctness of data
# Null constraint : Whether null is allowed
# Check constraint : Limits acceptance values (If today is in year 2023, you cannot enter 2050 in year column)
xxxxxxxxxx
CREATE TABLE table_name (
column1 datatype NOT NULL,
column2 datatype,
);
xxxxxxxxxx
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
.
);