BEGIN 
	DECLARE `@i` int(11);     
	DECLARE `@createSql` VARCHAR(2560); 
	DECLARE `@createIndexSql` VARCHAR(2560);     
		DECLARE `@tableName` varchar(32);

	set @i=0; 
	WHILE  @i< 16 DO
		IF @i<10 THEN
			SET @tableName=CONCAT('msg_message_0',@i);
		ELSE
			SET @tableName=CONCAT('msg_message_',@i);
		end IF;

		SET @createSql = CONCAT('CREATE TABLE IF NOT EXISTS ',@tableName,'(
			`ID` int  AUTO_INCREMENT PRIMARY KEY ,
			`OWNER` varchar(32) NOT NULL COMMENT \'ERP or VenderId\',
				`CONTENT` varchar(255) NOT NULL COMMENT \'消息内容\',
				`OWNER_TYPE` tinyint(4) NOT NULL COMMENT \'1 for ERP,2 for VenderId\',
				`CHANNEL` tinyint(4) default 0 COMMENT \'综合,频道,盘货,无线等\',
				`TYPE` tinyint(4) default 0 COMMENT \'1 for 驳回,2 for 通过等\',
				`CREATED` datetime COMMENT \'创建时间\',
				`MODIFIED` datetime COMMENT \'修改时间\',
				`STATUS` tinyint(4) DEFAULT 0 COMMENT \'0未读,1已读\' );'
			 ); 
				prepare stmt from @createSql; 
				execute stmt;                             
		
				-- 创建索引    
				set @createIndexSql  = CONCAT('create index `index_owner_owner_type` on ',@tableName,'(`OWNER`,`OWNER_TYPE`);');
				prepare stmt from @createIndexSql; 
				execute stmt; 
		SET @i= @i+1; 
    END WHILE;
END

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required

验证图片

*

二 + 二 =