SQL-Insert Statemnet


Insert: Insert Statement is used to insert values in tables. In Insert Statement the number of columns and values must be the same. If a column is not specified, the default value for the column is used. 

SQL Syntax would be as follows: 
Insert into tablename (column1, column2, column3) values (value1, value2, value3)

                                          (Or)
Insert into table name values (value1, value2, value3)


By using these two statements we can insert required data to the required table.


Example for Insert Statement:
Insert into Employee (empid, First Name, Last Name, Deportment, Address, City) values (001,’sam’, ‘Prasad’, ‘QA’, ‘XYZ Automobiles’, ’Delhi’);
After running the query "Employee" table will now look like this:





empid
First Name
Last Name
Deportment
Address
City
 001
 sam
prasad 
 QA
XYZ Automobiles 
 Delhi























It is not need to specify the all column(s) name in the SQL query if we are adding values for all the columns of the table. But make sure the order of the values is in the same of order as the columns in the table.
Insert into Employee values (001,’sam’, ‘Prasad’, ‘XYZ Automobiles’);
Table name is Employee
After running the Second query "Employee" table will now look like this:





empid
First Name
Last Name
Deportment
Address
City
 001
 sam
Prasad 

XYZ Automobiles  


































No comments:

Post a Comment