PostgreSQL Insert Record: Insert a record into a table against each column
1. Write a SQL statement to insert a record with your own value into the table countries against each column.
Here in the following is the structure of the table countries.
Column | Type | Modifiers --------------+-----------------------+----------- country_id | character varying(2) | country_name | character varying(40) | region_id | numeric(10,0) |
Sample Solution:
Code:
-- This SQL statement inserts a new row into the 'countries' table with specified values.
INSERT INTO countries VALUES('C1','India',1002);
Explanation:
- The INSERT INTO statement is used to add new rows into a table.
- countries is the name of the table where the new row will be inserted.
- VALUES('C1','India',1002) specifies the values to be inserted into each column of the table for the new row. In this case, 'C1' is inserted into the 'COUNTRY_ID' column, 'India' into the 'COUNTRY_NAME' column, and 1002 into the 'REGION_ID' column.
Here is the command to see the list of inserting rows:
postgres=# SELECT * FROM countries; country_id | country_name | region_id ------------+--------------+----------- C1 | India | 1002 (1 row)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: PostgreSQL Insert Records - Exercises, Practice, Solution
Next: Write a SQL statement to insert one row into the table countries against the column country_id and country_name.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics