'How to generate the table schema from INFORMATION_SCHEMA in MySQL?
I trying to generate table structure using INFORMATION_SCHEMA in MySQL. I need the same output as
SHOW CREATE TABLE Mytablename;
My intention is to generation create table script for list of tables in mysql. please help. I need to take table scripts for 100 tables. like below
CREATE TABLE `customer_list` (
`ID` smallint(5) unsigned NOT NULL DEFAULT '0',
`name` varchar(91) DEFAULT NULL,
`address` varchar(50) NOT NULL,
`zip_code` varchar(10) DEFAULT NULL,
`phone` varchar(20) NOT NULL,
`city` varchar(50) NOT NULL,
`country` varchar(50) NOT NULL,
`notes` varchar(6) NOT NULL DEFAULT '',
`SID` tinyint(3) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Solution 1:[1]
SHOW CREATE TABLE your_table_name;
Solution 2:[2]
The SQL query to get the table structure from the INFORMATION SCHEMA is as follows, where the database name is "dbname" and the table name is "Mytablename":
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'Mytablename';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Wei Zhen |
Solution 2 | Prabhjot Singh Kainth |