SQL Tutorial

SQL Tutorial SQL Introduction SQL Syntax SQL Data Types SQL OPERATORS SQL COMMANDS SQL Queries

SQL Database

SQL Create Database SQL DROP Database SQL SELECT Database

SQL Table

SQL TABLE SQL CREATE TABLE SQL COPY TABLE SQL ALTER TABLE SQL DELETE SQL TRUNCATE TABLE SQL DROP TABLE SQL UPDATE TABLE SQL INSERT TABLE

SQL SELECT

SQL SELECT Statement SQL SELECT WHERE Clause SQL SELECT IN Operator SQL BETWEEN Operator SQL SELECT BETWEEN Operator SQL SELECT AND Operator SQL SELECT OR Operator SQL SELECT LIKE Operator SQL SELECT DISTINCT SQL SELECT SUM SQL SELECT MAX SQL SELECT MIN SQL SELECT AVG

SQL Clause

SQL WHERE Clause SQL GROUP BY CLAUSE SQL ORDER BY Clause SQL HAVING Clause

SQL INSERT

SQL INSERT Statement SQL INSERT INTO Statement SQL INSERT INTO Values SQL INSERT INTO SELECT SQL Insert multiple rows

SQL JOIN

SQL JOIN SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL CROSS Join

SQL OPERATOR

SQL Comparison SQL LOGICAL Operator SQL Cast Operator SQL Arithmetic

Difference

SQL vs NOSQL WHERE vs HAVING DELETE vs DROP GROUP BY vs ORDER BY DROP vs TRUNCATE SQL IN vs SQL EXISTS Difference between Delete, Drop and Truncate in SQL

MISC

SQL SubQuery SQL CASE Commit and Rollback in SQL Pattern Matching in SQL DDL Commands in SQL DML Commands in SQL Types of SQL Commands SQL COUNT SQL Primary Key SQL FOREIGN KEY SET Operators in SQL Check Constraint in SQL SQL EXCEPT SQL VIEW SQL WHERE Statement SQL CRUD Operation Where Condition in SQL TCL Commands in SQL Types of SQL JOINS SQL Nth Highest Salary SQL NOT OPERATOR SQL UNION ALL SQL INTERSECT SQL Data Definition Language SQL Data Manipulation Language SQL Data Control Language SQL CONSTRAINTS SQL Aggregate Operators SQL KEYS Codd’s Rules in SQL What is SQL Injection? Trigger In SQL SQL WHERE Multiple Conditions Truncate function in SQL SQL Formatter WEB SQL SQL Auto Increment Save Point in SQL space() function in SQL SQL Aggregate Functions SQL Topological Sorting SQL Injection SQL Cloning Tables SQL Aliases SQL Handling Duplicate Update Query in SQL Grant Command in SQL SQL SET Keyword SQL Order BY LIMIT SQL Order BY RANDOM

How To

How to use the BETWEEN operator in SQL How To Use INNER JOIN In SQL How to use LIKE in SQL How to use HAVING Clause in SQL How to use GROUP BY Clause in SQL How To Remove Duplicates In SQL How To Delete A Row In SQL How to add column in table in SQL ? How to drop a column in SQL? How to create a database in SQL? How to use COUNT in SQL? How to Create Temporary Table in SQL? How to Add Foreign Key in SQL? How to Add Comments in SQL? How To Use Group By Clause In SQL How To Use Having Clause In SQL How To Delete Column In Table How To Compare Date In SQL How index works in SQL How to calculate age from Date of Birth in SQL How to Rename Column name in SQL What are single row and multiple row subqueries?

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”, “[email protected]”)  
Insert into worker VALUES (“Keerthi”, “Jaipur”, “[email protected]”),
Insert into worker VALUES (“Saleem”, “Hyderabad”, “[email protected]”),
Insert into worker VALUES(“Arjun”, “London”, “[email protected]”),
Insert into worker VALUES (“Ritika”,” Paris”, “[email protected]”);
Insert into worker VALUES (“Priyanka”, “Washington DC”,“[email protected]”);
Insert into worker VALUES (“Jimmy”, “Berlin”, “[email protected]”);
Insert into worker VALUES (“Kalyan”, “Mumbai”, “[email protected]”);

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

SELECT * FROM worker;

Output:

NameCityEmail
RameshHyderabad[email protected]
KeerthiJaipur[email protected]
SaleemHyderabad[email protected]
ArjunLondon[email protected]
RitikaParis[email protected]
PriyankaWashington DC[email protected]
JimmyBerlin[email protected]
KalyanMumbai[email protected]

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.