MySQL डेटाबेस से सभी कंस्ट्रेंट की सूची प्राप्त करने के लिए information_schema.table_constraints टेबल को क्वेरी करें।
सिंटैक्स
select *from information_schema.table_constraints where constraint_schema = 'yourDatabaseName';
उदाहरण: 'business' डेटाबेस के कंस्ट्रेंट देखना
mysql> select * -> from information_schema.table_constraints -> where constraint_schema = 'business';
मुख्य कॉलम
| कॉलम | विवरण |
|---|---|
| CONSTRAINT_CATALOG | कैटलॉग नाम |
| CONSTRAINT_SCHEMA | डेटाबेस नाम |
| CONSTRAINT_NAME | कंस्ट्रेंट नाम |
| TABLE_SCHEMA | टेबल का डेटाबेस |
| TABLE_NAME | टेबल नाम |
| CONSTRAINT_TYPE | कंस्ट्रेंट प्रकार (PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK) |
नमूना आउटपुट (संक्षिप्त)
+--------------------+-------------------+--------------------------+--------------+------------------------------+-----------------+ | 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 | UserId | business | usernameandpassworddemo | UNIQUE | | def | business | name | business | uniquedemo | UNIQUE | | def | business | ConstFK | business | tabledemo2 | UNIQUE | | def | business | constFKPK | business | foreigntable | FOREIGN KEY | | def | business | FKConst | business | foreigntabledemo | FOREIGN KEY | | def | business | ConstFK | business | tblf | FOREIGN KEY | +--------------------+-------------------+--------------------------+--------------+------------------------------+-----------------+
उपयोगी फिल्टर
केवल विशिष्ट प्रकार के कंस्ट्रेंट देखने के लिए:
-- केवल PRIMARY KEY select * from information_schema.table_constraints where constraint_schema = 'business' and CONSTRAINT_TYPE = 'PRIMARY KEY'; -- केवल FOREIGN KEY select * from information_schema.table_constraints where constraint_schema = 'business' and CONSTRAINT_TYPE = 'FOREIGN KEY'; -- केवल UNIQUE select * from information_schema.table_constraints where constraint_schema = 'business' and CONSTRAINT_TYPE = 'UNIQUE';