有没有办法 让 desc, count(*) 和 show index 用一行命令执行完毕的

MySql 码拜 8年前 (2016-05-19) 857次浏览
本人受到论坛提问的 定时自动建立数据库的启发,可以用concat 配合变量来 实现 自动
查看 表的一些基本信息, 就是desc aa, select count(*) from aa; show index from aa;  等等
============================================================
set @tbl =”aa”;
set @all_in = concat(“desc “,@tbl,”; select count(*) from “,@tbl,”; show index from  “,@tbl,”; show create table “,@tbl,”;” );
prepare  all_in from @all_in;
execute all_in ;
deallocate prepare all_in;
但是   prepare 这步骤的时候  会报错;
mysql> prepare  all_in from @all_in;
1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near “select count(*) from aa; show index from  aa; show create table aa” at line 1
就是 这种方法还不能   一句里边 放上多个 ;
所以  这个可以有什么办法么?
解决方案

10

前面那个自动创建table 是本人写的,确实不能运行多个sql
官方文档
http://dev.mysql.com/doc/refman/5.7/en/prepare.html
你有什么需求 为什么这么写,分开也可以吧

10

问过同样的问题,无直接的方法,你可以考虑存储过程

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明有没有办法 让 desc, count(*) 和 show index 用一行命令执行完毕的
喜欢 (0)
[1034331897@qq.com]
分享 (0)