如何基于 MySQL 中现有的表生成"create table"命令?
mysqlmysqli database更新于 2025/1/14 23:08:17
您可以借助 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 - > ); Query OK, 0 rows affected (0.54 sec)
现在使用上述语法来生成创建表的命令。
查询如下
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)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

