How to insert data into tables in mysql with examples

After creating tables in mysql, next step is to insert values or row into tables.
Follow bellowing steps to insert value into tables.

Syntax:-

INSERT INTO table_name (col_name1, col_name2,..col_namen) VALUES(col_name1_data,col_name2_data...col_namen_data);

Note:-

# Order of column name and values/data must match each other.
# Column values must be matching to data type of that column.
# mysql command are case insensitive.
# Character type data much be inside "".
# you can skip value/data for any column in table, mysql automatically insert NULL
(charter datatype) 0 (int datatype) to skipped values.
# Column name are case insensitive.


Examples:-

1. we inserting data into homedetails table.

INSERT INTO homedetails (homeno,homename,state,country) VALUES(206,"chiguru",”karnataka”,”india”);

homeno homename state city
206 chiguru karnataka india

2. order of column name in homedetails table are changed.

INSERT INTO homedetails (homename,state,homeno,country) VALUES("guru","kerala",20,”india”);

homeno homename state country
206 chiguru karnataka india
20 guru kerala india

3. value/data are skipped.


INSERT INTO homedetails (homeno,homename,country) VALUES(895,"gtog",”USA”);

homeno homename state country
206 chiguru karnataka india
20 guru kerala india
895 gtog NULL USA

4. Column name are case insensitive.

INSERT INTO homedetails (homEno,hoMenAme,State,cOUntrY) VALUES(58,"SRI Ram",”karnatAKA”,”India”);

homeno homename state country
206 chiguru karnataka india
20 guru kerala india
895 gtog NULL USA
58 SRI RAM karnatAKA India

4. If data are in order.

INSERT INTO homedetails VALUES(28,"krish",”goa”,”india”);

Note:- Data must be same order of that of columns in homedetails table.

homeno homename state country
206 chiguru karnataka india
20 guru kerala india
895 gtog NULL USA
58 SRI RAM karnatAKA India
28 krish goa India

Previous Code:-
Delete column from tables

List Code:-
Mysql Codes

Next Code:-
Update data in tables

Leave reply

Add your comments here

Back to Top