codescracker


sql

SQL Insert Into



« Previous Tutorial Next Tutorial »


SQL INSERT INTO statement is used to add new rows of data or new records in the table. Here is the general form to use INSERT INTO statement in SQL to insert record in the table:

INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);

Note - You mayn't need to specify the column(s) name in SQL query in case if you are adding values of all the columns of the table. But you need to check that the order must be in the same order as the columns present in the table.

SQL INSERT INTO Example

Here is an example of INSERT INTO statement in SQL to insert new record in the table. Here, following SQL statements creates ten records in the table named CUSTOMERS. Enter the query one by one, you can also do copy and paste to save your time.

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Awanish Rai', 30, 'New Delhi', 76000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, 'Shubham Singh', 31, 'Noida', 86000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'Ritesh Kumar Singh', 33, 'Gurgaon', 95000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, 'Aman Singh', 35, 'Mumbai', 65000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, 'Shubham Shrivastava', 29, 'Greater Noida', 85000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, 'Saurav Verma', 32, 'MP', 87500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (7, 'Praveen Datt Pathak', 31, 'Ghaziabad', 86000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (8, 'Sachin Sethi', 33, 'Ghaziabad', 98000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (9, 'Yogesh Yadav', 31, 'Chandigarh', 79000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (10, 'Ashutosh Pandey', 29, 'Chennai', 78000.00 );

Run all the above SQL Statements one by one to insert all the records (given above) into the table.

After performing all the above 10 statements, it would produce the following records in the table CUSTOMERS:

You have to just query this SQL statement, to watch your created table:

select * from customers;

It would display the created table shown here:

SQL insert into

SQL Insert Data Only in Specified Columns

You can also insert data only in the specified columns. The following SQL statements will insert a new row, but only insert the data in the following columns:

INSERT INTO Customers (ID, NAME, ADDRESS, SALARY)
VALUES (11, 'Aniruddh Sharma', 'Ghaziabad', 89000.00);

It will display this output as 1 rows inserted:

sql insert into statement

Now, type the query this to get the result of the new updated table:

select * from customers;

It will display this output:

SQL Row Inserted Table

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test