MySQL learning database operation DML detailed explanation for beginners

MySQL learning database operation DML detailed explanation for beginners

1. Insert statement

1.1 Insert a row

There are two types:
1. In the form of parentheses

Note: If there is no parenthesis after the table name, all columns will be added by default.

2. In set form

insert into + table name
set A field in the table = the value to be inserted, A field in the table = the value to be inserted, A field in the table = the value to be inserted...

1.2 Insert multiple rows

insert into + table name (column name) + values ​​(value 1, value 2…), (value 1, value 2…)…

Note that multi-row insertion and join query statements are not supported here, and the primary key cannot be empty or repeated.

1.3 Insert query statement

insert into + table name (column name) + select statement

Note that the query statement is run first and then the query result set is inserted into the table, but it must correspond to the column after the table name. The primary key cannot be repeated and cannot be empty, otherwise the insertion will fail.

2. Modify the statement

2.1 Modify single table records

update table name
set + column=newvalue, column=newvalue…
where + filter condition

2.2 Modify multi-table records

1. Use sql92 syntax

update+table1(alias),table2(alias)
set + column = value, column = value...
where+join conditions and filter conditions

2. Use sql99 syntax

update+table1+(alias)
inner|left|right join Table 2 Alias
on+connection condition
set + column = value, column = value...
where+filter condition

3. Delete statement

3.1 Method 1: Use delete to delete

1. Single table deletion

delete from + table name + where + filter condition

Will delete all the corresponding data in a whole row

2. Multiple table deletion

delete table
from Table 1
inner|left|right| join Table 2
on connection condition
where + filter condition

This is sql99 syntax, and sql92 syntax is also supported. The table after delete is the table whose contents are to be deleted.

3.2 Method 2: Delete using truncate

truncate table + table name

Directly delete the data of the entire table

3.3 The difference between using truncate and delete

1. delete can add where conditions but truncat cannot
2.truncat is less efficient
3. If the deleted table has a self-increasing sequence, then delete and then add will start from the breakpoint, while truncat starts from 1
4. truncat deletes no return value, but delete does.
5. truncat can not be rolled back, delete can not be rolled back

The above is the detailed content of MySQL learning: a detailed explanation of database operation DML for beginners. For more information about MySQL database operation DML, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • MySQL database terminal - common operation command codes
  • Python MySQL database basic operations and project examples
  • MySQL database aggregate query and union query operations
  • Detailed basic operations on data tables in MySQL database
  • MySQL database operations and data types
  • MySQL learning to create and operate databases and table DDL for beginners
  • MySQL database data table operations

<<:  html opens a new window with a hyperlink and can control window properties

>>:  Discussion on the Issues of Image Button Submission and Form Repeated Submission

Recommend

Detailed explanation of monitoring NVIDIA GPU usage under Linux

When using TensorFlow for deep learning, insuffic...

Vue custom bullet box effect (confirmation box, prompt box)

This article example shares the specific code of ...

CentOS 6.5 i386 installation MySQL 5.7.18 detailed tutorial

Most people compile MySQL and put it in the syste...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...

MySQL log settings and viewing methods

MySQL has the following logs: Error log: -log-err...

JavaScript to implement checkbox selection or cancellation

This article shares the specific code of JavaScri...

Summary of some small issues about MySQL auto-increment ID

The following questions are all based on the Inno...

Implementation of element multiple form validation

In the project, form testing is often encountered...

How to pass parameters to JS via CSS

1. Background that needs to be passed through CSS...

Implementing CommonJS modularity in browsers without compilation/server

Table of contents introduction 1. What is one-cli...

Example code for implementing a hollow mask layer with CSS

Contents of this article: Page hollow mask layer,...

Basic understanding and use of HTML select option

Detailed explanation of HTML (select option) in ja...

CentOS 8 is now available

CentOS 8 is now available! CentOS 8 and RedHat En...

Introduction to using the MySQL mysqladmin client

Table of contents 1. Check the status of the serv...