SQL as A Data Manipulation Language : INSERT

The INSERT Statement is used to add new rows of data to an existing table in the database. There are two basic syntax of the INSERT statement :

First syntax :
 INSERT INTO table_name (column1, column2, column3,...columnN) 
     VALUES (value1, value2, value3,...valueN);
Here, column1, column2, column3,...columnN are the names of the columns in the table into which you want to insert the data.

Example :
 INSERT INTO Employee (EmpId, EmpName, Salary, Addr, PIN)
     VALUES (101, 'John', 2000, 'Boston', 300987);

Second Syntax :
 INSERT INTO table_name VALUES (value1, value2, value3, ....valueN);
Example :
 INSERT INTO Employee VALUES (101, 'John', 2000, 'Boston', 300987, 9998765432);
At here, we are directly inserting values at the columns, because we are adding values for all the columns of the table, so we do not need to specify the columns name in SQL query. but make sure the order of the values is in the same order as the columns in the table.

Next Topic :

No comments:

Post a Comment