1. I searched for a long time on the Internet but couldn't find whether the judgment table existed, so I deleted it vaguely. But in the end, we found a roundabout way to save the country. Requirement: Delete the table with the suffix _ to be deleted. 1. The first step is to find all such tables and assemble the SQL to delete the table Select CONCAT( 'DROP TABLE IF EXISTS ', table_name, ';' ) FROM information_schema.tables Where table_name LIKE '%_to be deleted'; Execution Results 2. Step 2: Execute the delete statements one by one. If you are capable, you can write a script to execute something. 3. SQL parsing 3-1: concat string concatenation 3-2: DROP TABLE IF EXISTS equi_accp_info__to be deleted; -- Check if this table exists, and delete it if it exists Supplementary knowledge: mysql determines whether a table field exists and then modifies it I won't say much nonsense, let's just look at the code~ -- Check if the thresholdMin field exists in the vrv_paw_rule table. If it does not exist, add it. If it does exist, modify the field type DELIMITER ?? DROP PROCEDURE IF EXISTS schema_change?? CREATE PROCEDURE schema_change() BEGIN IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'vrv_paw_rule' AND column_name = 'thresholdMin') THEN ALTER TABLE vrv_paw_rule ADD COLUMN thresholdMin BIGINT; ELSE ALTER TABLE vrv_paw_rule MODIFY COLUMN thresholdMin BIGINT; END IF; END?? DELIMITER ; CALL schema_change(); delimit command: It tells the MySQL interpreter whether the command has ended and whether MySQL can execute it, that is, change the input terminator. By default, the delimiter is a semicolon ";". In the command line client, if a line of commands ends with a semicolon, Then after pressing Enter, MySQL will execute the command. But sometimes, you don't want MySQL to do this. Because you may enter more statements and the statements may contain semicolons. By default, it is not possible to wait until the user has entered all of the statements before executing the entire statement. Because mysql will automatically execute once it encounters a semicolon. In this case, you can use delimiter and replace the delimiter with other symbols, such as // or $$. At this time, the role of delimiter is to simply encapsulate the entire small statement. This command is mostly used to define subroutines, trigger programs, and other MySQL built-in programs. The above operation of MySQL to determine whether a table exists and then delete it in batches is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript to achieve the idea of snake game
>>: Detailed explanation of the latest IDEA process of quickly deploying and running Docker images
This article uses examples to explain the concept...
<br />This article is mainly to let beginner...
1. es startup command: docker run -itd -e TAKE_FI...
HTML is the abbreviation of Hypertext Markup Langu...
Preface: In MySQL, the master-slave architecture ...
Preface By default, MySQL will initialize a large...
Many times, we ignore the setting of the web page ...
<br />I just saw the newly revamped ChinaUI....
Table of contents Preface Scope 1. What is scope?...
Application Scenario In the data table, the appli...
View the nginx configuration file path Through ng...
As one of the most popular front-end frameworks, ...
Table of contents 1. Use the withRouter component...
Table of contents 1. What is a JavaScript engine?...
Table of contents Normal loading Lazy Loading Pre...