×

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

How to compare date in SQL

In this section, we will learn about how dates can be compared in SQL. We can compare any random date with another date stored in a column of a table.This comparison...

4 minutes read.

SQL Formatter

As a beginner, one does not focus much on Formatting the queries while writing their code. This leads to a great confusion while referring the code in future. For a...

5 minutes read.

SQL Comparision Operator

The Comparison Operator compares different data of the Structured Query Language table and checks whether the data are the same, less than, greater than, less than, or greater than equal....

14 minutes read.

How to Update Table in SQL?

How to Update Table in SQL Introduction UPDATE query is used to update a record in a table. UPDATE is a DML command, which operates on the data of the table and not...

4 minutes read.

Where Condition in SQL

WHERE clause is used with the Data Manipulation Language Command in SQL, the Data Manipulation Language commands are the SELECT statement, UPDATE statement, and DELETE statement. WHERE clause condition is an...

5 minutes read.

Drop vs Truncate in SQL

In this article, we will learn and understand the Drop and Truncate commands and the difference between these two commands. What is Drop Command? Drop is a Data Definition Language command in...

6 minutes read.

SQL Operators

Arithmetic Operators Arithmetic operators are +, -, *, /, % performs addition, subtraction, multiplication, division, modulo respectively. Example:   Select 100+222; Select salary+100 From teacher Where teacher_id=1; Following output screen shows different arithmetic operations. We...

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 Tutorial for Beginners

SQL tutorial provides basic and advanced concepts of Structured Query Language and how you deploy SQL to work with a relational database system. Our SQL tutorial is designed for beginners...

3 minutes read.

SQL Truncate

This command deletes all records from table. Truncate is a DDL command. Syntax: TRUNCATE table table_name; Example: Truncate table teacher; ORDER BY The ORDER BY clause arranges the table or column in ascending...

5 minutes read.

DDL Commands in SQL

DDL stands for Data Definition Language. Data Definition Language is a bunch of SQL commands used to create, modify and delete Database schema but not the records or data. Data Definition...

5 minutes read.

SQL Handling Duplicate

Removing Duplicates using DISTINCT Keyword: By using the DISTINCT keyword in SQL we can remove duplicate characters from tables or databases. A table contains more duplicate values and duplicate values can cause...

4 minutes read.

SQL COPY Table

In this tutorial, we will learn how to copy tables in SQL with the help of examples. Using the SELECT INTO statement in the SQL we can copy one table into...

4 minutes read.

SQL SELECT OR Operator

This SQL tutorial explains and helps us understand how to use the OR operator in the SELECT query with examples. The OR operator in the Structured Query Language is used to...

3 minutes read.

SQL Queries

In a database, queries are used to request the result set of data from the table or action on the records. A Query can answer your simple or complicated question, perform...

5 minutes read.

SQL ORDER BY

SQL ORDER BY The SQL ORDER BY clause is used to sort the data stored in tables in the database. The sorting can be done in an ascending way, descending way,...

5 minutes read.

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...

4 minutes read.

SQL INSERT Table

In this tutorial, we will help you to understand and learn how to add records to the table in SQL with the help of examples. SQL INSERT query is used to...

5 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.

WHERE Clause vs HAVING Clause

The WHERE Clause and HAVING clause filter the records in the Structured Query Language queries. The main difference between the WHERE clause and the HAVING clause is the WHERE clause...

5 minutes read.