Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    3

    Unanswered: Create table in stored procedure

    How can I create table in stored procedure but pass the name of table as parameter?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you would do it with DECLARE, PREPARE, and EXECUTE statements

    http://dev.mysql.com/doc/mysql/en/St...rocedures.html

    http://dev.mysql.com/doc/mysql/en/SQLPS.html

    are you sure you are in the right forum?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2004
    Posts
    3

    can I do this?

    CREATE PROCEDURE `CreateTable`(in TableName varchar(63))
    BEGIN
    DECLARE tn, s varchar(63);
    SET @tn = TableName;
    SET @S = 'CREATE TABLE ? (
    `time` datetime NOT NULL default ''0000-00-00 00:00:00'',
    `value` double NOT NULL default ''0'',
    KEY `time` (`time`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1';

    PREPARE stmt FROM @S;
    EXECUTE stmt USING @tn;
    DEALLOCATE PREPARE stmt;
    END

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i dunno, i don't have version 5

    what happens when you execute that procedure?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2004
    Posts
    3

    can't execute it!

    "You have an error in your SQL syntax..."

    Is there someone who can write to me an example that works? The main is that I want to create table in stored procedure but pass the table name via param.

    (I'm using MySQL 5.0.0 alpha)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •