SQL – INSERT

SQL – INSERT Statement:

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

SQL INSERT INTO Syntax:

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

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

If You want to insert values in selected 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


Advertisements

Add Comment

📖 Read More