sp_help for 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)

);

让我们为表实现以上语法-

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)

以上是 sp_help for MySQL显示字段类型和外键约束? 的全部内容, 来源链接: utcz.com/z/331116.html

回到顶部