Skip to content

Commit 02d149a

Browse files
committed
understanding different types and use of integrity constraint
1 parent 46b0694 commit 02d149a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

integrity_constraint.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use temp_db;
2+
3+
show tables;
4+
5+
/* different types of integrity constraint
6+
1. NOT NULL
7+
2. UNIQUE
8+
3. PRIMARY KEY
9+
4. FOREIGN KEY
10+
5. CHECK
11+
6. DEFAULT
12+
13+
these are applied on table column
14+
at the time of creating the table and altering the table
15+
*/
16+
17+
-- example using NOT NULL means we can not be having any NULL values in the table
18+
create table emp_new(s_no int NOT NULL, s_name varchar(15)); -- here s_no can not be null
19+
20+
insert into emp_new values(1, 'SANOJ'); -- successfully inserted
21+
insert into emp_new values (NULL, 'Kumar'); -- it will return error that s_no cannot be null
22+
insert into emp_new(s_name) values ('Kumar'); -- it will also return error same error

0 commit comments

Comments
 (0)