文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

从 MySQL 数据库获取约束列表?

2023-10-22 10:24

关注

要从 MySQL 数据库获取约束列表,请使用以下语法 -

select *from information_schema.table_constraints where constraint_schema = 'yourDatabaseName';

在这里,我们将从数据库“business”中获取约束。以下是列出数据库“business”中所有表的约束的查询 -

mysql> select *
   −> from information_schema.table_constraints
   −> where constraint_schema = 'business';

以下是显示所有约束的输出 -

+--------------------+-------------------+--------------------------+--------------+------------------------------+-----------------+
| CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME          | TABLE_SCHEMA | TABLE_NAME                   | CONSTRAINT_TYPE |
+--------------------+-------------------+--------------------------+--------------+------------------------------+-----------------+
| def                | business          | PRIMARY                  | business     | primarytable                 | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | primarytable1                | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | autoincrementtable           | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | demoauto                     | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | autoincrement                | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | primarytabledemo             | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | sequencedemo                 | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | updtable                     | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | transcationdemo              | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | triggedemo                   | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | usernameandpassworddemo      | PRIMARY KEY     |
| def                | business          | UserId                   | business     | usernameandpassworddemo      | UNIQUE          |
| def                | business          | PRIMARY                  | business     | tblp                         | PRIMARY KEY     |
| def                | business          | name                     | business     | uniquedemo                   | UNIQUE          |
| def                | business          | name                     | business     | uniqueconstdemo              | UNIQUE          |
| def                | business          | PRIMARY                  | business     | keydemo                      | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | nextiddemo                   | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | tablepri                     | PRIMARY KEY     |
| def                | business          | ConstFK                  | business     | tabledemo2                   | UNIQUE          |
| def                | business          | ConstFK                  | business     | tabledemo3                   | UNIQUE          |
| def                | business          | PRIMARY                  | business     | college                      | PRIMARY KEY     |
| def                | business          | id                       | business     | uniquedemo1                  | UNIQUE          |
| def                | business          | id                       | business     | uniqueautoid                 | UNIQUE          |
| def                | business          | PRIMARY                  | business     | schemadatabasemethoddemo     | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | employeeinformation          | PRIMARY KEY     |
| def                | business          | name                     | business     | addingunique                 | UNIQUE          |
| def                | business          | PRIMARY                  | business     | parentdemo                   | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | lastinsertrecordiddemo       | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | demoindex                    | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | compositeprimarykey          | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | addingautoincrement          | PRIMARY KEY     |   
| def                | business          | Id                       | business     | uniqueconstrainttable        | UNIQUE          |
| def                | business          | PRIMARY                  | business     | mergedemo1                   | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | mergedemo2                   | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | foreigntable1                | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | twoprimarykeytabledemo       | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | showconstraintsdemo          | PRIMARY KEY     |
| def                | business          | BookAuthor               | business     | showconstraintsdemo          | UNIQUE          |
| def                | business          | PRIMARY                  | business     | autoincrementtozero          | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | altertabletoaddautoincrement | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | addingprimarykeydemo         | PRIMARY KEY     |
| def                | business          | PRIMARY                  | business     | resetprimarykey              | PRIMARY KEY     |
| def                | business          | constFKPK                | business     | foreigntable                 | FOREIGN KEY     |
| def                | business          | FKConst                  | business     | foreigntabledemo             | FOREIGN KEY     |
| def                | business          | ConstFK                  | business     | tblf                         | FOREIGN KEY     |
| def                | business          | StudCollegeConst         | business     | studentenrollment            | FOREIGN KEY     |
| def                | business          | ConstChild               | business     | childdemo                    | FOREIGN KEY     |
| def                | business          | primarytable1demo_ibfk_1 | business     | primarytable1demo            | FOREIGN KEY     |
+--------------------+-------------------+--------------------------+--------------+------------------------------+-----------------+
48 rows in set, 2 warnings (0.24 sec)
阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯