数据库名
tsrs_maintenance_center
要建表的表结构
在数据库写上面表的存储过程函数
KEY cycle
(cycle
) USING BTREE 是索引。
create procedure create2_historyTable(IN souce_Name varchar(50),IN d_tsrs_interface_history varchar(50))
begin
declare tablename varchar(50);
declare tableOldName varchar(50);
declare tablePname varchar(50);
declare tablePOldName varchar(50);
declare tableEname varchar(50);
declare tableEOldName varchar(50);
declare tablenameAalrm varchar(50);
if d_tsrs_interface_history <>'' then
-- 判断history表是否存在
select table_name into tablePOldName from information_schema.tables where table_schema =souce_Name and table_name =concat('d_tsrs_interface_history_',DATE_FORMAT(CURDATE(),'%Y%m%d')) LIMIT 1;
if tablePOldName is null then
-- 创建history新表
set @createTbSql1=concat('CREATE TABLE IF NOT EXISTS ','d_tsrs_interface_history_',DATE_FORMAT(CURDATE(),'%Y%m%d'),'(
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ''标识'',
`unixTime` bigint(20) DEFAULT NULL COMMENT ''Unix时间'',
`cycle` bigint(255) DEFAULT NULL COMMENT ''帧序号'',
`deviceId` bigint(20) DEFAULT NULL COMMENT ''存储设备CTCSID'',
`typeId` int(255) DEFAULT NULL COMMENT ''接口类型'',
`passagewayType` int(255) DEFAULT NULL COMMENT ''通道类型'',
`isPeriod` int(255) DEFAULT NULL COMMENT ''周期'',
`sender` bigint(20) DEFAULT NULL COMMENT ''发送方'',
`receiver` bigint(20) DEFAULT NULL COMMENT ''接收方'',
`messageType` varchar(255) DEFAULT NULL COMMENT ''信息类型'',
`originalData` mediumtext COMMENT ''原始数据内容'',
PRIMARY KEY (`id`),
KEY `cycle` (`cycle`) USING BTREE
) DEFAULT CHARSET=utf8mb4 ;');
-- 执行动态生成的sql语句
PREPARE temp FROM @createTbSql1;
EXECUTE temp;
end if;
end if;
end
执行存储过程,生成create2_historyTable
调用存储过程,执行命令:
call create2_historyTable('tsrs_maintenance_center','d_tsrs_interface_history')