
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL stored procedure to execute SHOW CREATE TABLE?
To execute SHOW CREATE TABLE in a stored procedure, use SHOW CREATE TABLE. Let us first create a table −
mysql> create table DemoTable2011 -> ( -> StudentId int NOT NULL AUTO_INCREMENT, -> StudentName varchar(20), -> StudentAge int, -> StudentCountryName varchar(20), -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (0.80 sec)
Following is the stored procedure executing SHOW CREATE TABLE −
mysql> delimiter // mysql> create procedure test_show_create_demo(table_name varchar(100)) -> begin -> set @query=concat("SHOW CREATE TABLE ",table_name); -> prepare st from @query; -> execute st; -> end -> // Query OK, 0 rows affected (0.22 sec) mysql> delimiter ;
Call the stored procedure using CALL command −
mysql> call test_show_create_demo('DemoTable2011');
This will produce the following output −
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DemoTable2011 | CREATE TABLE `demotable2011` ( `StudentId` int(11) NOT NULL AUTO_INCREMENT, `StudentName` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `StudentAge` int(11) DEFAULT NULL, `StudentCountryName` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`StudentId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci | +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.01 sec) Query OK, 0 rows affected, 1 warning (0.06 sec)
- Related Articles
- MySQL Stored Procedure to create a table?
- Create a stored procedure to get the detail of a particular MySQL table stored in a database?
- How can I create a stored procedure to insert values in a MySQL table?
- How can I create a stored procedure to delete values from a MySQL table?
- How can I create a stored procedure to update values in a MySQL table?
- Create a table inside a MySQL stored procedure and insert a record on calling the procedure
- Create a stored procedure with delimiter in MySQL
- How can I create a MySQL stored procedure that returns multiple values from a MySQL table?
- Insert data in a table in MySQL stored procedure?
- Display table records from a stored procedure in MySQL
- Create variables in MySQL stored procedure with DECLARE keyword
- What is stored procedure and how can we create MySQL stored procedures?
- How to create MongoDB stored procedure?
- How can we create MySQL stored procedure to calculate the factorial?
- MySQL Stored procedure won't fetch the whole table?

Advertisements