获取指定表字段
获取指定前缀的表名(只能查看,无法拼接字段):
SHOW TABLES LIKE 'ck_cus%';
获取指定前缀的表名,并以逗号分隔拼接:
SELECT group_concat(TABLE_NAME)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'ck_%';
获取指定前缀的表名,拼接生成特定SQL语句:
SELECT concat('alter table ',TABLE_NAME,' add tenant_id varchar(32) null comment ''租户ID'' after is_archive;')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'ck_%';
获取某个表的所有字段
只查看:
SHOW COLUMNS FROM sys_oper_log;
以逗号拼接所有字段:
SELECT GROUP_CONCAT(column_name ORDER BY ordinal_position SEPARATOR ', ') as fields
FROM information_schema.columns
WHERE table_schema = 'byteexpress' -- 替换为你的数据库名
AND table_name = 'sys_user'; -- 替换为你的表名
标签:NAME,SQL,指定,信息,获取,拼接,表名,TABLE
From: https://www.cnblogs.com/byteexpress/p/18324280