banner



How To Add Data In Table Mariadb

totn MariaDB


MariaDB: INSERT Argument

This MariaDB tutorial explains how to use the MariaDB INSERT argument with syntax and examples.

Description

The MariaDB INSERT statement is used to insert a unmarried record or multiple records into a table in MariaDB.

Syntax

The syntax for the MariaDB INSERT statement when inserting a single record using the VALUES keyword is:

INSERT INTO table (column1, column2, ... ) VALUES (expression1, expression2, ... ), (expression1, expression2, ... ), ...;

OR

The syntax for the INSERT argument when inserting multiple records using a sub-select in MariaDB is:

INSERT INTO table (column1, column2, ... ) SELECT expression1, expression2, ... FROM source_table [WHERE conditions];

Parameters or Arguments

table
The table to insert the records into.
column1, column2
The columns in the table to insert values.
expression1, expression2
The values to assign to the columns in the tabular array. So column1 would be assigned the value of expression1, column2 would be assigned the value of expression2, and so on.
source_table
The source tabular array when inserting data from some other table.
WHERE conditions
Optional. The conditions that must be met for the records to exist inserted.

Note

  • When inserting records into a tabular array using the MariaDB INSERT statement, you must provide a value for every Not Zero column.
  • You lot can omit a column from the MariaDB INSERT statement if the cavalcade allows Goose egg values.

Example - Using VALUES keyword

Allow's look at how to utilise the INSERT statement in MariaDB using the VALUES keyword.

For example:

INSERT INTO sites (site_id, site_name) VALUES (one, 'TechOnTheNet.com');

This MariaDB INSERT statement would outcome in one record being inserted into the sites table. This new record would have a site_id of 1 and a site_name of 'TechOnTheNet.com'.

You lot could apply the syntax in a higher place to insert more than one tape at a time.

For example:

INSERT INTO sites (site_id, site_name) VALUES (i, 'TechOnTheNet.com'), (2, 'CheckYourMath.com');

This INSERT example would result in two records existence inserted into the sites table. The showtime record would have a site_id of 1 and a site_name of 'TechOnTheNet.com'. The 2d record would have a site_id of 2 and a site_name of 'CheckYourMath.com'.

This would be equivalent to the following 2 INSERT statements:

INSERT INTO sites (site_id, site_name) VALUES (1, 'TechOnTheNet.com');  INSERT INTO sites (site_id, site_name) VALUES (ii, 'CheckYourMath.com');

Example - Using sub-select

Next, let'southward expect at how to use the INSERT statement in MariaDB using a sub-select.

For example:

INSERT INTO contacts (contact_id, contact_name) SELECT site_id, site_name FROM sites WHERE site_name = 'TechOnTheNet.com';

Past placing a SELECT statement within the INSERT statement, you lot can perform multiples inserts chop-chop.

With this type of INSERT statement, you may wish to cheque for the number of rows being inserted. You can determine the number of rows that will be inserted past running the post-obit MariaDB SELECT statement before performing the insert.

SELECT COUNT(*) FROM sites WHERE site_name = 'TechOnTheNet.com';

How To Add Data In Table Mariadb,

Source: https://www.techonthenet.com/mariadb/insert.php

Posted by: sotocapts1955.blogspot.com

0 Response to "How To Add Data In Table Mariadb"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel