**创建索引**
```
create index indexname on tablename(column_name)
```
**添加索引**
```
ALTER table tableName ADD INDEX indexName(columnName)
SELECT table_name, column_name
FROM information_schema.columns
WHERE table_schema = 'caishuiai'
AND column_name = '444e3e7296717dae0254add52f8bdbb9';
```
**储存过程**
```
DELIMITER //
CREATE PROCEDURE delete_data_in_tables()
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE tableName VARCHAR(255);
DECLARE columnExists INT DEFAULT 0;
-- 游标用于遍历表名
DECLARE cur CURSOR FOR
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'ganfushenghuo';
-- 当游标没有遍历完所有表时,继续循环
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 打开游标
OPEN cur;
-- 循环遍历表并执行删除操作
read_loop: LOOP
FETCH cur INTO tableName;
IF done THEN
LEAVE read_loop;
END IF;
-- 检查列是否存在
SELECT COUNT(*)
INTO columnExists
FROM information_schema.columns
WHERE table_schema = 'ganfushenghuo'
AND table_name = tableName
AND column_name = 'uniacid';
IF columnExists > 0 THEN
-- 构建删除语句并执行
SET @sql = CONCAT('DELETE FROM ganfushenghuo.', tableName, ' WHERE uniacid = 601;');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END LOOP;
-- 关闭游标
CLOSE cur;
END //
DELIMITER ;
```
你可以使用以下 SQL 查询语句来列出 MySQL 数据库中的所有表,并按数据大小排序:
~~~
sql复制代码SELECT * FROM information_schema.tables ORDER BY data_length DESC;
~~~
这将返回一个结果集,其中包含所有 MySQL 数据库中的表名、类型、表大小等信息。 `data_length` 列用于获取每个表的字节大小。你可以通过将查询结果集传递给一个可视化工具,例如 Microsoft Excel,以进一步分析和排序。