Skip to content

Commit 758b53c

Browse files
committed
understanding check integrity constrain
1 parent 18abe68 commit 758b53c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

check_integrity_constraint.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use temp_db;
2+
3+
show tables;
4+
5+
create table emp_new1(id int, name varchar(15), exp int, check(exp > 2));
6+
7+
insert into emp_new1 values(1, 'SANOJ', 3); -- no error
8+
insert into emp_new1 values(NULL,'DEEPAK', 4); -- no error
9+
10+
insert into emp_new1 values(2, 'KUMAR', 2); -- will gives error
11+
12+
-- so basically check constraint is used on the column for checking the values according to the
13+
-- given condition
14+
15+
16+
create table emp_new2(id int, name varchar(15), exp int, location varchar(15), check(exp > 2 and location in ('india', 'usa', 'Uk')));
17+
18+
insert into emp_new2 values(1, 'SANOJ', 3, 'india'); -- no error
19+
insert into emp_new2 values(NULL,'DEEPAK', 1, 'india'); -- gives error because of exp check
20+
21+
insert into emp_new2 values(2, 'KUUMAR', 4, 'new delhi'); -- will give error

0 commit comments

Comments
 (0)