批量创建表空间数据文件(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 达梦数据库学习使用列表

相关推荐
YashanDB1 小时前
【YashanDB知识库】XMLAGG方法的兼容
数据库·yashandb·崖山数据库
独行soc1 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍11基于XML的SQL注入(XML-Based SQL Injection)
数据库·安全·web安全·漏洞挖掘·sql注入·hw·xml注入
风间琉璃""2 小时前
bugkctf 渗透测试1超详细版
数据库·web安全·网络安全·渗透测试·内网·安全工具
drebander2 小时前
SQL 实战-巧用 CASE WHEN 实现条件分组与统计
大数据·数据库·sql
IvorySQL2 小时前
IvorySQL 4.0 发布:全面支持 PostgreSQL 17
数据库·postgresql·开源数据库·国产数据库·ivorysql
18号房客2 小时前
高级sql技巧进阶教程
大数据·数据库·数据仓库·sql·mysql·时序数据库·数据库架构
Dawnㅤ2 小时前
使用sql实现将一张表的某些字段数据存到另一种表里
数据库·sql
张声录13 小时前
【ETCD】【实操篇(十二)】分布式系统中的“王者之争”:基于ETCD的Leader选举实战
数据库·etcd
运维&陈同学3 小时前
【模块一】kubernetes容器编排进阶实战之基于velero及minio实现etcd数据备份与恢复
数据库·后端·云原生·容器·kubernetes·etcd·minio·velero
有态度的马甲3 小时前
一种基于etcd实践节点自动故障转移的思路
数据库·etcd