Advantages of INSERT INTO SET in MySQL

Advantages of INSERT INTO SET in MySQL

Insert data into mysql database. Previously commonly used

INSERT INTO table name (column name 1, column name 2…) VALUES (column value 1, column value 2);
If it is in a PHP program, it will be written as follows (adding products to the product library)
$sql = "INSERT INTO products (p_title,p_price.........) VALUES ('$p_title','$p_price'............)";
The disadvantage is that when the table has a lot of columns, it will be very messy.
  • 1. The front and back need to correspond, and it is easy to write the wrong order.
  • 2. Later changes (add columns, reduce columns) are made after the front part, which is scattered and easy to make mistakes.
  • 3. Difficulty in reading.
In fact, you can use
INSERT INTO table name SET column name 1 = column value 1, column name 2 = column value 2,...;
If it is in a PHP program, it will be written as follows (adding products to the product library):
$sql = " INSERT INTO products SET
            p_title = '$p_title',
               p_price = '$p_price',
            ...
   ";
This makes it clear and easy to check for errors.
And it has some common parts with the update statement, which makes it easier to reuse.
However, you cannot add data in batches using the INSERT INTO SET method. If you want to add data in batches, use this method (example)
$sql = "INSERT INTO products (p_title,p_price) VALUES ('apple','5 yuan'),('lychee','10 yuan'),('red dates','8 yuan')";

The above is the advantages of INSERT INTO SET in MySQL that I would like to introduce to you. I hope it will be helpful to you. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • php mysql insert into with detailed explanation and example code
  • Correct use of MySQL INSERT INTO statement
  • Example of using INSERT INTO statement to update multiple records in MySql
  • Analysis of the usage of Insert Into data insertion in PHP+MySQL
  • Insert into xxx on duplicate key update problem in Mysql

<<:  Docker installation of Nginx problems and error analysis

>>:  Essential knowledge for web development interviews and written tests (must read)

Recommend

The difference between ${param} and #{param} in MySQL

The parameter passed by ${param} will be treated ...

Detailed example of locating and optimizing slow query sql in MySQL

Table of contents 1. How to locate and optimize s...

MySQL view principles and basic operation examples

This article uses examples to illustrate the prin...

Example analysis of the principle and solution of MySQL sliding order problem

This article uses examples to explain the princip...

Let's talk about the difference between containers and images in Docker

What is a mirror? An image can be seen as a file ...

Some Linux file permission management methods you may not know

Why do we need permission management? 1. Computer...

MySQL Workbench download and use tutorial detailed explanation

1. Download MySQL Workbench Workbench is a graphi...

Summary of MySQL stored procedure permission issues

MySQL stored procedures, yes, look like very rare...

Div css naming standards css class naming rules (in line with SEO standards)

There are many tasks to be done in search engine o...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

Analysis of MySQL joint index function and usage examples

This article uses examples to illustrate the func...

Summary of commonly used CSS encapsulation methods

1. pc-reset PC style initialization /* normalize....

25 div+css programming tips and tricks

1. The ul tag has a padding value by default in M...

HTML5+CSS3 header creation example and update

Last time, we came up with two header layouts, on...