-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNOT NULL in SQL.txt
More file actions
20 lines (18 loc) · 885 Bytes
/
NOT NULL in SQL.txt
File metadata and controls
20 lines (18 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// NOT NULL
-> By default a tables column can hold NULL values.
The NOT NULL constraint enforces a field to always contain a vlaue. This means that you cannot insert a new record, or update a record without
adding a value to this field.
ex:create table example(name varchar (30),roll int (10), number int(10)
NOT NULL);
// output
desc example;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| name | varchar(30) | YES | | NULL | |
| roll | int | YES | | NULL | |
| number | int | NO | | NULL | |
+--------+-------------+------+-----+---------+-------+
msg : INSERT INTO example (name,roll) VALUES('Ram',10);
ERROR 1364 (HY000): Field 'number' doesn't have a default value
mysql>