当前位置:网站首页>MySQL script batch queries all tables containing specified field types in the database

MySQL script batch queries all tables containing specified field types in the database

2022-07-07 01:15:00 Chen Li Li

Due to changes in project requirements , You need to regenerate the code with the table ,text The entity code generated by type reverse engineering will be separated from other types of entities , In order to find out all the contents text Table of fields . Checked and wrote the information , Sort out the query script , Note the . It will inevitably be used again in the future .

Query field name and field type

Query all field names and field types in the specified database

SELECT COLUMN_NAME,DATA_TYPE FROM information_schema.COLUMNS WHERE table_schema =' Library name '

 Insert picture description here

Query the table containing the specified field type

mysql The script queries all tables in the database that contain the specified field type

With text Type as an example

Query all the contents in the Library text Type field

SELECT COLUMN_NAME,DATA_TYPE FROM information_schema.COLUMNS WHERE table_schema =' Library name ' AND DATA_TYPE = ' Field type '

Query results :

ver_detail	text
ver_url	text
menu_desc	text
menu_pic	text
menu_url	text
role_desc	text
rule_desc	text
rule_txt	text
express_name	text
mail_body_template	text
remark	text
send_bean	text
msg_site_template	text
remark	text
remark	text
sms_template	text
param_desc	text
sp_desc	text
sql_load	text
sp_desc	text
oth_params	text
url	text
para_desc	text
para_value	text
link_name	text

 Insert picture description here

Query all tables with a certain field under the Library

Query all tables with a certain field under the Library

SELECT TABLE_NAME,column_name,data_type,column_type,column_comment FROM information_schema.columns WHERE column_name=' Field ' AND TABLE_SCHEMA=' Library name '

Query results :

t_app_version	ver_detail	text	text	

 Insert picture description here

Organize batch scripts

Batch query all tables containing specified field types in the database

SELECT DISTINCT
	TABLE_NAME,
	column_name,
	data_type,
	column_type,
	column_comment 
FROM
	information_schema.COLUMNS 
WHERE
	column_name IN ( SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_schema = ' Library name ' AND DATA_TYPE = ' Field type ' ) 
	AND TABLE_SCHEMA = ' Library name ' 
	AND DATA_TYPE = ' Field type '

Return results :

t_auth_menu	menu_desc	text	text	????
t_auth_menu	menu_pic	text	text	??????????????URL?
t_auth_role	role_desc	text	text	????
t_auth_rule	rule_desc	text	text	????
t_auth_rule	rule_txt	text	text	????
t_base_express	express_name	text	text	??????????
t_base_msg_mail	mail_body_template	text	text	??????
t_base_msg_mail	remark	text	text	??
t_base_msg_send_type	send_bean	text	text	???????Bean
t_base_msg_site	msg_site_template	text	text	?????
t_base_msg_site	remark	text	text	??
t_base_msg_sms	sms_template	text	text	????
t_base_msg_sms	remark	text	text	??

 Insert picture description here

原网站

版权声明
本文为[Chen Li Li]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130930330788.html