Key Constraints in DBMS
Key Constraints in DBMS
Example
Example
The following SQL sets a DEFAULT value for the “city” column when the
“emp” table is created:
My SQL / SQL Server / Oracle / MS Access:
CREATE TABLE emp (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'hyderabad'
);
Check
Suppose in real-time if you want to give access to an application
only if the age entered by the user is greater than 18 this is done
at the back-end by using a check constraint
Check constraint ensures that the data entered by the user for
that column is within the range of values or possible values
specified
Primary Key
A primary key is a constraint in a table which uniquely
identifies each row record in a database table by enabling one or
more the column in the table as primary key
Reference Table
Child Table
CREATE TABLE CUSTOMERS2(
ID INT ,
MARKS INT,
REFERENCES CUSTOMERS1(ID)
);