Hongmu Notes
Home Language Notes SQL statement to truncate the database
Language Notes mySql

SQL statement to truncate the database

SQL statement to truncate the database

Can be used TRUNCATE Use the `TRUNCATE` command to clear a table; if you need to clear the entire database, you must truncate each table individually.

Here is an example SQL statement for clearing the entire database:

SET foreign_key_checks = 0;

SELECT CONCAT('TRUNCATE TABLE `', table_name, '`;') 
FROM information_schema.tables 
WHERE table_schema = 'database_name';

SET foreign_key_checks = 1;

among database_name This is the name of the database that needs to be cleared; you can replace it with the actual database name. This statement will generate a series of operations. TRUNCATE TABLE This statement is used to truncate each table. Note that you should disable foreign key constraints before truncating the tables to prevent errors from occurring during the truncation process. After truncation is complete, re-enable the foreign key constraints.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

sqlite uses PDO to execute SQL statements exec(), query()

sqlite uses PDO to execute SQL statements exec(), query() Language Notes mySql

In PHP scripts, executing SQL queries using PDO to interact with a database can be done through three different approaches; the choice of which method to use depends on the specific operation you intend to perform. 1. Using the PDO::exec() method: When executing queries such as INSERT, UPDATE, or DELETE that do not return a result set, use the exec() method on a PDO object to execute the query. Upon successful execution, this method returns the number of affected rows...
👁 323
Mysql efficiency improvement: limit this piece of shit

Mysql efficiency improvement: limit this piece of shit Language Notes mySql

In mysql, the efficiency of limit is not high, especially my millions of data, limit 100000, 50, so writing, the query is even slower, at first it was quite fast, and the server cup behind it was directly filled for me! I thought the server was hacked, so I looked for the problem. I looked for it for a few days, but it turned out to be this dog, which made me angry! So I inquired about the principle of limit, emmm, change! Must be changed ...
👁 155
Query error: #1075-Incorrect table definition; there can be only one auto column, and it must be defined as a key.

Query error: #1075-Incorrect table definition; there can be only one auto column, and it must be defined as a key. Language Notes mySql

This error message indicates that you have defined multiple auto-increment columns when creating a table, or that you have not defined an auto-increment column as a primary key or a unique key; as a result, MySQL is unable to create the table. In MySQL, there can be only one auto-increment column, and it must be defined as a primary key or a unique key. Here are some possible ways to resolve this issue: Ensure that there is only one auto-increment column: You should check your table definition to confirm that only one column is defined as an auto-increment column. If you need...
👁 409

Recommended reading

Responsive Dental Cosmetic Surgery Website Template 1039

Responsive Dental Cosmetic Surgery Website Template 1039 Practical Collection Yiyou template

An eyouCMS responsive website template designed for the medical and dental aesthetics industries. Its professional and clean design effectively showcases dental aesthetics treatments, the medical team, the clinical environment, and success stories. This template helps dental aesthetics clinics attract patients online and enhance their brand professionalism. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for YououCMS...
👁 42
Industrial electronic components service provider website template 0004

Industrial electronic components service provider website template 0004 Practical Collection Yiyou template

This set of eyoucms templates is suitable for industrial electronic component service providers. The design style has a strong sense of technology and the information level is clear. It is suitable for displaying electronic component products, technical support and solutions, and helps electronic component distributors or manufacturers to establish their brand image online and expand industrial customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Yiyou CMS installation common...
👁 66
(Adaptive Mobile Version) HTML5 Responsive pbootCMS Human Resources Website Template – Download Source Code for Management Consulting Firm Websites – 0185

(Adaptive Mobile Version) HTML5 Responsive pbootCMS Human Resources Website Template – Download Source Code for Management Consulting Firm Websites – 0185 Practical Collection pbootcms Template

This is an adaptive, HTML5 responsive PbootCMS website template designed for HR and consulting services, optimized for mobile devices. Its professional and sophisticated design effectively showcases HR services, management consulting offerings, and success stories, helping headhunting firms or management consulting agencies build a strong professional online brand image. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 60
Empire CMS – Q&A, Information & News Category – Dual-Platform (WAP + PC) Adaptive Template 026

Empire CMS – Q&A, Information & News Category – Dual-Platform (WAP + PC) Adaptive Template 026 Practical Collection empire template

Although this is a template obtained from an external source, after prolonged use, numerous issues have been resolved: the system has been tested for two hours, all functions are fully operational, all erroneous pages have been removed, and all article thumbnails have been replaced! The Changyan comment section that previously caused page errors is now functional, and page loading speeds have been significantly improved! Preview image decompression password 🔒 – Hidden content: View after commenting. If no password prompt appears when downloading the page, the default password is: www.4s5.cn
👁 213
Dental Cosmetic Surgery Company Website Template 1040

Dental Cosmetic Surgery Company Website Template 1040 Practical Collection Yiyou template

This EyouCMS template is ideal for dental aesthetics and healthcare businesses. Its professional and clean design effectively showcases dental aesthetic treatments, medical teams, diagnostic and treatment equipment, as well as successful case studies. It helps dental clinics attract patients online and enhance their brand professionalism. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 39
Grains and agricultural products adaptive website template 0005

Grains and agricultural products adaptive website template 0005 Practical Collection Yiyou template

An eyoucms adaptive website template designed for grain and agricultural products enterprises. The design style is natural and fresh, which can well display cereal products, planting bases and brand stories. It helps agricultural enterprises establish their brand image online and expand sales channels for agricultural products. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation...
👁 46