EN
MySQL - Insert NULL values
0 points
In this article, we would like to show you how to insert NULL
values to the table in MySQL.
Quick solution:
xxxxxxxxxx
1
INSERT INTO `table_name`
2
(`column1`, `column2`, `column3`, `columnN`)
3
VALUES
4
(value1, NULL, NULL, valueN);
To show you how to insert NULL
values to the table, we will use the following users
table:

Note:
At the end of this article you can find database preparation SQL queries.
In this example, we will insert rows with NULL
values to the users
table.
Query
xxxxxxxxxx
1
INSERT INTO `users`
2
( `name`, `surname`, `department_id`, `salary`)
3
VALUES
4
(NULL, NULL, NULL, NULL),
5
('Simon', NULL, NULL, NULL),
6
('Taylor', 'Martin', NULL, NULL),
7
('Andrew', 'Thompson', 1, NULL),
8
('Taylor', 'Martin', 2, '2000');
Result:

create_tables.sql
file:
xxxxxxxxxx
1
CREATE TABLE `users` (
2
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
3
`name` VARCHAR(50),
4
`surname` VARCHAR(50),
5
`department_id` INT(10),
6
`salary` DECIMAL(15,2),
7
PRIMARY KEY (`id`)
8
);
insert_data.sql
file:
xxxxxxxxxx
1
INSERT INTO `users`
2
( `name`, `surname`, `department_id`, `salary`)
3
VALUES
4
('John', 'Stewart', 1, '6000'),
5
('Chris', 'Brown', 2, '6000'),
6
('Kate', 'Lewis', 3, '4000');