批量创建表空间数据文件(DM8:达梦数据库)

DM8:达梦数据库 - - 批量创建表空间数据文件

  • 环境介绍
  • [1 批量创建表空间SQL](#1 批量创建表空间SQL)
  • [2 达梦数据库学习使用列表](#2 达梦数据库学习使用列表)

环境介绍

  • 在某些场景(分区表子表)需要批量创建表空间,给不同的表使用,以下代码是批量创建表空间的SQL语句;

1 批量创建表空间SQL

sql 复制代码
--创建 24个数据表空间,每个表空间有3个数据文件,一个数据文件初始化为128M,每次扩展1024M,最大扩展到 409600M

DECLARE
    TBS_NAME VARCHAR :='TBS_DATA_';		--数据表空间名称
    --TBS_NAME VARCHAR :='TBS_INDEX_';	--索引表空间名称

    TBS_COUNT        INT :=24;	--表空间数量
    TBS_FILE_COUNT   INT :=3;	--表空间数据文件数量
    TBS_FILE_F       INT;
    
    TBS_EXTENT_BEGIN VARCHAR;
    TBS_EXTENT_TEMP  VARCHAR;
    TBS_EXTENT_TEMP2 VARCHAR;
    TBS_EXTENT_END   VARCHAR;
    TBS_EXTENT_ALL   VARCHAR;
BEGIN
    FOR I IN 1..TBS_COUNT 
    LOOP
        TBS_EXTENT_BEGIN :='create tablespace "'||TBS_NAME||I||'" datafile '''||TBS_NAME||I||'_FILE_1.DBF'' size 128 autoextend on next 1024 maxsize 409600';
        TBS_EXTENT_TEMP  :='';
        FOR TBS_FILE_F IN 2..TBS_FILE_COUNT 
        LOOP
            TBS_EXTENT_TEMP2    := ','''||TBS_NAME||I||'_FILE_'||TBS_FILE_F||'.DBF'' size 128 autoextend on next 1024 maxsize 409600';
            TBS_EXTENT_TEMP := TBS_EXTENT_TEMP||TBS_EXTENT_TEMP2;
        END LOOP;
        TBS_EXTENT_END := ' CACHE = NORMAL;';
        TBS_EXTENT_ALL :=TBS_EXTENT_BEGIN||TBS_EXTENT_TEMP||TBS_EXTENT_END;
        PRINT (TBS_EXTENT_ALL);
        EXECUTE IMMEDIATE TBS_EXTENT_ALL;
    END LOOP;
END;
-- 生成的创建表空间 SQL
/*
create tablespace "TBS_DATA_1" datafile 'TBS_DATA_1_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_1_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_1_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_2" datafile 'TBS_DATA_2_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_2_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_2_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_3" datafile 'TBS_DATA_3_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_3_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_3_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_4" datafile 'TBS_DATA_4_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_4_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_4_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_5" datafile 'TBS_DATA_5_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_5_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_5_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_6" datafile 'TBS_DATA_6_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_6_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_6_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_7" datafile 'TBS_DATA_7_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_7_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_7_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_8" datafile 'TBS_DATA_8_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_8_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_8_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_9" datafile 'TBS_DATA_9_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_9_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_9_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_10" datafile 'TBS_DATA_10_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_10_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_10_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_11" datafile 'TBS_DATA_11_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_11_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_11_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_12" datafile 'TBS_DATA_12_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_12_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_12_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_13" datafile 'TBS_DATA_13_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_13_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_13_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_14" datafile 'TBS_DATA_14_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_14_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_14_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_15" datafile 'TBS_DATA_15_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_15_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_15_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_16" datafile 'TBS_DATA_16_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_16_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_16_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_17" datafile 'TBS_DATA_17_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_17_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_17_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_18" datafile 'TBS_DATA_18_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_18_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_18_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_19" datafile 'TBS_DATA_19_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_19_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_19_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_20" datafile 'TBS_DATA_20_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_20_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_20_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_21" datafile 'TBS_DATA_21_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_21_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_21_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_22" datafile 'TBS_DATA_22_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_22_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_22_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_23" datafile 'TBS_DATA_23_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_23_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_23_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;
create tablespace "TBS_DATA_24" datafile 'TBS_DATA_24_FILE_1.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_24_FILE_2.DBF' size 128 autoextend on next 1024 maxsize 409600,'TBS_DATA_24_FILE_3.DBF' size 128 autoextend on next 1024 maxsize 409600 CACHE = NORMAL;

*/

2 达梦数据库学习使用列表

相关推荐
果果燕18 分钟前
SQLite3数据库查询学习笔记2
数据库·sqlite
2501_9083298530 分钟前
实战:用OpenCV和Python进行人脸识别
jvm·数据库·python
认真的薛薛1 小时前
Docker网络模式
linux·运维·数据库·面试·github
Java后端的Ai之路1 小时前
Milvus 向量数据库从入门到精通:AI 时代的“记忆中枢“实战指南(建议收藏!)
数据库·人工智能·milvus·向量数据库·rag
老刘说AI1 小时前
WorkFlow Agent案例:auto_document_agent(文件自动处理)
开发语言·数据库·人工智能·python·神经网络·自然语言处理
脚大江山稳1 小时前
单独为mysql数据库的某个库创建用户
android·数据库·mysql
LSL666_1 小时前
MybatisPlus——通用枚举
数据库·mybatisplus
golang学习记2 小时前
Go 实时批处理:让数据库少挨点打 [特殊字符]
开发语言·数据库·golang
wang09072 小时前
Linux性能优化之平均负载
linux·数据库·性能优化
电商API&Tina2 小时前
比价 / 选品专用:京东 + 淘宝 核心接口实战(可直接复制运行)
大数据·数据库·人工智能·python·json·音视频