1. 在db2中,如何在某個用戶下創建表
DB2裡面有一個schema(模式)的概念,你要創建把表創建到某個用戶下面,只需要在創建表的時候指定表的模式,當然首先需要在那個模式下面創建表的許可權。
比如你是user1, 想要創建表到user2下面,默認情況下用user1登陸的時候,表是創建在user1模式下面的。
如下:
db2==> connect to TESTDB user user1 using "xxxxxx"
db2==> create table user2.tbl1(id int not null primary key, c1 char(20))
這樣,創建的表就在user2這個模式下面了。
2. 在db2中,如何在某個用戶下創建表
DB2裡面有一個schema(模式)的概念,你要創建把表創建到某個用戶下面,只需要在創建表的時候指定表的模式,當然首先需要在那個模式下面創建表的許可權。
比如你是user1,
想要創建表到user2下面,默認情況下用user1登陸的時候,表是創建在user1模式下面的。
如下:
db2==>
connect
to
TESTDB
user
user1
using
"xxxxxx"
db2==>
create
table
user2.tbl1(id
int
not
null
primary
key,
c1
char(20))
這樣,創建的表就在user2這個模式下面了。
3. db2資料庫導出表結構
第一行是連接資料庫,後面就是具體的建表語句。 2、執行建表腳本 命令為: db2 –tvf f:\export\init.sql 1 以上是導出了資料庫中所有表的表結構,並在新的資料庫中執行命令,新建所有表。但是表中均是不存在數據的。
4. oracle 建表語句修改為DB2的建表語句
db2 "create table tabname(id varchar(10),
password varchar(10),
ywlx varchar(10),
kh varchar(10))"
以上是 db2 建表命令, 與Oracle其實類似的。改動不太大,區別可能就是欄位類型不一樣
5. db2的命令行處理器怎麼執行sql腳本文件建表
無論是windows系統,還是linux或AIX
你可以在實例用戶下,先鍵入 db2 這個命令,進入到db2命令行,然再執行creat database mydb
或者
你可以在系統命令行下直接執行
db2 create database mydb
或
db2 "create database mydb"
6. 如何在DB2建表空間
一、建表空間和資料庫
1.在db2ad、db2db和db2ap上均執行:
[sql] view plain
db2set db2comm=tcpip
db2set db2codepage=1386
2.新建資料庫:
[sql] view plain
db2 create db <dbname> using codeset gbk territory CN collate using identity
3.連接上資料庫:
[sql] view plain
db2 "connect to <dbname>"
4.創建緩沖池 + 建立表空間;
1).刪除舊的表空間:
[sql] view plain
db2 drop tablespace tablespace1, tablespace2, tablespace3
2).新建緩沖池:
[sql] view plain
db2 create bufferpool bp32k all nodes size -1 pagesize 32k
bp32k為該緩沖池的名稱;
32K為頁大小;
size=-1表示使用預設的buffpage,而buffpage可以通過db2 get db cfg|grep -i buff參數查看到;
3).新建表空間:
[sql] view plain
db2 "create regular tablespace tablespace1 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace1' 5g) bufferpool bp32k"
db2 "create regular tablespace tablespace2 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace2' 10g) bufferpool bp32k"
db2 "create regular tablespace tablespace3 pagesize 32k managed by database using(file '/usr/yixiayizi/tablespace3' 2g) bufferpool bp32k"
注意(file '/usr/yixiayizi/tablespace1' 5g)的設置:
第一個參數:
當指向外置盤時,file改為device;
當指向文件路徑時,為file;
第二個參數:需要是絕對路徑;
第三個參數:該表空間的大小;
關於表空間和緩沖池的說明見如下網頁:
http://www.ibm.com/developerworks/cn/data/library/techarticles/0212wieser/0212wieser.html
5.調整表空間大小:
[sql] view plain
ALTER TABLESPACE <tablespace1> RESIZE ( FILE '/cstp/usr/db2ad/db2ad/ <tablespace1>' 5g )
6.調整緩沖池大小:
[sql] view plain
db2 alter bufferpool bp32k size 2g
--------------------------------------------------------------------------------------------
遠程客戶端的配置網路:
1.db2ad賬戶下:
1). 首先查看/etc/services中db2各個服務的埠號:
more /etc/services
可以看到如下信息:
DB2_db2ad 60040/tcp
DB2_db2ad_1 60041/tcp
DB2_db2ad_2 60042/tcp
DB2_db2ad_END 60043/tcp
2).
[sql] view plain
db2 update dbm cfg using SVCENAME DB2_db2ad
這樣在服務端實例對應的埠號就是60040;
------------
2.db2db賬戶下:
1).
[sql] view plain
db2 catalog tcpip node <node_name> remote 172.17.252.214 server 60040
(上面操作的反編目:db2 uncatalog node <node_name>)
2).db2 list node directory可以看到如下信息:
Node Directory
Number of entries in the directory = 1
Node 1 entry:
Node name = <node_name>
Comment =
Directory entry type = LOCAL
Protocol = TCPIP
Hostname = 172.17.252.214
Service name = 60040
3).
[sql] view plain
db2 catalog db <dbname> at node <node_name>
(上面操作的反編目:db2 uncatalog db <dbname>)
4).db2 list db directory可以看到如下信息:
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = <dbname>
Database name = <dbname>
Node name = <node_name>
Database release level = c.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
--編目系統資料庫目錄
-----------------------
授權:
在db2ad賬戶下,給db2db授權使用表空間:
[sql] view plain
db2 "grant use of tablespace <tablespace1> to user db2db"
db2 "grant use of tablespace <tablespace2> to user db2db"
db2 "grant use of tablespace <tablespace3> to user db2db"
二、建表
切換到db2db用戶,執行建表的sql語句:
db2 -vf tmp.sql
7. db2建表語句
-- 以table1表為例創建一個結構一樣的零時的表table2
CREATE GLOBAL TEMPORARY TABLE table2 LIKE table1;
-- 並插入table1表的數據到table2中來
insert into table2 select * from table1;