数据库建表的存储过程

数据库名

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')

生成当天的表

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值