SQL INSERT INTO VALUE EXAMPLE

aimtocode

SQL INSERT INTO VALUE

In simple form, the syntax for the INSERT statement when inserting a single record using the VALUES keyword in SQL Server is:

INSERT INTO table
(column1, column2, ... )
VALUES
(expression1, expression2, ... ),
(expression1, expression2, ... ),
...;

However, the full syntax for the INSERT statement when inserting a single record using the VALUES keyword in SQL Server (Transact-SQL) is:

INSERT INTO table
(column1, column2, ... )
VALUES
( DEFAULT | NULL | expression1, 
  DEFAULT | NULL | expression2, 
  ...
);

Let's take an example of table which has five records within it.

INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (1, PRAYAG, 21, RANCHI);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (2, RAHUL, 25, PATNA);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (3, REKHA, 19, DELHI);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (4, PANKAJ, 23, GUJRAT);
INSERT INTO STUDENTS (ROLL_NO, NAME, AGE, CITY)
VALUES (5, PREM, 27, CHENNAI);

It will show the following table as the final result.

ROLL_NONAME AGECITY
1PRAYAG21RANCHI
2RAHUL25PATNA
3REKHA19DELHI
4PANKAJ23GUJRAT
5PREM27CHENNAI

You can create a record in CUSTOMERS table by using this syntax also.

INSERT INTO CUSTOMERS 
VALUES (6, AFRIN, 21, CHENNAI);

The following table will be as follow:

ROLL_NONAME AGECITY
1PRAYAG21RANCHI
2RAHUL25PATNA
3REKHA19DELHI
4PANKAJ23GUJRAT
5PREM27CHENNAI
6AFRIN21CHENNAI
aimtocode