×

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

SQL SELECT IN

SQL SELECT IN is a logical operator in Structured Query Language. It is used in SQL queries to reduce the use of multiple 'OR' operators. s The IN operator in SQL...

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

How to use the BETWEEN operator in SQL

In this entire SQL article, we will understand and learn about the BETWEEN operator concept and how to use it in SQL. What is the BETWEEN operator in SQL? The Between operator...

4 minutes read.

Difference between SQL and NoSQL

SQL vs. NoSQL | Difference between SQL and NoSQL Choosing a database is the most fundamental decision that needs to be decided before starting a task. Relational and non-relational databases are...

3 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 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 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 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 Injection

SQL injection is a technique, this may destroy the database. It is one type of hacking technique. SQL IN WEB PAGES: Injection occurs when we ask for input like an id or...

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

Nth highest salary

The most common and important question asked in interviews that how we can find the Nth highest salary in a table (2nd highest salary, 3rd highest salary, or Nth highest...

6 minutes read.

SQL Cloning Tables

Cloning a Table: To create a copy of the table. To perform the operations, without affecting the actual table. Steps for creating a Cloning Table: Step 1: Empty Table Creation The syntax for Creating...

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

SQL DROP Database

This tutorial will help us understand how to drop a database from the SQL Server with a few examples. The DROP command removes all the objects stored in the database and...

4 minutes read.

space() function in SQL

 This function returns a string with a specified number of spaces. If we specify a number, it returns the strings having that specified number of spaces. SPACE Function is available...

2 minutes read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.

How to delete a row in SQL

Introduction To delete or remove the unused/unwanted rows from a table, DELETE command is used in SQL.DELETE command removes the entire record from a table.The DELETE statement can delete one or...

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

How to delete column in table

Introduction In SQL, sometimes it is required to delete a column of a table.The use of ALTER TABLE command with DROP COLUMN clause will serve the purpose to delete/remove a column...

4 minutes read.