对于复杂的 sql, 我们不清楚其表结构和索引结果. 使用 CommentSql 工具, 可以帮助我们快速阅读 sql 逻辑.
以 java 格式调用
import cn.sybn.util.io.driver.util.CommentSqlUtil;
@Test
public void commentSqlSimpleTest() {
String sql = "-- sql\n" +
"select a \n" +
"from t \n" +
"where b >1 and c = 1 and d is not null;\n" +
"-- 建表语句\n" +
"create table `t` (\n" +
" a int comment '字段a注释',\n" +
" b int comment '字段b注释',\n" +
" c int comment '字段c注释',\n" +
" d int comment '字段c注释',\n" +
" PRIMARY KEY (`a`),\n" +
" UNIQUE KEY `b` (`b`),\n" +
" KEY `b_c` (`b`,`c`)\n" +
")\n";
String s = CommentSqlUtil.commentSql(sql);
}
-
如果服务器可以连接目标库, 或者已经的导入了目标表的 information_schema 数据, 可以不用写建表语句.
-
对于服务器无法连接到sql中的表, 可以逐一附上建表语句
-- 请在此写入想要添加注释的 select 代码
select count(a) as a
from t
where b > 1
and c = 1
and d is not null;
-- 如果本页面无权访问相关表, 可直接附上 create table 语句
create table `t` (
a int comment '字段a注释',
b int comment '字段b注释',
c int comment '字段c注释',
d int comment '字段c注释',
PRIMARY KEY (`id`),
UNIQUE KEY `b` (`b`),
KEY `c` (`c`)
);
- 在 web sql 中在线调用