SQL INSERT Statement

How to store data in a Table?

Answer is very simple, Use INSERT  query. There are two ways to insert data in table.

Syntax:

Form1 :
INSERT INTO "tableName"
values (value1, value2, ....  ,valueN);

OR

Form2 :
INSERT INTO "tableName" (column1, column2, ...., columnN)
values (value1, value2, ....  ,valueN);

Parameters :

tableName : Name of the table in which we are going to insert data.

column1, column2, columnN : Columns name of the table which will have specified data in it.

value1, value2, valueN : Values which are going to stored in table for e.g. column1 will have value1, column2 will have value2 and so on columnN will have value valueN.

INSERT INTO with columns name  is below :

INSERT INTO `tutorialsmines`.`employee` (`id`, `name`, `salary`, `age`) VALUES (‘3’, ‘Jyoti’, ‘55000’, ’32’);

insert-into-query-by-column-name

Using Select to see all the records.

insert-into-output-query-by-column-name

DIRECT INSERT INTO  is below :

INSERT INTO `tutorialsmines`.`employee` VALUES (‘5’, ‘Leena’, ‘52000’, ’35’);

insert-into-query

Using Select to see all the records.

insert-into-query-output

INSERT INTO for adding multiple rows at a same time  is below :

INSERT INTO `tutorialsmines`.`employee` (`id`, `name`, `salary`, `age`) VALUES ('1', 'Arnav', '50000', '27'), ('2', 'Urmila', '45000', '29');

Note : You should provide values for all the NON NULL defined columns.
Please remember about the datatypes of your column to avoid errors while inserting data in table.
Do not forgot about integrity constraints applies on your coulmns definition.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *