Skip to content

Commit fa81a48

Browse files
committed
understanding default integrity constraint
1 parent 758b53c commit fa81a48

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

default_integrity_constraint.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use temp_db;
2+
3+
show tables;
4+
5+
6+
-- this is basically used when there is no value provided for a column and we want to have some default value instead of null
7+
8+
create table emp_new3(id int, exp int default 1);
9+
10+
insert into emp_new3 values(1, 1); -- no error
11+
insert into emp_new3 values(NULL, NULL); -- no error
12+
13+
insert into emp_new3(id) values(1); -- no error but the default value of exp is 1 not NULL.
14+
15+
select * from emp_new3;

0 commit comments

Comments
 (0)