MySQL में किसी टेबल के सभी कॉलम (फील्ड) की सूची प्राप्त करने के लिए, INFORMATION_SCHEMA.COLUMNS टेबल को क्वेरी करें जहां table_schema वर्तमान डेटाबेस हो और table_name लक्ष्य टेबल हो। यह DESCRIBE या SHOW COLUMNS का प्रोग्रामेटिक विकल्प है।
क्वेरी
mysql> SELECT column_name AS ALL_FIELDS FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'DemoTable1938';
नमूना आउटपुट (वर्टिकल फॉर्मेट \\G):
*************************** 1. row *************************** ALL_FIELDS: StudentId *************************** 2. row *************************** ALL_FIELDS: StudentName *************************** 3. row *************************** ALL_FIELDS: StudentAge *************************** 4. row *************************** ALL_FIELDS: StudentCountryName *************************** 5. row *************************** ALL_FIELDS: StudentMobileNumber
पूर्ण मेटाडेटा प्राप्त करें
SELECT
column_name AS Field,
column_type AS Type,
is_nullable AS Null,
column_key AS Key,
column_default AS Default,
extra AS Extra
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 'DemoTable1938'
ORDER BY ordinal_position;
आउटपुट:
+--------------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------------+------------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(20) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentCountryName | varchar(20) | YES | | NULL | | | StudentMobileNumber| bigint(20) | YES | | NULL | | +--------------------+------------------+------+-----+---------+----------------+
वैकल्पिक कमांड
| कमांड | विवरण | आउटपुट फॉर्मेट |
|---|---|---|
| DESC table_name | सरल, त्वरित | टेबुलर |
| DESCRIBE table_name | DESC का पर्याय | टेबुलर |
| SHOW COLUMNS FROM table_name | अधिक विकल्प (FULL, WHERE) | टेबुलर |
| SHOW CREATE TABLE table_name | पूरा CREATE स्टेटमेंट | SQL |
| INFORMATION_SCHEMA.COLUMNS | पूर्ण नियंत्रण, प्रोग्रामेटिक | SELECT परिणाम |
उपयोगी फ़िल्टर