SQL Insert Statement

INSERT INTO command is used to add new record into the table.

there is two way to insert a record into the table.

1) If you want to insert records in all fields(columns) then do not need defines the columns.

Syntax:-


INSERT INTO table_name 
values(value_1,value_2,value_3,value_4....value_n) 

Example:-


INSERT INTO employees 
values(1,"Virat","Kohli","virat@abc.com","delhi") 

Now check the new record is saved into employees table


 SELECT * FROM employees

Output:-


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | Virat      | Kohli     | virat@abc.com  | delhi      |
+----+------------+-----------+----------------+------------+

2) If you want to insert records in some fields (columns) then it should be defined.

Syntax:-


INSERT INTO table_name(column_1,column_2,column_3)
values(value_1,value_2,value_3) 

Example:-


INSERT INTO employees("id","first_name","email") 
values(2,"Rohit","rohit@abc.com")

Now check the new record is saved into employees table


 SELECT * FROM employees

Output:-


+----+------------+-----------+----------------+------------+
| id | first_name | last_name | email          | address    |
+----+------------+-----------+----------------+------------+
|  1 | Virat      | Kohli     | virat@abc.com  | delhi      |
|  2 | rohit      | NULL      | rohit@abc.com  | NULL       |
+----+------------+-----------+----------------+------------+

SQL Insert Statement – Interview Questions

Q 1: What is INSERT used for?

Ans: It adds new records to a table.

Q 2: Basic INSERT syntax?

Ans: INSERT INTO table VALUES (...);

Q 3: Can specific columns be inserted?

Ans: Yes, by specifying column names.

Q 4: Can multiple rows be inserted?

Ans: Yes, using a single INSERT statement.

Q 5: What happens if data types mismatch?

Ans: The query fails with an error.

SQL Insert Statement – Questions and Answers

No questions found.

SQL Insert Statement – Objective Questions (MCQs)

Q1. Which SQL command is used to add new records to a table?






Q2. Which clause specifies the values to insert?






Q3. What happens if column names are not specified in INSERT?






Q4. Which statement inserts multiple rows at once?






Q5. INSERT command belongs to which SQL category?






Related SQL Insert Statement Topics