
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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