For a long time it puzzled me how something so expensive, so leading edge, could be so useless. And then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. Bill Bryson
Constraints apply specific rules to data for ensuring the data conforms to the requirements defined.
The not null Constraint do not allow null values into the table. The primay should not contain null values.
The unique Constraint do not allow duplicate values into the table. The primay should not contain duplicate values.
The Primary Key constraint uniquely identifies each record in a database table. It will not allow null or unique data.
A Foreign Key in one table points to a Primary Key in another table. IT helps to link the table.
--NOT Null Constraint Create table person ( pno integer, pname varchar2(20) not null ); --UNIQUE Constraint Create table person ( pno integer, pname varchar2(20) constraint uq_pname unique ); --Primary Key Constraint Create table person ( pno integer constraint pk_pno PRIMARY KEY, pname varchar2(20) ); -- Foreign Key Constraint CREATE TABLE DEPT ( DEPTNO INTEGER PRIMARY KEY, DEPTNAME VARCHAR2(20) NOT NULL, LOCATION VARCHAR2(20) ); CREATE TABLE EMP ( EMPNO INTEGER PRIMARY KEY, EMPNAME VARCHAR2(20) NOT NULL, SALARY NUMBER, DEPTNO INTEGER constraint fk_deptno references DEPT(deptno) );