MariaDB INSERT
The MariaDB INSERT INTO statement is used to insert records into a table.
Syntax:
INSERT into table_name(column_1, column_2, ... column_n ) VALUES(value1, value2, .. valuen);
Example 1: Single record insertion:
Players table before insertion:
ID NAME SPORTS 1 Sachin Cricket 2 Dhoni Cricket
INSERT INTO Players (id, name, sports) VALUES (3, 'Sunil’, ‘Football’); |
Explanation:
The ‘players’ is an already created table with some records. Now we are adding a new row of records under the respective columns with the corresponding values: 3, ‘Sunil’ and ‘Football’. Verify the insertion, using the SELECT statement.
SELECT * FROM Players;
OutPut:
Players table after insertion:
ID NAME SPORTS 1 Sachin Cricket 2 Dhoni Cricket 3 Sunil Football
Example 2: Multiple record insertion:
Players table before insertion:
ID NAME SPORTS 1 Sachin Cricket 2 Dhoni Cricket 3 Sunil Football
INSERT INTO Players (id, name, sports) VALUES (4, 'Srikanth’, ‘Badminton’), (5, 'Mary’, ‘Boxing’); |
Explanation:
The ‘players’ is an already created table with some records. Now we are adding multiple new rows of records under the respective columns with the corresponding values. Verify the insertion, using the SELECT statement.
SELECT * FROM Players;
Output:
Players table after insertion:
ID NAME SPORTS 1 Sachin Cricket 2 Dhoni Cricket 3 Sunil Football 4 Srikanth Badminton 5 Mary Boxing