INSERT statement in MySQL
Hello and
welcome everyone. In this article, we will learn about INSERT INTO statement in
MySQL. Let’s go.
MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/
C# basic course click on: https://www.udemy.com/learn-csharp-with-sagar-jaybhay/
Web API 2- .Net Core In depth In 5 Hours click
on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/
INSERT
INTO
The MySQL
server database system is store data in the rows and column wise in table.
Using INSERT INTO statement you can insert data in row format. It allows you to
insert data one or more rows format into the table. INSERT INTO command creates
a new row in the table to store data in table.
The
following are the INSERT INTO syntax
INSERT INTO table_name (column_1,
column_2, column_3, …)
VALUES
(value_1,
value_2, value_3,…);
Here is the INSERT INTO is
the command that you insert the data in table.
table_name - which table you want to insert the data.
column_1, column_2,
column_3, … - you can specified the column to be updated in the new row.
VALUES (value_1, value_2,
value_3,…) – here is you can specifies the values to be added into the new row
in table.
NOTE 1: if you want to add values for all the column of the table, then
you do not need to specify the column names in the above syntax, but one thing
is important is that the order of the values is in the same order as the
columns in the table. Following is the syntax you can use for adding values for
all the columns of the table:
INSERT
INTO table_name
VALUES (value_1, value_2, value_3,…);
For
example:
Here is the, we will create table for
employee in the database.
CREATE
TABLE IF NOT EXISTS employee (
e_id
int (10) PRIMARY KEY,
e_firstname
varchar (50) NOT NULL,
e_lastname
varchar (50) NOT NULL,
e_age
int (10),
e_city
varchar (250)
e_sex
char (1)
e_phnumber
int (15) NOT NULL
)
Now using INSERT INTO statement
two formats.
One is
INSERT INTO employee
VALUES
(
1, ‘Hone’, ‘Reus’, 25, ‘San Jose’,
‘M’, ‘ + 1 886 889 1111’
)
And second one is, you can
specify the column name to insert values.
INSERT INTO employee (
‘e_id’, ’e_firstname’, ’e_lastname’,
’e_age’, ’e_city’, ’e_sex’,
’e_phnumber’
)
VALUES
(
1, ‘Hone’, ‘Reus’, 25, ‘San Jose’, ‘M’, ‘ +
1 555 555 1111’
),
(
2, ‘Cries’, ’Fence’, 23, ’Fresno’, ’F’, ’
+1 555 555 1111’
);
NOTE 2: The string or character values should be use single quotes ( ‘ ‘
) and number values do not need to use single quotes ( ‘ ‘ ).
NOTE 3: When you insert values into the table, then you must provide a
value for every NOT NULL column.
You can see inserted row
into the table using following query:
SELECT * FROM employee
Then it will show you
inserted values in the table.
In this article we are
learn about INSERT INTO statement in the MySQL.
MongoDB with .Net Core course link => https://www.udemy.com/mongodb-with-net-core-sagar-jaybhay/
C# basic course click on: https://www.udemy.com/learn-csharp-with-sagar-jaybhay/
Web API 2- .Net Core In depth In 5 Hours click
on: https://www.udemy.com/web-api-2-net-core-in-depth-in-5-hrs-with-sagar-jaybhay/
Comments
Post a Comment