SQL INSERT INTO Query
The INSERT statement is used to insert records in a table. The table selected to insert data must have the same number of columns and values. In this tutorial section, we will discuss on the Insert statement syntax with an example.
Watch this Insert query in SQL video
A Brief on the INSERT Query in SQL
Once the table is created, the next step is to insert values into it according to its constraints. The insert statement consists of two ways.
Value of the data to be inserted is specified with the column names.
Column names and values:
Column name is mentioned, and then the values are inserted.
We are using the only values method in this tutorial section. In only values, the values entered must be in an order according to the column.
INSERT INTO tablename VALUES (value1, value2,….valueN);
where INSERT INTO and VALUES are the keywords and tablename is the name of the table; value1 to valueN are the set of values, followed by a semicolon.
Values are given for each of the columns, respectively. Whenever a variable length character appears, then the values are entered in a single quote. And when an integer appears, it is written just like that.
Interested in learning SQL? Enroll in our SQL training now!
- As our employee table is created, let’s insert values into it
Insert into employee values(1,’sam’,30000,26,’male,’operation’);
- After writing the query, click on the execute button to check for errors
- Once the query is executed, a message appears like ‘Commands completed successfully’
- Repeat the procedure and create 5 more sets of entries. Once you enter the records, the employee table will be displayed as follows:
Finally, our table is ready with the values. We have inserted six records and, this is the way Insert query in SQL works. In the next tutorial section, we will learn how to select individual records from a table.
Come to Intellipaat’s SQL Community if you have more queries on SQL!