sp_help 如何在 MySQL 中显示字段类型和外键约束?


在 MySQL 中,可借助 SHOW CREATE 命令实现 sp_help。

情况 1

对于表,语法如下 −

SHOW CREATE TABLE yourTableName;

情况 2

对于存储过程,语法如下 −

SHOW CREATE PROCEDURE yourProcedureName;

首先创建一个表 −

mysql> create table DemoTable
(
   EmployeeId int NOT NULL AUTO_INCREMENT,
   EmployeeFirstName varchar(40) NOT NULL,
   EmployeeLastName varchar(40) NOT NULL,
   EmployeeAge int,
   EmployeeCountryName varchar(40),
   EmployeeCityName varchar(40),
   PRIMARY KEY(EmployeeId),
   UNIQUE KEY(EmployeeFirstName,EmployeeCityName)
);
Query OK, 0 rows affected (0.97 sec)

为该表执行上面的语法 −

mysql> SHOW CREATE TABLE DemoTable;

这将生成如下输出,其中显示了字段名称和约束 −

+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table         | Create Table 
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| DemoTable     | CREATE TABLE `demotable` (`EmployeeId` int(11) NOT NULL AUTO_INCREMENT, `EmployeeFirstName` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `EmployeeLastName` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `EmployeeAge` int(11) DEFAULT NULL, `EmployeeCountryName` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `EmployeeCityName` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`EmployeeId`), UNIQUE KEY `EmployeeFirstName` (`EmployeeFirstName`,`EmployeeCityName`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.03 sec)

更新日期: 2019 年 10 月 10 日

浏览 832 次

助力您的 职业

完成课程,获得认证

开始
广告