If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Create table in stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-15-04, 09:34
Tanton Tanton is offline
Registered User
 
Join Date: Nov 2004
Posts: 3
Create table in stored procedure

How can I create table in stored procedure but pass the name of table as parameter?
Reply With Quote
  #2 (permalink)  
Old 11-15-04, 11:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-16-04, 03:56
Tanton Tanton is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 11-16-04, 06:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
i dunno, i don't have version 5

what happens when you execute that procedure?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-16-04, 09:03
Tanton Tanton is offline
Registered User
 
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)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On