×

SQL INSERT INTO Values

This article will help you in getting a better understanding of a very important SQL INSERT INTO VALUES function.

INSERT INTO statement is used to insert or add a new record into a particular/specific table.

New records can be inserted into a table in the following two ways:

  1. Inserting only values
  2. Inserting both column names and values

This article will mainly focus on Inserting only values method.

Inserting only Values:

By using this method only values can be inserted into the table. The syntax is mentioned below.

Syntax:

INSERT INTO table_name VALUES(val1, val2, val3………...)

Here table_name represents the name of the table into which the records are inserted.

val1, val2, val3……… represent the values that are to be inserted into the table.

Examples of Insert into values

Example 1:

Let us create a table called Player_info which contains basic information related to the player and insert VALUES into it using Insert Into statement.

CREATE TABLE Player_info(
	ID INT,
	First_Name VARCHAR(255),
	Last_Name VARCHAR(255),
	Year_Of_Birth INT,
	DayOfYear_Of_Birth INT,
	Place_Of_Birth VARCHAR(255),
	Country VARCHAR(255),
	PRIMARY KEY (ID)
);
INSERT INTO Player_info VALUES(1, 'Sanju', 'Samson', 1981, 340, 'Kerala', 'India');
INSERT INTO Player_info VALUES(2, 'Jonathan', 'Trott', 1981, 114, 'CapeTown', 'SouthAfrica');
INSERT INTO Player_info VALUES(3, 'Lasith', 'Malinga', 1977, 303, 'Matale', 'Srilanka');
INSERT INTO Player_info VALUES(4, 'Virat', 'Kohli', 1988, 310, 'Delhi', 'India');
INSERT INTO Player_info VALUES(5, 'Karn', 'Sharma’, 1987, 126, 'Haryana', 'India');
INSERT INTO Player_info VALUES(6, 'Ravindra', 'Jadeja', 1988, 341, 'Nagpur', 'India');
INSERT INTO Player_info VALUES(7, 'Stuart', 'Broad’, 1982, 186, 'Manchester', 'England');

We can check the data of table by using the following command:

SELECT * FROM Player_info;

Output:

First_NameLast_NameYear_Of_BirthDayOfYear_Of_BirthPlace_Of_BirthCountry
SanjuSamson1981340KeralaIndia
JonathanTrott1981114CapetownSouth Africa
LasithMalinga1977303MataleSrilanka
ViratKohli1988310DelhiIndia
KarnSharma1987126HaryanaIndia
RavindraJadeja1988341NagpurIndia
StuartBoard1982186ManchesterEngland

Example 2:

Let us create a table called Subscription_info which consists of customer name, Subscription_type, and purchasetime, and insert VALUES into it with the help of INSERT INTO statement.

create table Subscription_info(customer_name VARCHAR(200), Subscription_ info VARCHAR(200) purchase time VARCHAR(200));

let us insert VALUES into the table.

INSERT INTO Subscription_info VALUES('Krishna', 'Gold', ‘03:13:20’);
INSERT INTO Subscription_info VALUES('Abrar', 'Basic', ‘02: 23:39’);
INSERT INTO Subscription_info VALUES('Ali', 'Premium', ‘05:45:30’);
INSERT INTO Subscription_info VALUES('Mahesh', 'Basic', ‘06:30:32’);
INSERT INTO Subscription_info VALUES('Hafeez', 'Gold', ‘11:25:35’);
INSERT INTO Subscription_info VALUES('Joseph', 'Premium', ‘10:32:50’);
INSERT INTO Subscription_info VALUES('Nikhil', 'Gold', ‘09:22:55’);
INSERT INTO Subscription_info VALUES('Ramya', 'Premium', ‘11:42:53’);
INSERT INTO Subscription_info VALUES(‘Kavya’, ‘Basic’, ‘12:30:00’);
INSERT INTO Subscription_info VALUES(‘Priyanka’, ‘Basic’, ‘10:55:00’);

We can check the data of table by using the following command:

SELECT * FROM Subscription_info;

Output:

Customer_nameSubscription_namepurchasetime
KrishnaGold03:13:20
AbrarBasic02:23:39
AliPremium05:45:30
MaheshBasic06:30:32
HafeezGold11:25:35
JosephPremium10:32:50
NikhilGold09:22:55
RamyaPremium11:42:53
KavyaBasic12:30:00
PriyankaBasic10:55:00

Example 3:

Let us create a table with the following attributes:

 CREATE TABLE worker( Namevarchar(100), city varchar(100), email varchar(100))

Now let us insert some VALUES into this table

Insert into worker VALUES(“Ramesh”, “Hyderabad”, “ramesh@gmail.com”)  
Insert into worker VALUES (“Keerthi”, “Jaipur”, “keerthi@gmail.com”),
Insert into worker VALUES (“Saleem”, “Hyderabad”, “saleem@gmail.com”),
Insert into worker VALUES(“Arjun”, “London”, “arjun33@gmail.com”),
Insert into worker VALUES (“Ritika”,” Paris”, “ritika@gmail.com”);
Insert into worker VALUES (“Priyanka”, “Washington DC”,“priyanka@gmail.com”);
Insert into worker VALUES (“Jimmy”, “Berlin”, “jimmyjones@gmail.com”);
Insert into worker VALUES (“Kalyan”, “Mumbai”, “kalyan@gmail.com”);

We can check the data of table by using the following command:

SELECT * FROM worker;

Output:

NameCityEmail
RameshHyderabadramesh@gmail.com
KeerthiJaipurkeerthi@gmail.com
SaleemHyderabadsaleem@gmail.com
ArjunLondonarjun@gmail.com
RitikaParisritika@gmail.com
PriyankaWashington DCpriyanka@gmail.com
JimmyBerlinjimmyjones@gmail.com
KalyanMumbaikalyan@gmail.com

Example 4:

Let us create a table called product_desc which consists of the selling price, buying price, selling date, etc related details of the product.

CREATE TABLE Product_desc(
   Product_id INT AUTO_INCREMENT,  
   Product_name VARCHAR(100),
   Buying_price INT,
   Selling_price INT,
   Selling_Date Date,
  );

 Let us insert some VALUES into it.

INSERT INTO   Product_desc VALUES ('Wireless mouse’, 5000, 6000, '2019-11-12'),
   INSERT INTO   Product_desc VALUES ('Laptop', 60000, 65000, '2008-04-25'),
   INSERT INTO   Product_desc VALUES ('Tablet', 40000, 50000, '2015-07-21'),
   INSERT INTO   Product_desc VALUES ('Speaker', 2000, 2500, '2018-05-08' ),
   INSERT INTO   Product_desc VALUES ('Earphones', 1000, 1200, '2018-01-12'  ),
  INSERT INTO   Product_desc VALUES ('SSD disk’, 7500, 9000, '2020-12-11'  ),
  INSERT INTO   Product_desc VALUES ('Pendrive', 500, 700, '2021-07-06'  ),
   INSERT INTO   Product_desc VALUES ('Charging_cable',1200, 1500, '2022-04-18' ) ;

We can check the data of table by using the following command:

SELECT * FROM Product_desc;

Output:

Product_idProduct_nameBuying_priceSelling_priceSelling_date
1Wireless_mouse500060002019-11-12
2Laptop60000650002008-04-25
3Tablet40000500002015-07-21
4Speaker200025002018-05-08
5Earphones100012002018-01-12
6SSD disk750090002020-12-11
7Pendrive5007002021-07-06
8Charging_cable120015002022-04-18

Example 5:

Let us create a table called shop_timings which contains shop names and their opening time.

create table shop_timings(shop_no varchar(10), OpeningTimeStamp VARCHAR(10));

let us insert some VALUES into it.

INSERT INTO shop_timings VALUES(‘S1’, TIMESTAMP('2019-03-18', '16:12:45.765421’);
INSERT INTO shop_timings VALUES(‘S2’, TIMESTAMP('2020-11-12', '05:52:25.147236');
INSERT INTO shop_timings VALUES(‘S3’, TIMESTAMP('2019-03-05', '16:12:45.987534’);
INSERT INTO shop_timings VALUES(‘S4’, TIMESTAMP('2022-06-28', '05:02:34.549831');
INSERT INTO shop_timings VALUES(‘S5’, TIMESTAMP('2021-07-30’,’08:20:18.167865’);
INSERT INTO shop_timings VALUES(‘S6’, TIMESTAMP('2016-12-23, '18:26:41.985312’);
INSERT INTO shop_timings VALUES(‘S7’, TIMESTAMP('2019-03-18', '21:04:18.856438');

We can check the data of table by using the following command:

SELECT * FROM shop_timings;

Output:

shop_noOpeningTimeStamp
S12019-03-18   16:12:45.765421
S22020-11-12   05:52:25.147236
S32019-03-05   16:12:45.987534
S42022-06-28   05:02:34.549831
S52021-07-30   08:20:18.237865
S62016-12-23  18:26:41.985312
S72019-03-18  21:04:18.856438

This is all about INSERT INTO statement in MYSQL. Hope you understood this topic.


Related Topics

Codd’s Rules in SQL

Codd’s Rules Dr. Edgar F. Codd, in 1985, laid down 13 fundamental rules after doing large-scale research on the Relational Model of databases. According to him, every database must follow these...

3 minutes read.

DELETE VS DROP in SQL

This page contains all the information about the Delete command and Drop command concept and the difference between the DELETE and DROP commands in SQL. What is the DELETE command in...

3 minutes read.

SQL IN vs SQL EXISTS

SQL IN vs SQL EXISTS This article discusses in detail about the IN and the EXISTS operators in SQL. It is a common question between developers that what is the difference...

3 minutes read.

GROUP BY vs ORDER BY

The GROUP BY clause and ORDER BY clause in SQL are used to arrange data obtained by SQL queries. The important difference between the GROUP BY clause and ORDER BY...

4 minutes read.

SQL Select Distinct

The SQL DISTINCT query is used to fetch unique values from the tables using the SELECT statement in the SQL. There may be a situation that arises when you want to...

4 minutes read.

SQL Aggregate Operators

In SQL, the aggregate operators perform a calculation on multiple rows or multiple values of a single column and give the output a single value. Here, multiple rows of data are...

4 minutes read.

SQL Right Join

The SQL Right Join query displays all the table records and similar records from the left table. The query display zero records if it doesn’t find any similar records. If...

4 minutes read.

SQL SELECT AND Operator

This SQL tutorial explains and helps us understand how to use the AND Operator in the SELECT query with examples. The AND Operator is used to fetch the table’s records if...

2 minutes read.

SQL CREATE TABLE

In SQL tutorial, we learned and created different databases. To stores data in databases, we need to create a table. To create the table, we need to use CREATE TABLE...

5 minutes read.

SQL WHERE Statement

SQL WHERE Statement Introduction WHERE clause is used to include a condition while fetching data from tables.When you have to specify a condition that has to be obeyed while data is...

9 minutes read.

How to create a database in SQL?

How to create a database in SQL It is very necessary to create a database in order to store the data into the database.Database name must always be unique.SQL does not...

6 minutes read.

SQL Commands

SQL commands are classified into four groups on the basis of their nature. DDL (Data Definition Language) DML (Data Manipulation Language) DCL (Data Control Language) DQL (Data Query Language) NOTE: This...

1 minute read.

SQL Cast Operator

While writing SQL queries, we can see many values which are to be converted into another datatype for accessing them. In SQL this conversion is generally done by CAST function. CAST...

4 minutes read.

How to use COUNT in SQL?

How to use COUNT in SQL Introduction COUNT( ) is an aggregate function in SQL.This function counts the number of records in a table if the condition is not specified.If the condition...

4 minutes read.

How to drop a column in SQL?

How to drop a column in SQL Introduction To delete a column from an already created table, one needs to use the ALTER command along with the DROP COLUMN clause. Syntax: ALTER TABLE tablename...

4 minutes read.

SQL WHERE Multiple Conditions

In this topic, we will learn how to add multiple conditions using the WHERE clause. First, let's understand the concept of WHERE clause. WHERE clause is used to specify a condition while...

5 minutes read.

SQL WHERE Clause

The WHERE clause is a search filter that returns only true records. The WHERE clause chooses the selected records based on the given conditions. The WHERE clause is used with...

4 minutes read.

Introduction to SQL

SQL Introduction SQL is Standard Query Language. This language is used to communicate or interact with database. In other words, SQL is used to access and manage data or information...

2 minutes read.

SQL FOREIGN KEY

In this article, we will learn about the FOREIGN KEY constraints and how to define a FOREIGN KEY constraint to build the relationship between two tables. In a Relational Databases Management...

4 minutes read.

SQL Count

Structured Query Language Count() Function is used with Structured Query Language SELECT Statement. SQL Count() function returns the number of items that match the specified criteria in the SELECT statement. Count()...

2 minutes read.