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

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

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

环境介绍

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

1 批量创建表空间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;

*/

批量创建表空间数据文件(DM8:达梦数据库)_第1张图片

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

  • 达梦数据库学习使用列表 - - 点击跳转

你可能感兴趣的:(数据库,DMSQL,数据库,oracle)