- 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)
- Related Articles
- Get a list of Foreign Key constraints in MySQL
- How to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle?
- How can we add FOREIGN KEY constraints to more than one fields of a MySQL table?
- MySQL Syntax to create Foreign Key?
- How to identify foreign key in MySQL DB?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- Display information about field names in MySQL including TYPE, KEY, etc.
- How to display all constraints on a table in MySQL?
- Verify that MySQL SET FOREIGN KEY CHECKS is set to = 1?
- How to refer primary key as Foreign to various table in MySQL?
- Difference between Primary key and Foreign key in Database
- Difference Between Primary key and Foreign key in DBMS
- Foreign Key in RDBMS
- Difference between Primary key and Foreign key in SQL Database
- How to disable MySQL foreign key checks and what are the benefits of\ndisabling it?

Advertisements