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_NO | NAME | AGE | CITY |
---|---|---|---|
1 | PRAYAG | 21 | RANCHI |
2 | RAHUL | 25 | PATNA |
3 | REKHA | 19 | DELHI |
4 | PANKAJ | 23 | GUJRAT |
5 | PREM | 27 | CHENNAI |
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_NO | NAME | AGE | CITY |
---|---|---|---|
1 | PRAYAG | 21 | RANCHI |
2 | RAHUL | 25 | PATNA |
3 | REKHA | 19 | DELHI |
4 | PANKAJ | 23 | GUJRAT |
5 | PREM | 27 | CHENNAI |
6 | AFRIN | 21 | CHENNAI |