您可以借助SHOW CREATE命令基于MySQL中的现有表生成create table命令。
语法如下
SHOW CREATE TABLE yourTableName;
为了理解上述语法,让我们创建一个表。创建表的查询如下
mysql> create table StudentInformation - > ( - > StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > StudentName varchar(20), - > StudentAge int DEFAULT 18, - > StudentRollNo int, - > StudentAddress varchar(200), - > StudentMarks int, - > StudentDOB datetime, - > StudentAdmissionDate datetime - > );
现在,使用以上语法生成一个create table命令。
查询如下
mysql> SHOW CREATE TABLE StudentInformation;
以下是输出
+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +--------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | StudentInformation | CREATE TABLE `studentinformation` ( `StudentId` int(11) NOT NULL AUTO_INCREMENT, `StudentName` varchar(20) DEFAULT NULL, `StudentAge` int(11) DEFAULT '18', `StudentRollNo` int(11) DEFAULT NULL, `StudentAddress` varchar(200) DEFAULT NULL, `StudentMarks` int(11) DEFAULT NULL, `StudentDOB` datetime DEFAULT NULL, `StudentAdmissionDate` datetime DEFAULT NULL, PRIMARY KEY (`StudentId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | +--------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.04 sec)