Inserting rows into a table is not a complex task. Below, you’ll find sample queries that help you use in your project readily.

Here is an SQL query to insert a single row at a time
INSERT INTO MY_TABLE VALUES('RAMA', 20000, 'HYDERABAD', 1001);The process of inserting values into a table with multiple columns in a single line is called a single-row insert. The example given is a table named my_table with four columns: Name, Salary, City, and EmpCode.
You can insert a NULL value into a table. The optional thing is that you can avoid the column names if the values are in the same order as the table columns.
INSERT INTO MY_TABLE (Name, Salary, City, EmpCode)VALUES('RAMA', 20000, 'HYDERABAD', 1001);Here is an SQL query to insert multiple rows at a time
Example-1
Inserting multiple rows saves you time, and you can avoid using the VALUES keyword multiple times when writing. After each value line, you need to use a comma ,. The semicolon should be used only once (at the end of the SQL query).
INSERT INTO MY_TABLE (Name, Salary, City, EmpCode)VALUES('RAMA', 20000, 'HYDERABAD', 1001), ('RAVI', 30000, 'DELHI', 1002), ('RANI', 40000, 'LUKNOW', 1003);Example-2
Check out inserting rows using SELECT and INSERT INTO here.
References
- SQL Pocket guide
- SQL course from Miami University

You must be logged in to post a comment.