menu

SQL – INSERT

SQL – INSERT Statement :

SQL INSERT INTO Statemet is used to insert new row(ie. record) in table.

SQL INSERT INTO Syntax :

INSERT INTO TableName VALUES(Value1,Value2,….);

Note : The Above Sytax inserts rows in all columns of the table .

If You want to insert values in seleted columns the following syntax is used :

INSERT INTO TableName (ColumnName1,ColumnName2,….)VALUES(Value1,Value2,….);

EXAMPLE 1 (Insert in all column) :

Example

INSERT INTO Users VALUES(‘1′,’John’,’john@yahoo.com’,’USA’,’NewYork’);

1 New row will be inserted.

Now the table has its first record after the selection it will show :

MysqlInsertStatement

EXAMPLE 2 (Insert in few columns only) :

Example

INSERT INTO Users (ID,Name,Email)VALUES(‘2′,’Devid’,’david@yahoo.com’);

Note : We need to specify the column name in which we want to insert values Like If want to insert values in ID, Name and Email Columns only. .

Now the table will look like :

SQL - INSERT-in-Selected-columns

Sql-INsert-in-Selected-columns



Leave a Reply