# DB2 管理

##### 資料庫

新增資料庫

```pl/sql
create db MYDB on /db2_home/istv11/MYDB using codeset big5 territory TW collate using identity
 USER TABLESPACE MANAGED BY DATABASE USING (FILE '/db2_home/istv11/MYDB/TBS_DMS/userspace_4k_c01' 524288)
 TEMPORARY TABLESPACE MANAGED BY SYSTEM USING ('/db2_home/istv11/MYDB/TBS_SMS/tempspace1') ;
```

> TIP: 語系編碼 codeset 除了 big5，也有 utf-8。

> TIP: 區域碼 territory TW 是台灣。

##### 執行 SQL 時顯示開始與結束時間

```SQL
select 'Begin Time:',char(current date,iso)||' '||char(current time,iso) from sysibm.sysdummy1;
--
--
select 'End Time:',char(current date,iso)||' '||char(current time,iso) from sysibm.sysdummy1; 
```

##### 快速產生所有資料表的 runstats 腳本

```shell
db2 -x "select 'runstats on table',substr(rtrim(tabschema)||'.'||rtrim(tabname),1,35),'with distribution and detailed indexes all allow write access;'from syscat.tables where type = 'T' and tabschema not in ('SYSIBM','ASN')" > runstats_all.sql
```

##### 開發工具下載

URL: [https://early-access.ibm.com/software/support/trial/cst/programwebsite.wss?siteId=1120](https://early-access.ibm.com/software/support/trial/cst/programwebsite.wss?siteId=1120)

- DB2 Community Edition : A FREE edition that provides for up to 8GB of memory, 4 CPU cores, and no restrictions on features or database size.
- Database Administrator Tools
- Developer Tools