Constraint:
- Primary Key
- Not Null
- Check and
- References.
Creating Table using primary key and not null
create table student
(
rollno number primary key,
name varchar2(15) not null,
Branch varchar2(5),
gender varchar2(7),
DOB date,
email_id varchar2(25),
Address varchar2(25),
phone_no number
);
Creating Table using check and References
create table student_marks
(
rollno number references students_035,
marks number
constraint check_marks check(marks between 0 and 100)
);
We apply the check Constraint on marks so if marks is not between the 0 and 100 then sql command is violated.
Example:
SQL> insert into student_marks values(1,67);
1 row created.
SQL> insert into student_marks values(40,107);
insert into student_marks values(40,107)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CHECK_MARKS) violated