使用变量建表
时间:2008-06-16 来源:szlishun
DELIMITER $$
DROP PROCEDURE IF EXISTS `short_msg`.`create_tab`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `create_tab`()
BEGIN
set @s_tabsql = 'create table s_';
set @s_tabsql = concat(@s_tabsql, adddate(curdate(), 1) + 'a');
set @s_tabsql = concat(@s_tabsql, " (
`id` int(11) NOT NULL auto_increment,
`mob_nu` varchar(20) default NULL,
`msg` varchar(200) default NULL,
`r_time` timestamp NULL default NULL,
`s_time` timestamp NULL default CURRENT_TIMESTAMP,
`class` tinyint(4) default '0',
PRIMARY KEY (`id`)
)");
PREPARE stmt1 FROM @s_tabsql;
EXECUTE stmt1;
set @r_tabsql = 'create table r_';
set @r_tabsql = concat(@r_tabsql, adddate(curdate(), 1) + 'a');
set @r_tabsql = concat(@r_tabsql, " (
`id` int(11) NOT NULL auto_increment,
`mob_nu` varchar(20) default NULL,
`msg` varchar(200) default NULL,
`r_time` timestamp NULL default NULL,
`s_time` timestamp NULL default CURRENT_TIMESTAMP,
`class` tinyint(4) default '0',
PRIMARY KEY (`id`)
)");
PREPARE stmt2 FROM @r_tabsql;
EXECUTE stmt2;
END$$ DELIMITER ;
BEGIN
set @s_tabsql = 'create table s_';
set @s_tabsql = concat(@s_tabsql, adddate(curdate(), 1) + 'a');
set @s_tabsql = concat(@s_tabsql, " (
`id` int(11) NOT NULL auto_increment,
`mob_nu` varchar(20) default NULL,
`msg` varchar(200) default NULL,
`r_time` timestamp NULL default NULL,
`s_time` timestamp NULL default CURRENT_TIMESTAMP,
`class` tinyint(4) default '0',
PRIMARY KEY (`id`)
)");
PREPARE stmt1 FROM @s_tabsql;
EXECUTE stmt1;
set @r_tabsql = 'create table r_';
set @r_tabsql = concat(@r_tabsql, adddate(curdate(), 1) + 'a');
set @r_tabsql = concat(@r_tabsql, " (
`id` int(11) NOT NULL auto_increment,
`mob_nu` varchar(20) default NULL,
`msg` varchar(200) default NULL,
`r_time` timestamp NULL default NULL,
`s_time` timestamp NULL default CURRENT_TIMESTAMP,
`class` tinyint(4) default '0',
PRIMARY KEY (`id`)
)");
PREPARE stmt2 FROM @r_tabsql;
EXECUTE stmt2;
END$$ DELIMITER ;
相关阅读 更多 +