12 (18-1) SQL Constraints
12 (18-1) SQL Constraints
Constraints can be specified when the table is created with the CREATE TABLE
statement, or after the table is created with the ALTER TABLE statement.
Types of SQL Constraints:
(i). CREATE table Student (sid int PRIMARY KEY, Name varchar(60),Age int);
(I). CREATE TABLE Persons (ID int, LastName varchar(255), FirstName varchar(25),
Age int, City varchar(25) DEFAULT ‘Delhi');
5. CHECK Constraint:
CHECK constraint is used to restrict the value of a column between a range. It
performs check operation on the values, before storing them into the database.
(i). create table Student(sid int CHECK(sid > 0), Name varchar(60), Age int);
The table with the foreign key is called the child table, and the table with the
primary key is called the referenced or parent table.
(i). CREATE TABLE Orders (OrderID int PRIMARY KEY, OrderNumber int, PersonID int
FOREIGN KEY REFERENCES Persons(PersonID));