INSERT Statement MYSQL

As we have a new table ‘Persons’ now, it’s time to insert data into the table that we just created

The INSERT INTO statement can be insert new records in a table

It is possible to write the INSERT INTO statement in two ways.


Syntax:

The first way specifies both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, …)
VALUES (value1, value2, value3, …);

Or

Second way specifies just the values

INSERT INTO table_name
VALUES (value1, value2, value3, …);

Query:

INSERT INTO `persons`(`PersonID`, `LastName`, `FirstName`, `Address`, `City`) 
VALUES (1,'Bawankar','Rajiv','Ashok Nagar','Mumbai')


Output
:

Insert row Example

As you see above one row of data is inserted into the table.


Insert Multiple row

Query:

INSERT INTO `persons`(`PersonID`, `LastName`, `FirstName`, `Address`, `City`) VALUES

(1,'Singh','Mohan','HRS','Delhi'),

(1,'Nair','Sonu','Shenoy Nagar','Chennai'),

(1,'Samini','Sanjay','','Bengaluru')

Output:

Insert Multiple row Example

As you see above multiple rows of data is inserted into the table with one sql command

Tester Usage Tips:

  • Insert data into the table for application or data testing
  • Validate sequence columns like autogenerated product unique Id’s
  • Insert partial columns data to validate if the data can be inserted with mandatory column as null
  • Validate different data formats validation like max length, text format etc.