 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements
 