Files
mayfly-go/server/internal/db/dbm/dbi/metasql/mysql_meta.sql

89 lines
2.1 KiB
MySQL
Raw Normal View History

2023-12-26 22:31:51 +08:00
--MYSQL_DBS
SELECT
SCHEMA_NAME AS dbname
FROM
information_schema.SCHEMATA
WHERE
SCHEMA_NAME NOT IN ('mysql', 'information_schema', 'performance_schema')
ORDER BY SCHEMA_NAME
2023-12-26 22:31:51 +08:00
---------------------------------------
2023-05-24 12:32:17 +08:00
--MYSQL_TABLE_INFO
SELECT
table_name tableName,
table_comment tableComment,
table_rows tableRows,
data_length dataLength,
index_length indexLength,
create_time createTime
FROM
information_schema.tables
WHERE
table_type = 'BASE TABLE'
AND table_schema = (
2023-05-24 12:32:17 +08:00
SELECT
database ()
)
ORDER BY table_name
---------------------------------------
--MYSQL_TABLE_INFO_BY_NAMES
SELECT
table_name tableName,
table_comment tableComment,
table_rows tableRows,
data_length dataLength,
index_length indexLength,
create_time createTime
FROM
information_schema.tables
WHERE
table_type = 'BASE TABLE'
AND table_name IN (%s)
AND table_schema = (
SELECT
database ()
)
ORDER BY table_name
---------------------------------------
2023-05-24 12:32:17 +08:00
--MYSQL_INDEX_INFO
SELECT
index_name indexName,
column_name columnName,
index_type indexType,
IF(non_unique, 0, 1) isUnique,
2023-05-24 12:32:17 +08:00
SEQ_IN_INDEX seqInIndex,
INDEX_COMMENT indexComment
FROM
information_schema.STATISTICS
WHERE
table_schema = (
SELECT
database ()
)
AND table_name = ?
2023-05-24 12:32:17 +08:00
ORDER BY
index_name asc,
SEQ_IN_INDEX asc
---------------------------------------
2023-05-24 12:32:17 +08:00
--MYSQL_COLUMN_MA
SELECT table_name tableName,
column_name columnName,
column_type columnType,
column_default columnDefault,
column_comment columnComment,
CASE
WHEN column_key = 'PRI' THEN
1
ELSE 0
END AS isPrimaryKey,
CASE
WHEN extra LIKE '%%auto_increment%%' THEN
1
ELSE 0
END AS isIdentity,
is_nullable nullable,
NUMERIC_SCALE numScale
FROM information_schema.COLUMNS
WHERE table_schema = (SELECT DATABASE())
AND table_name IN (%s)
ORDER BY table_name,
ordinal_position