insert的时候,如何判断表是否存在
需求是这样的,表是按天生成的,例如table20110101,table20110102….
但是中间有可能某天的表不存在
这样,我按天循环insert的时候就会出错,请问怎么在insert的同时判断表是否存在,不存在就停止操作?
——解决方案——————–
——解决方案——————–
关联 系统表,实例sql如下。看看
select * information_schema.TABLES
where table_schema=’test’ and table_name=’test’;
——解决方案——————–
- SQL code
create procedure sp() begin if exists(select 1 information_schema.TABLES where table_schema='test' and table_name='test') then insert into test values(1); end if; end;
------解决方案--------------------
- SQL code
create procedure sp() begin if exists(select 1 from information_schema.TABLES where table_schema='test' and table_name='test') then insert into test values(1); end if; end;
------解决方案--------------------
建议重新考虑你的数据库设计,这种分表设计都少见。你应该使用一张表来存储所有的记录,而不是每天一张表。
如果有效率上的考虑,则可以使用分区表。
------解决方案--------------------
按天分表,确实比较少见。估计楼主的需求也比较特殊。
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
mysql分区表
------解决方案--------------------
欢迎大家阅读《insert的时候,怎么判断表是否存在》,跪求各位点评,by 搞代码