- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
sp_help for MySQL to display field types and foreign key constraints?
In MySQL, you can achieve sp_help with the help of SHOW CREATE command.
CASE 1 −
For table, the syntax is as follows −
SHOW CREATE TABLE yourTableName;
CASE 2 −
For stored procedure, the syntax is as follows −
SHOW CREATE PROCEDURE yourProcedureName;
Let us first create a table −
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)
Let us implement the above syntax for our table −
mysql> SHOW CREATE TABLE DemoTable;
This will produce the following output displaying the field names and constraints −
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 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)
Advertisements