Posts

Showing posts from July, 2013

How To Create Dynamic Table Using Mysql Stored Procedure..

Hi Guys,               Here I am writing the snippet code of mysql stored procedure which shows you how to create dynamic table using mysql stored procedure & dynamic SQL prepared statement and cursor. Many of the database developer needs this types of technique in there database developments , so I am writing the snippet for those  database developer who are facing the problems for developing the same. Go through the snippet code. DROP PROCEDURE IF EXISTS dynamictable; DELIMITER // CREATE PROCEDURE dynamictable() BEGIN DECLARE done INT DEFAULT 0; DECLARE tnm varchar(20); # Selecting the table Name from table in which you have stored one by one using Cursor. DECLARE curname cursor FOR SELECT distinct(tname)  FROM table_name; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; open curname ; FETCH curname INTO tnm; REPEAT # Dropping table dynamically if exist with same name which you are creating. SET @stm = CONCAT('DROP TABLE IF EXISTS ', tnm)