How to insert data into MySQL Table?

How to insert data into MySQL Table?

Hi,

How to insert the data into MySQL Database? Please explain me with the examples and videos thanks.

Thanks

View Answers

June 26, 2016 at 2:16 AM

Hi,

The insert into query is used to insert the data into MySQL table. Suppose we have a table:

CREATE TABLE email
(
    first_name varchar(20),
    last_name varchar(20),
    email varchar(40),
    email_count Int
)

Then we can use the following query to insert the data:

insert into email(first_name,last_name,email,email_count)
values('Deepak','Kumar','[email protected]',100);

Thanks


June 26, 2016 at 2:20 AM

There are three ways you can run the insert query:

  1. With all fields in the query:

    insert into email(firstname,lastname,email,email_count) values('Deepak','Kumar','[email protected]',100);

  2. Without fields in the insert query. Here values for all the columns is to be provided:

    insert into email values('Rajeev','Singh','[email protected]',500);

    insert into email values('Dinesh','Singh','[email protected]',200);

    insert into email values('John','T','[email protected]',400);

  3. Insert values in selective columns:

    insert into email(firstname,lastname,email_count) values('Ishu','roy',800) ;

Thanks


June 26, 2016 at 2:21 AM

Hi,

Here is the queries in correct format:

insert into email(first_name,last_name,email,email_count)
values('Deepak','Kumar','[email protected]',100);

insert into email
values('Rajeev','Singh','[email protected]',500);


insert into email
values('Dinesh','Singh','[email protected]',200);


insert into email
values('John','T','[email protected]',400);

insert into email(first_name,last_name,email_count)
values('Ishu','roy',800) ;

Thaks


June 26, 2016 at 2:22 AM

Hi,

Full output of MySQL client tool:

mysql> describe email;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| first_name  | varchar(20) | YES  |     | NULL    |       |
| last_name   | varchar(20) | YES  |     | NULL    |       |
| email       | varchar(40) | YES  |     | NULL    |       |
| email_count | int(11)     | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into email(first_name,last_name,email,email_count)
    -> values('Deepak','Kumar','[email protected]',100)
    -> ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
+------------+-----------+----------------------+-------------+
1 row in set (0.00 sec)

mysql> insert into email
    ->         values('Rajeev','Singh','[email protected]',500);
Query OK, 1 row affected (0.00 sec)

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
+------------+-----------+----------------------+-------------+
2 rows in set (0.00 sec)

mysql> insert into email
    ->         values('Dinesh','Singh','[email protected]',200);
Query OK, 1 row affected (0.01 sec)

mysql> insert into email
    ->         values('John','T','[email protected]',400);
Query OK, 1 row affected (0.01 sec)

mysql> insert into email(first_name,last_name,email_count)
    -> values('Ishu','roy',800) ;
Query OK, 1 row affected (0.00 sec)

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
| John       | T         | [email protected]   |         400 |
| Ishu       | roy       | NULL                 |         800 |
+------------+-----------+----------------------+-------------+
5 rows in set (0.00 sec)

mysql>

Thanks

Ads









Related Tutorials/Questions & Answers:
How to insert data into MySQL Table?
Purge Data from Mysql tables
Advertisements
what is the jsp coding to insert a data in database tables
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java
How to insert clob data??
how to insert excel file into mysql datbase in servlet
Uploading Excel sheet record in JSP to insert data in MySql
insert data into mysql databse using swing
JDBC Video Tutorial- How to insert data into MySQL database table?
How to insert image in MySQL database using sql query?
Mysql Multiple Date Insert
how to insert data from netbeans into databse
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans
Mysql Multiple Date Insert
single query to insert the data
mysql select from multiple tables
How to compare two tables, and insert values which r not in one table to another table?
How to insert data from a combobox and textbox values into DB using JSP?
how to insert data in database using html+jsp
Mysql Insert
how to insert data into database using jsp & retrive
Create Database and tables in MySQL
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc
how to insert data into databasse by using jdbc
How to delete data from MySQL?
how to insert, retrieve data from,to db(code)....
MySQL BIGINT
Different tables present in MySQL
how to insert, retrieve data from,to db(code)....
how to post data in mysql php form
insert query in mysql
How to insert and retreive an image in mysql database using spring mvc framework???
How to Generate XML files from the data in DB tables?
Mysql List Tables
ModuleNotFoundError: No module named 'tableh'
Mysql Join 3 Tables
example of before insert trigger in mysql
Servlet Example To Insert Mysql Clob Data
How to insert data from textfields into database using hibernate?
How to Insert image and data both together in database in JSP/Servlet ?
how to insert array data into sql server using jsp
How to insert data into databse by JSP form registration page in netbeans
how to store JTree data hierarchically in mysql database from netbeans
Insert data in mysql database through jsp using prepared statement
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array

Ads