当前位置:网站首页>Mysql常用sql语句之修改表名、删除表、获取表信息、删除指定日期的表记录
Mysql常用sql语句之修改表名、删除表、获取表信息、删除指定日期的表记录
2022-06-26 01:56:00 【怎么又有bug单】
前言
为什么操作表要用命令,而不直接使用简便的可视化工具直接操作呢?
在数据量小的时候,使用可视化工具显然更用户友好,简单的鼠标点击操作,无需学习直接入门。
但是当数据量越来越大时,使用可视化工具操作就不现实了,比如:一张有三千万行的大表,怎么可能用手点的方式去治理呢?
使用命令行的方式,显然更便捷更不容易出错。
如何修改表名
举例:
ALTER table A RENAME TO B;
把表A改名为表B
如何删除表
此处使用drop删除,关于drop,delete,truncate的区别见:
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为表名
如何获取表的基本信息
select * from information_schema.tables where table_name=‘A’;
A为表名
这里列举比较重要的参数
TABLE_ROWS(表的行数):39137335
AVG_ROW_LENGTH(每行的平均长度):126
DATA_LENGTH(数据长度):4951375872
如何删除指定日期的表记录
获取三个月以前的数据sql:
SELECT *
FROM tp_order_cancel_log
WHERE add_time < curdate() - INTERVAL 3 MONTH
ORDER BY add_time DESC;
add_time是我这张表里面定义的记录创建时间的字段(更常用的一般是create_time)
删除三个月以前的数据sql:
DELETE *
FROM tp_order_cancel_log
WHERE add_time < curdate() - INTERVAL 3 MONTH;
边栏推荐
- 请指教同花顺软件究竟是什么?在线开户安全么?
- The difference between like,%, - in database query SQL
- 2022-06-25: given a positive number n, it means that there are tasks 0~n-1. Given an array of length N, time[i] means the time when task I is completed. Given a two-dimensional array matrix, matrix[j]
- Explain the JVM clearly at one time and don't be asked by the interviewer again
- Possible values for @supply in kotlin
- Little p weekly Vol.10
- Redis Lua sandbox bypass command execution (cve-2022-0543)
- High performance and high availability computing architecture based on microblog comments
- How to default that an app is not restricted by traffic
- Eureka registration information configuration memo
猜你喜欢

df报错Stale file handle

High availability in Internet three highs (high concurrency, high performance and high availability)

Bloc入门之Cubit详解

【flask入门系列】flask处理请求和处理响应

Blazor University (33) form - editcontext, fieldidentifiers

UTONMOS:以数字藏品助力华夏文化传承和数字科技发展

组件与路由

Dual batteries in series, hardware design

【机器学习】基于多元时间序列对高考预测分析案例
![2022-06-25:给定一个正数n, 表示有0~n-1号任务, 给定一个长度为n的数组time,time[i]表示i号任务做完的时间, 给定一个二维数组matrix, matrix[j] = {a,](/img/93/d95255bae20b138851bdc8a50f8647.png)
2022-06-25:给定一个正数n, 表示有0~n-1号任务, 给定一个长度为n的数组time,time[i]表示i号任务做完的时间, 给定一个二维数组matrix, matrix[j] = {a,
随机推荐
Termux install openssh
用指南针交易股票安全吗?指南针是如何交易股票的,需要开户吗
第一章:渗透测试的本质信息收集
Cvpr2022 𞓜 future transformer with long-term action expectation
Is it safe to trade stocks with a compass? How does the compass trade stocks? Do you need to open an account
Audio video and CPU architecture
A high-frequency interview question from a large factory: tell me about the solution of high and low interface idempotence? Solutions are attached.
Technology is to be studied
Is it safe to open a securities account at the school of Finance and business in 2022?
7 tips to change your life
2021-08-04
Redis configuration and optimization of NoSQL
业务流程图设计
程序员的八年工资变动,令网友羡慕不已:你一个月顶我一年工资
如何在 ggplot2 中删除网格线(附示例)
A few simple ways for programmers to exercise their waist
【系统架构】-如何评估软件架构
Share some remote office experience in Intranet operation | community essay solicitation
Limit the input character length to 1 character in English and 2 characters in Chinese
OpenAPI 3.0 规范-食用指南