MySQL INSERT INTO Statement

MySQL | INSERT INTO: Learn about the MySQL INSERT INTO Statement, with its explanation, syntax, and query examples. How to insert records into a table in MySQL?
Submitted by Apurva Mathur, on September 03, 2022

INSERT INTO Statement - Inserting Records into a Table

After creating a database and a table, now we will learn how can we insert records into a table. For that, we use INSERT INTO statement. INSERT INTO statement helps us to store the records in the database table.

INSERT INTO Statement Syntax

INSERT INTO table_name (column_name1, column_name2, ...)
VALUES (value1, value2...);

Let us insert the value in the database considering the following database:

INSERT INTO statement step (1)

Suppose, we have a database named "studentdb", and inside that database, we have a table named "student_details". In the following columns to insert the values, we'll use the following query:

INSERT INTO  student_details (`ID`, `Student_name`, `Student_department`, `Year`, `Gender`)
VALUES ('1', 'Roshini', 'CSE', '2', 'Female');

This is how we insert the value inside our database;

INSERT INTO statement step (2)

Now if I want to insert the values in specific columns only in that case we'll use the following SQL structure:

INSERT INTO student_details (`ID`, `Student_name`, `Year`) 
VALUES ('4', 'shalini', '3');

In this case, it is important that you don't have NOT NULL constraints on your column else it will show you an error.

INSERT INTO statement step (3)

Now let us see how we insert it through the workbench.

In the workbench we directly insert the values shown in the picture;

INSERT INTO statement step (4)

After writing the values click on apply and simply refresh the page your values are inserted successfully.

INSERT INTO statement step (5)


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.