麟の随笔

  • 游戏
  • 影视
  • Tech
  1. 首页
  2. 科技
  3. SQL
  4. 正文

SQL语句记录

2023年10月11日 1742点热度 1人点赞 0条评论

通用SQL

MySQL

一、当意外删除经纬度字段时从空间字段中获取值

update `table_name` t set t.LAT = REPLACE(substring_index(ST_AsText(t.SHAPE)," ",-1),")","") 

二、查询MySQL数据库空间使用(全库)

SELECT 
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;

三、查询MySQL数据库空间使用(单库)

SELECT 
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)',
sum(truncate(DATA_FREE/1024/1024, 2)) as '碎片占用(MB)'
from information_schema.tables
where table_schema='zwmmps'
order by data_length desc, index_length desc;

锦集

MySQL 空间坐标系修改
MySQL空间查询函数

Oracle

PostgreSQL

PostgreSQL模仿MySQL的substring_index方法

CREATE OR REPLACE FUNCTION substring_index(varchar, varchar, integer)
RETURNS varchar AS $$
DECLARE
tokens varchar[];
length integer ;
indexnum integer;
BEGIN
tokens := pg_catalog.string_to_array($1, $2);
length := pg_catalog.array_upper(tokens, 1);
indexnum := length - ($3 * -1) + 1;
IF $3 >= 0 THEN
RETURN pg_catalog.array_to_string(tokens[1:$3], $2);
ELSE
RETURN pg_catalog.array_to_string(tokens[indexnum:length], $2);
END IF;
END;
$$ IMMUTABLE STRICT LANGUAGE PLPGSQL;

批量赋予权限

GRANT  ALL privileges on all tables in SCHEMA PUBLIC to user
标签: 暂无
最后更新:2024年8月12日

晓虎

必须有人浴血奋战,世上才有自由可言!

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

文章目录
  • 通用SQL
    • MySQL
      • 一、当意外删除经纬度字段时从空间字段中获取值
      • 二、查询MySQL数据库空间使用(全库)
      • 三、查询MySQL数据库空间使用(单库)
      • 锦集
  • Oracle
  • PostgreSQL

COPYRIGHT © 2024 kirinz.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

闽ICP备19013981号