-- 查看表结构
DESC 表名;
-- 查看 表 - 字段 - 结构信息
SELECT
table_name,
column_name,
column_comment
FROM
information_schema.COLUMNS
WHERE
table_schema = '表所在的库'
AND table_name = '要查的表';
SELECT
ORDINAL_POSITION 序号,
COLUMN_NAME 属性,
COLUMN_TYPE 数据类型,
IF (COLUMN_KEY = 'PRI', '√', '') AS '主键',
IF (
EXTRA = 'auto_increment',
'√',
''
) AS '自增标识',
IF (IS_NULLABLE = 'NO', '√', '') AS '非空',
COLUMN_COMMENT 注释
FROM
INFORMATION_SCHEMA. COLUMNS
WHERE
table_schema = 'baggagetrack'
AND table_name = 'resource'
ORDER BY
ORDINAL_POSITION ASC;
-- 查看 库 - 表 - 结构信息
SELECT
table_name,
table_comment
FROM
information_schema.TABLES
WHERE
table_schema = '表所在的库'
AND table_name = '要查的表';
-- 查看表的DDL语句
SHOW CREATE TABLE 表名;