guoyu/log/查询数据库表结构.sql

36 lines
1.0 KiB
MySQL
Raw Normal View History

2025-12-11 23:28:07 +08:00
-- ========================================
-- 查询数据库中所有的学生相关表
-- ========================================
-- 1. 查询所有表名包含student或study的表
SELECT table_name, table_rows, table_comment
FROM information_schema.tables
WHERE table_schema = 'study'
AND (table_name LIKE '%student%'
OR table_name LIKE '%study%'
OR table_name LIKE '%class%')
ORDER BY table_name;
-- 2. 查询所有表名(完整列表)
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'study'
ORDER BY table_name;
-- 3. 查询用户表结构看看是否有user_type字段区分学生
SHOW COLUMNS FROM sys_user;
-- 4. 查询用户表中的用户类型分布
SELECT user_type, COUNT(*) AS count
FROM sys_user
GROUP BY user_type;
-- 5. 如果有study_student_class表查询其结构
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'study'
AND table_name = 'study_student_class';
-- 如果存在,查询结构
-- SHOW COLUMNS FROM study_student_class;