tags:

views:

33

answers:

1

I want to write a Stored procedure...which will create a table with xyz name ...but when i call the SP for very second time it will give the error bcoz table already exist...I want to take table name as input..and want table to be created with that name... How to archive this..... Asp.net ---My sql

+2  A: 
delimiter //
CREATE PROCEDURE CreateTable (IN name VARCHAR(100))
BEGIN
  SET @q = CONCAT('CREATE TABLE ', name ,' (...)');
  PREPARE s FROM @q;
  EXECUTE s;
  DEALLOCATE PREPARE s;
END//
Lukáš Lalinský
I am new to dynamic table creation....it is throwing syntax error near '..)' when i am calling this procedure
hrishi
Of course, you are supposed to replace *...* with your table definition. :)
Lukáš Lalinský
off course its working fine ..but not for varchar typa like 'mh-30-o-126'
hrishi