分享作为DBA日常工作中,关于mysql主键的3个常用查询语句,分别如下:
创新互联服务项目包括曲阜网站建设、曲阜网站制作、曲阜网页制作以及曲阜网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,曲阜网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到曲阜省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
select tab.table_schema as database_schema,
sta.index_name as pk_name,
sta.seq_in_index as column_id,
sta.column_name,
tab.table_name
from information_schema.tables as tab
inner join information_schema.statistics as sta
on sta.table_schema = tab.table_schema
and sta.table_name = tab.table_name
and sta.index_name = 'primary'
where tab.table_schema = 'your database name'
and tab.table_type = 'BASE TABLE'
order by tab.table_name,
column_id;
select tab.table_schema as database_name,
tab.table_name
from information_schema.tables tab
left join information_schema.table_constraints tco
on tab.table_schema = tco.table_schema
and tab.table_name = tco.table_name
and tco.constraint_type = 'PRIMARY KEY'
where tco.constraint_type is null
and tab.table_schema not in('mysql', 'information_schema',
'performance_schema', 'sys')
and tab.table_type = 'BASE TABLE'
-- and tab.table_schema = 'sakila' -- put schema name here
order by tab.table_schema,
tab.table_name;
注意:如果您需要特定数据库(模式)的信息,请取消注释 table_schema 行并提供您的数据库名称。
select count(*) as all_tables,
count(*) - count(tco.constraint_type) as no_pk_tables,
cast( 100.0*(count(*) - count(tco.constraint_type)) / count(*)
as decimal(5,2)) as no_pk_percent
from information_schema.tables tab
left join information_schema.table_constraints tco
on tab.table_schema = tco.table_schema
and tab.table_name = tco.table_name
and tco.constraint_type = 'PRIMARY KEY'
where tab.table_type = 'BASE TABLE'
-- and tab.table_schema = 'database_name' -- put your database name here
and tab.table_schema not in('mysql', 'information_schema',
'sys', 'performance_schema');
分享文章:DBA技术分享--MySQL三个关于主键PrimaryKeys的查询
浏览路径:http://www.mswzjz.cn/qtweb/news29/254879.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能