This presentation focuses on solving example queries related to constraints in SQL, building on the understanding established in previous sessions.
CREATE TABLE table_name (
column1 datatype constraint_name,
column2 datatype constraint_name,
...
column_n datatype constraint_name
);
CREATE TABLE employee (
ID INT UNIQUE,
Name VARCHAR(50) NOT NULL,
DepartmentName VARCHAR(40),
Salary INT
);
CREATE TABLE student (
Name VARCHAR(10) NOT NULL
);
ALTER
command to add or drop constraints in existing tables.Unique Constraint Example:
UNIQUE
without NOT NULL
.Not Null Constraint Example:
Default Constraint Example:
DEFAULT 18
) if no value is specified for a column during an insertion.Check Constraint Example:
IN
clause:
CREATE TABLE student (
Gender CHAR CHECK (Gender IN ('M', 'F'))
);
Primary Key Preview:
UNIQUE
and NOT NULL
.Next Presentation Focus: More detailed exploration of Primary Key and Foreign Key with examples.
A thorough understanding of these constraints allows for robust database design, ensuring data integrity, and establishing clear relationships between database tables. Future sessions will delve deeper into more complex constraints like Primary Key and Foreign Key.