Insert query in mysql

Insert query in mysql

Blog Bustle 25/01/2020

What is insert query in mysql?

insert query is used to insert new records in mysql table.

Insert query syntax

insert into table_name (column_1,column_2,column_3,....)

values (value_1,value_2,value_3,....);

There are some ways to write insert query in mysql table.

Method 1: We have to specify both column name and it's value

A. when column squence is not changed

insert into student(name,email,mobile,address)

values('mohit','mohit@gmail.com','1234567890','delhi');

insert query in mysql

B. when column squence is changed

insert into student(email,mobile,address,name)

values('mohit@gmail.com','1234567890','delhi','mohit');

insert query in mysql

in student table 'id' is primery key. you don't need to write column 'id' and it's value in insert query in this method.

Method 2: Specify only column's value

If you are not changing column sequence in mysql insert query then you can also write insert query this way.

insert into student values('3','mohit','mohit@gmail.com','1234567890','delhi');

insert query in mysql

Note: if you can not add some column value in student table

for example you dont want to insert address value in student table then your query will be

insert into student(name,email,mobile)

values('mohit','mohit@gmail.com','1234567890');

If address default value is set to null its value will be null otherwise empty.

Other important links

Update query in mysql

Delete query in mysql

Select query in mysql

Difference between sql and mysql

Create Database in mysql

Insert query in mysql searches:

Tags: #mysql