SQL Column Level Vs Table Level Constraint- Tutorial using Oracle

Creating a Student table with column level check constraints

 
SQL> create table student(
    name varchar2(10),
    mark1 number constraint student_mark1_ck check(mark1>=0),
    mark2 number constraint student_mark2_ck check(mark2>=0));
Table created.

SQL> insert into student values ('satish',122,54);
1 row created.



Establish Table level constraints on the student table

 
SQL> create table student1(name varchar2(10),
  2  mark1 number,
  3  mark2 number,
  4  constraint student_mark_ck check(mark1>=0 and mark2>=0 and mark2<=100));
Table created.

SQL> insert into student1 values ('satish',122,54);
1 row created.

SQL> select * from student1;

Output
NAME            MARK1      MARK2
---------- ---------- ----------
satish            122         54

Table level unique key constraint

 
SQL> create table student(
    2  name varchar2(10),
    3  phone1 number,
    4  phone2 number,
    5  constraint student_phone_uk unique(phone1,phone2));

Output
Table created.

Unique key constraint violation

 
SQL> insert into student values('sam',111,222);

1 row created.
  
SQL> insert into student values('satish',111,222);
insert into student values('satish',111,222)
*

Output
ERROR at line 1:
ORA-00001: unique constraint (SATISH.STUDENT_PHONE_UK) violated