如何识别任何Mysql数据库表中的复合主键?
如何识别任何Mysql数据库表中的复合主键? 或者
编辑2 应该使用什么sql查询 显示任何表的索引 包含复合主键?
我在 mysql 数据库中有许多表,它们具有 2 或 3 个主键的复合键,我正在使用 phpmyadmin,我必须编写一个 php 脚本来识别哪个表具有复合键,现在我可以识别通过使用查询来查找表
SHOW INDEXES FROM `".$row3['TABLE_NAME']."` WHERE Key_name = 'PRIMARY'
,该查询给了我想要的东西,但是现在我如何找到具有复合键的索引?
编辑1
在丹尼尔图像评论的背景下 查找复合主键 phpmyadmin
How to identify composite primary key in any Mysql Database table?
or
EDIT 2
what sql query should be used to
display the indees of any table who
contains the composite primary keys?
I have many tables in mysql database which are having composite keys of 2 or 3 primary keys, I am using phpmyadmin, and I have to code a php script to identify which table has the composite keys, right now i can identify the primary key of the tables by using a query
SHOW INDEXES FROM `".$row3['TABLE_NAME']."` WHERE Key_name = 'PRIMARY'
which is giving me what i want, but now how can i find out the indexes where i have composite keys?
EDIT 1
In the context of Daniel Image comment
for look of composite primary keys in
phpmyadmin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:
对于更新的问题,您可能需要在 PHP 脚本中使用以下内容:
此查询将返回
num_keys
> 1 如果表 tb 具有复合主键。我不确定我是否理解您想要实现的目标,但您可能需要考虑使用
SHOW INDEX
,如下所示:如果它不是复合键,则您只会在
SHOW INDEX
查询:UPDATE:
Further to the updated question, you may want to use the following in your PHP script:
This query will return
num_keys
> 1 if tabletb
has a composite primary key.I'm not sure if I understood what you are trying to achieve, but you may want to consider using
SHOW INDEX
as follows:If it were not a composite key, you would only get one row in the
SHOW INDEX
query:谢谢丹尼尔和普拉纳夫:)
Thanks Daniel and Pranav :)