
- 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 create a table?
Following is the query to create a stored procedure that creates a table. Here, we are creating a table with three columns, one of them is Id −
mysql> DELIMITER // mysql> CREATE PROCEDURE Stored_Procedure_CreatingTable() BEGIN create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserFirstName varchar(20), UserLastName varchar(20) ); END; // Query OK, 0 rows affected (0.16 sec) mysql> DELIMITER ;
Now you can call stored procedure with the help of CALL command −
mysql> call Stored_Procedure_CreatingTable(); Query OK, 0 rows affected (0.18 sec)
Let us check the description of table using DESC command −
mysql> desc DemoTable;
This will produce the following output −
+---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserFirstName | varchar(20) | YES | | NULL | | | UserLastName | varchar(20) | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.04 sec)
- Related Articles
- MySQL stored procedure to execute SHOW CREATE TABLE?
- Create a stored procedure to get the detail of a particular MySQL table stored in a database?
- Create a table inside a MySQL stored procedure and insert a record on calling the procedure
- 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 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 a MySQL stored procedure which fetches the rows from a table by using a cursor?
- Create a temporary table in a MySQL procedure?
- Create a MySQL stored procedure that generates five random numbers?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- How to create MongoDB stored procedure?

Advertisements