SQL Insert table – Insert data into Table

SQL insert table example – Learn how to insert data into a table in MySQL database with example and important points.

Insert statement is used to insert data into the database tables.

SQL syntax to insert data into a database table

Syntax:    Insert into table_name(column_list) values(value_list);

Points to notice:

  • column_list contains column names separated with commas(,).
  • value_list contains values for corresponding columns separtated with commas(,)

Different ways to insert data into a table in SQL

To insert the data into a database table, it is possible to insert in different ways.

SQL statement to insert data into table by specifying column names

  1. INSERT INTO table_name (column1,column2,…..) values(value1,value2,….);

In this case data is inserted into the database table  based on the order of the column names that is specified while inserting.

SQL query to insert data into a table.

INSERT INTO BOOKS(ISBN_NO,TITLE,AUTHORFIRSTNAME,AUTHORLASTNAME)               VALUES(‘181′,’The Castle’,’Franz’,’Kalka’  );

SQL statement to insert data into table without specifying Columns name

  1. INSERT INTO table_name values(value1,value2,……..);

in this case values is inserted for all the columns, and no need to specify the column names in the query.

Order of  values in the query is same as order of columns in the database table

SQL query to insert data into a table.

INSERT INTO BOOKS VALUES(‘191′,’Animal Farm’,’George’,’Orwell’);

SQL Statement to insert data in to table in multiple rows at a time

  1. INSERT INTO table_name values(value11,value12,……..),

(value21,value22,……..),

(valuen1,valuen2,……..);

in this case we can insert multiple rows into the database table with the value list of each row is separated by comma.

SQL query to insert data into a Table

INSERT INTO BOOKS VALUES(‘205′,’Madhushala’,’Harivansh’,’Rai’),

(‘209′,’Historica’,’Herodotus’,’Herodotus’);

Sql query to retreive the data from the table BOOKS

query example:  SELECT *  FROM BOOKS;

OUTPUT:

ISBN_NOTITLEAUTHORFIRSTNAMEAUTHORLASTNAME
181The CastleFranzKalka
191Animal FarmGeorgeOrwell
205MadhushalaHarivanshRai
209HistoricaHerodotusHerodotus

Related Posts