当前位置: 首页 > 科技观察

MySQL关于查找模式对象的声明

时间:2023-03-19 20:32:31 科技观察

在日常工作中,搜索特定的数据库对象是最常见的工作。下面是关于mysql模式搜索的几个说法。1、查找MySQL数据库中名称中包含数字的表selecttable_schemaasdatabase_name,table_namefrominformation_schema.tableswheretable_type='BASETABLE'andtable_namerlike('[0-9]')orderbytable_schema,table_name;description:database_name-找到表的数据库(schema)的名称table_name-找到的表的名称2.在MySQL数据库中查找关于特定列名的表selecttab.table_schemaasdatabase_name,tab.table_namefrominformation_schema.tables作为tabinner加入information_schema.columns作为coloncol.table_schema=tab.table_schema和col.table_name=tab.table_namewheretab.table_type='BASETABLE'andcolumn_name='idcity'orderbytab.table_schema,tab.表名;说明:database_name-找到表的数据库(schema)的名称table_name-找到的表的名称3.在MySQL数据库中查找没有具有特定名称的列的表selecttab.table_schemaasdatabase_name,tab.table_namefrominformation_schema.tablestableftjoininformation_schema.columnscolontab.table_schema=col.表模式dtab.table_name=col.table_nameandcol.column_name='id'--将列名放在这里wheretab.table_schemanotin('information_schema','mysql','performance_schema','sys')andtab.table_type='BASETABLE'和col.column_name是nullorderbytab.table_schema,tab.table_name;说明:database_name-找到的表的数据库(模式)名称table_name-找到的表的名称