Insert a row into the MySQL 'countries' table with a NULL value for the 'region_id' column
MySQL insert into Statement: Exercise-4 with Solution
4. Write a MySQL query to insert NULL values against region_id column for a row of countries table.
Sample Solution:
-- Inserting a new record into the 'countries' table with specified columns
INSERT INTO countries (country_id, country_name, region_id) VALUES('C1', 'India', NULL);
Let execute the above code in MySQL command prompt.
Here is the structure of the table:
mysql> SELECT * FROM countries; +------------+--------------+-----------+ | COUNTRY_ID | COUNTRY_NAME | REGION_ID | +------------+--------------+-----------+ | C1 | India | NULL | +------------+--------------+-----------+ 1 row in set (0.00 sec)
Explanation:
The above code inserts a new record into the 'countries' table with specified column values 'C1' for 'country_id', 'India' for 'country_name', and NULL for 'region_id'.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous:Write a MySQL query to create duplicate of countries table named country_new with all structure and data.
Next:Write a MySQL query to insert 3 rows by a single insert statement.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mysql-exercises/insert-into-statement/insert-into-statement-exercise-4.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics