mysql delete multi-table connection deletion function

mysql delete multi-table connection deletion function

Deleting a single table:

DELETE FROM tableName WHERE columnName = value;
Delete all rows in a table:
That is: retain the table structure, attributes, and indexes DELETE FROM tablename;
DELETE * FROM tablename;

Delete all contents in the same table (delete data, table structure)

TRUNCATE customer;

Cannot report how many rows were deleted and can only be used for a single table

Deleting multiple table connections:

DELETE orders,itrms FROM orders,items 
  WHERE orders.userid = items.userid
  AND orders.orderid = items.orderid
  AND orders.date<"2000/03/01";

The name of the table to be deleted is listed after DELETE, and the table used in the join condition is listed after FROM.

Suppose you want to delete all wine farms in the BV region, but not the place names.

DELETE winery FROM region,winery 
  WHERE winery.regionid = region.regionid
  AND region.regionname = 'BV';

The query only affects the winery table, but also uses winery and region to find the records that need to be deleted.

Using advanced join queries

DELETE orders,items FROM orders
  INNER JOIN otems ON orders.orderid = items.orderid
  AND orders.userid = items.userid
  WHERE orders.date<"2000/03/01";

You can also use nested queries (the inner query cannot reference the deleted data), GROUP BY, and HAVING in the DELETE statement;

You can also use ORDER BY in a single-table query, but it doesn't make much sense unless you use it with LIMIT to delete some data rows.

Add the quick modifier to quickly delete index items, speeding up large or frequent deletion operations.

DELETE QUICK FROM customer WHERE userid<10;

Only available for MyISAM tables.

Cleaning up MyISAM tables

OPTIMIZE TABLE customer;

The above is the mysql delete multi-table connection deletion function introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • A brief discussion on the execution details of Mysql multi-table join query
  • MySQL multi-table join introductory tutorial
  • MySQL multi-table join query example explanation
  • Basic multi-table join query tutorial in MySQL
  • Detailed explanation of MySQL multi-table join query

<<:  How to use Nginx to realize the coexistence of multiple containers in the server

>>:  Steps to package and deploy the Vue project to the Apache server

Recommend

Detailed explanation of MySQL three-value logic and NULL

Table of contents What is NULL Two kinds of NULL ...

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

How to call the browser sharing function in Vue

Preface Vue (pronounced /vjuː/, similar to view) ...

Detailed description of mysql replace into usage

The replace statement is generally similar to ins...

Deploy Nginx+Flask+Mongo application using Docker

Nginx is used as the server, Mongo is used as the...

js version to realize calculator function

This article example shares the specific code of ...

Detailed explanation of the lock structure in MySQL

Mysql supports 3 types of lock structures Table-l...

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

Linux common text processing commands and vim text editor

Today, let's introduce several common text pr...

Detailed examples of how to use the box-shadow property in CSS3

There are many attributes in CSS. Some attributes...

Windows platform configuration 5.7 version + MySQL database service

Includes the process of initializing the root use...

Box-shadow and drop-shadow to achieve irregular projection example code

When we want to add a shadow to a rectangle or ot...

Detailed explanation of MySQL trigger trigger example

Table of contents What is a trigger Create a trig...