[DB2]資料庫建立實驗

zad800發表於2010-07-26

資料庫建立

         課上,演示了一段建立資料庫的語句,出現了錯誤:

CREATE DATABASE  INFO \

managed BY DATABASE using \

AUTOMATIC STORAGE  YES \

ON \

/home/db2inst1/db2inst1/NODE0000/P1, \

/home/db2inst1/db2inst1/NODE0000/P2, \

/home/db2inst1/db2inst1/NODE0000/P3 \

AUTORESIZE YES \

INITIALSIZE 50M \

INCREASESIZE 10M \

MAXSIZE NONE

         原因:create database中只能指定儲存的路徑,不能指定“目錄”的容量大小,建立的語法如下:

db2 => ? create database

CREATE DATABASE database-name

[AT DBPARTITIONNUM | [AUTOMATIC STORAGE {NO | YES}]

[ON path[{,path}...][DBPATH ON path]]

[ALIAS database-alias] [USING CODESET codeset TERRITORY territory]

[COLLATE USING {SYSTEM | IDENTITY | IDENTITY_16BIT | COMPATIBILITY | NLSCHAR | UCA400_NO | UCA400_LSK | UCA400_LTH | language-aware-collation | locale-sensitive-collation}]

[PAGESIZE integer [K]]

[NUMSEGS numsegs] [DFT_EXTENT_SZ dft_extentsize] [RESTRICTIVE]

[CATALOG TABLESPACE tblspace-defn] [USER TABLESPACE tblspace-defn]

[TEMPORARY TABLESPACE tblspace-defn] [WITH "comment-string"]]

[AUTOCONFIGURE [USING config-keyword value [{,config-keyword value}...]]

[APPLY {DB ONLY | DB AND DBM | NONE}]]

         而在建立表空間的時候,才能指定autoresize,容器的初始化大小,增量的大小等,語法如下:

tblspace-defn:

  MANAGED BY { SYSTEM USING ('string' [ {,'string'} ... ] ) |

  DATABASE USING ({FILE | DEVICE} 'string' number-of-pages

  [ {,{FILE | DEVICE} 'string' number-of-pages} ... ]) | AUTOMATIC STORAGE}

  [EXTENTSIZE number-of-pages] [PREFETCHSIZE number-of-pages]

  [OVERHEAD number-of-milliseconds] [TRANSFERRATE number-of-milliseconds]

  [NO FILE SYSTEM CACHING | FILE SYSTEM CACHING]

  [AUTORESIZE {NO | YES}] [INITIALSIZE integer {K |M |G}]

  [INCREASESIZE integer {PERCENT |K |M |G}] [MAXSIZE {NONE | integer {K |M |G}}]

         修改上述語句,只能保留下如下的語句(managed by也只能用在建立表空間的時候):

db2 => CREATE DATABASE  INFO \

db2 (cont.) => AUTOMATIC STORAGE  YES \

db2 (cont.) => ON P1, P2, P3 \

db2 (cont.) =>

SQL1047N  The application is already connected to another database.

         出錯,提示需要斷開和已有資料庫的連線

db2 => disconnect  demo

DB20000I  The SQL DISCONNECT command completed successfully.

        然後再執行建立資料庫的語句即可。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14600958/viewspace-669432/,如需轉載,請註明出處,否則將追究法律責任。

相關文章