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

WBOY
发布: 2023-08-30 16:09:03
转载
569 人浏览过

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

要从 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)
登录后复制

以上是从 MySQL 数据库获取约束列表?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!