INSERT INTO command in SQL

For Complete YouTube Video: Click Here

In this class, we will understand the INSERT INTO command in SQL.

We have already discussed how to create a table in SQL.

INSERT INTO command in SQL

We have created the tables for the employee and department.

In that table, we will insert the values.

The structure of the command to insert the values in the table is as shown below.

INSERT INTO tablename (column1, column2, column3, …) VALUES (value1, value2, value3, …);

INSERT INTO is the keyword.

After an INSERT INTO, we have to provide the table name.

Then in the parentheses, we have to provide the column names into which the values are inserted.

VALUES is a keyword.

In the parentheses, we have to provide the values we want to insert.

Using the same structure, we will try to insert the values into the employee table.

INSERT INTO employee (Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary, Dno) VALUES (‘James’, ‘E’, ‘Borg’, 888665555, ’10-NOV-1937′, ‘430 Stone, Houston, TX’, ‘M’, 55000, 1);

If the column’s data type is varchar, the corresponding value must be enclosed in single quotes.

The single quotes are not required for the columns of integer data type.

The output after executing the query is as shown below.

INSERT INTO command in SQL 1
INSERT INTO command in SQL 1

Now we insert the values into the department table.

The query is as shown below.

INSERT INTO department (Dname, Dnumber, Locations) VALUES (‘Research’, 5, ‘Vijayawada’);

The output after executing the query is as shown below.

INSERT INTO command in SQL 2
INSERT INTO command in SQL 2

To verify whether the values are inserted or not is decided by the select command.

We will discuss the details of the SELECT command in our later classes.

The image below shows the table after inserting the values into the table.

INSERT INTO command in SQL 3
INSERT INTO command in SQL 3
INSERT INTO command in SQL 4
INSERT INTO command in SQL 4