In a Database Management System (DBMS), tables are used to store data in rows and columns. After creating a table, the next step is to add records to it. The INSERT INTO command is used to insert new data into a table.
This command allows users to add one or more rows of data to a table by specifying the values for each column.
The INSERT INTO query is a Data Manipulation Language (DML) command used to add new records (rows) into a table in a database.
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
If values are provided for all columns in the correct order, column names can be omitted.
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
When the INSERT INTO command is executed:
Assume we have a table named students.
| id | name | age | course |
|---|
Insert a new record:
INSERT INTO students (id, name, age, course)
VALUES (1, 'Rahul', 20, 'BCA');
After inserting the record, the table will look like this:
| id | name | age | course |
|---|---|---|---|
| 1 | Rahul | 20 | BCA |
MySQL also allows inserting multiple rows in a single query.
INSERT INTO students (id, name, age, course)
VALUES
(2, 'Anita', 21, 'BBA'),
(3, 'Rohit', 19, 'BCA'),
(4, 'Priya', 22, 'BCom');
After executing the command, the table will contain multiple records.
Example:
'Rahul'
INSERT INTO is a DML command.The INSERT INTO command is used to add new records to a table in a database. It allows users to insert data into specific columns or all columns of a table. This command plays an important role in storing and managing data within a DBMS.