当前位置:网站首页>Modifying table names, deleting tables, obtaining table information, and deleting table records on specified dates for common MySQL statements

Modifying table names, deleting tables, obtaining table information, and deleting table records on specified dates for common MySQL statements

2022-06-26 02:52:00 Why is there a bug list

Preface

Why does the operation table use commands , Instead of using simple visual tools to operate directly ?

When the amount of data is small , Using visualization tools is obviously more user-friendly , Simple mouse click operation , Get started without learning .
But as the amount of data increases , It is not realistic to use visualization tools , such as : A big watch with 30million lines , How can we manage it by hand ?
Using the command line , Obviously, it is more convenient and less error prone .

How to modify the table name

give an example :
ALTER table A RENAME TO B;
Keep watch A Rename table B

How to delete a table

Use here drop Delete , About drop,delete,truncate See the difference between the two :
https://blog.csdn.net/GBS20200720/article/details/125128287?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165613788116782248557404%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=165613788116782248557404&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_ecpm_v1~rank_v31_ecpm-4-125128287-null-null.nonecase&utm_term=drop&spm=1018.2226.3001.4450

drop:
DROP TABLE A;
A Is the name of the watch

How to get the basic information of a table

select * from information_schema.tables where table_name=‘A’;
A Is the name of the watch

Here are some important parameters

TABLE_ROWS( The number of rows in the table ):39137335

AVG_ROW_LENGTH( Average length per row ):126

DATA_LENGTH( Data length ):4951375872

How to delete a table record on a specified date

Get the data three months ago sql:

SELECT *
FROM tp_order_cancel_log
WHERE add_time < curdate() - INTERVAL 3 MONTH
ORDER BY add_time DESC;

add_time It is the field of record creation time defined in my table ( More commonly used is create_time)

Delete data three months ago sql:
DELETE *
FROM tp_order_cancel_log
WHERE add_time < curdate() - INTERVAL 3 MONTH;

原网站

版权声明
本文为[Why is there a bug list]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260155579509.html