亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Database Mysql Tutorial How to write sql insert statement

How to write sql insert statement

May 15, 2019 pm 01:51 PM
insert statement sql

How to write the sql insert statement: 1. "insert into table name values ??(value 1, value 2...);", insert the specified data into the existing table; 2. "Insert into table Name 1 select * from table name 2;" to find out the data in another table and insert it into the existing table.

How to write sql insert statement

SQL's insert statement is an insert statement, which is used to insert new rows (new data) into the table.

There are three ways to write the insert statement:

1, insert into...valuesStatement

insert...values The statement inserts the specified data into the existing table, which can be divided into two situations:

1). There is no need to specify the column name of the data to be inserted, just provide the inserted value:

insert into table_name
values (value1,value2,value3,...);

2), you need to specify the column name and the value to be inserted:

insert into table_name (column1,column2,column3,...)
values (value1,value2,value3,...);

2, insert into...setstatement

Like the insert...values statement, the insert...set statement also inserts the specified data into an existing table. Basic syntax:

Insert into table_name set column1=value1,column2=value2,........;

3, insert into...select statement

insert...select statement is to query data in another table out and inserted into a ready-made table. Basic syntax:

Insert into table_name select * from table_name2;

Example:

mysql> desc students;
+-------+-------------+------+-----+---------+-------+
| Field     | Type  | Null  | Key    | Default | Extra |
+-------+-------------+------+-----+---------+-------+ 
|sid        |int(11)    |YES        |   |NULL   |   |
|sname  |varchar(20)    |YES    |   |NULL   |   |
+-------+-------------+------+-----+---------+-------+

Insert into students values(1,’aaa’);
Insert into students set sid=2,sname=‘bbb’;
Insert into students select * from students_bak;

mysql> select * from students;
+------+-------+
|sid |sname|
+------+-------+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
+------+-------+

The above is the detailed content of How to write sql insert statement. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The Purpose of SQL: Interacting with MySQL Databases The Purpose of SQL: Interacting with MySQL Databases Apr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

How to use AWS Glue crawler with Amazon Athena How to use AWS Glue crawler with Amazon Athena Apr 09, 2025 pm 03:09 PM

As a data professional, you need to process large amounts of data from various sources. This can pose challenges to data management and analysis. Fortunately, two AWS services can help: AWS Glue and Amazon Athena.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

SQL: The Language, MySQL: The Database Management System SQL: The Language, MySQL: The Database Management System Apr 21, 2025 am 12:05 AM

The relationship between SQL and MySQL is: SQL is a language used to manage and operate databases, while MySQL is a database management system that supports SQL. 1.SQL allows CRUD operations and advanced queries of data. 2.MySQL provides indexing, transactions and locking mechanisms to improve performance and security. 3. Optimizing MySQL performance requires attention to query optimization, database design and monitoring and maintenance.

MySQL: A Practical Application of SQL MySQL: A Practical Application of SQL May 08, 2025 am 12:12 AM

MySQL is popular because of its excellent performance and ease of use and maintenance. 1. Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2. Insert and query data: operate data through INSERTINTO and SELECT statements. 3. Optimize query: Use indexes and EXPLAIN statements to improve performance.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

SQL and MySQL: Understanding the Relationship SQL and MySQL: Understanding the Relationship Apr 16, 2025 am 12:14 AM

The relationship between SQL and MySQL is the relationship between standard languages ??and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

SQL and phpMyAdmin: A Beginner's Guide SQL and phpMyAdmin: A Beginner's Guide Apr 16, 2025 am 12:02 AM

Beginners can learn SQL and phpMyAdmin from scratch. 1) Create database and tables: Create a new database in phpMyAdmin and create tables using SQL commands. 2) Execute basic query: Use SELECT statement to query data from the table. 3) Optimization and best practices: Create indexes, avoid SELECT*, use transactions, and regularly back up databases.

See all articles