手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux下学习DB2命令的笔记

[日期:2012-08-10] 来源:Linux社区  作者:sunrier [字体:大 中 小]

11.在数据库test中创建表student
[db2inst1@localhost ~]$ db2 connect to test

   Database Connection Information

 Database server        = DB2/LINUX 9.7.1
 SQL authorization ID   = DB2INST1
 Local database alias   = TEST

[db2inst1@localhost ~]$ db2 "create table student (id int,fname varchar(30),age int)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 list tables

Table/View                      Schema          Type  Creation time           
------------------------------- --------------- ----- --------------------------
STUDENT                         DB2INST1        T     2012-08-06-14.38.33.456768

  1 record(s) selected.

[db2inst1@localhost ~]$

 

12.向表student中添加数据信息
[db2inst1@localhost ~]$ db2 "insert into student values (1,'Tom',22)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "insert into student values (2,'Jack',21)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "insert into student values (3,'Sunrier',25)"
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$

 

13.显示表student所有的信息
[db2inst1@localhost ~]$ db2 "select * from student"

ID          FNAME                          AGE      
----------- ------------------------------ -----------
          1 Tom                                     22
          2 Jack                                    21
          3 Sunrier                                 25

  3 record(s) selected.

[db2inst1@localhost ~]$

 

14.查看表student结构
[db2inst1@localhost ~]$ db2 "describe select * from student"

 Column Information

 Number of columns: 3

 SQL type              Type length  Column name                     Name length
 --------------------  -----------  ------------------------------  -----------
 497   INTEGER                   4  ID                                        2
 449   VARCHAR                  30  FNAME                                     5
 497   INTEGER                   4  AGE                                       3

[db2inst1@localhost ~]$

或
[db2inst1@localhost ~]$ db2 "describe select * from db2inst1.student"

 Column Information

 Number of columns: 3

 SQL type              Type length  Column name                     Name length
 --------------------  -----------  ------------------------------  -----------
 497   INTEGER                   4  ID                                        2
 449   VARCHAR                  30  FNAME                                     5
 497   INTEGER                   4  AGE                                       3

[db2inst1@localhost ~]$

15.列出所有的系统表
[db2inst1@localhost ~]$ db2 list tables for system

Table/View                      Schema          Type  Creation time           
------------------------------- --------------- ----- --------------------------
ATTRIBUTES                      SYSCAT          V     2012-08-06-14.20.49.182036
AUDITPOLICIES                   SYSCAT          V     2012-08-06-14.20.49.237474
AUDITUSE                        SYSCAT          V     2012-08-06-14.20.49.243535
BUFFERPOOLDBPARTITIONS          SYSCAT          V     2012-08-06-14.20.49.264336
BUFFERPOOLNODES                 SYSCAT          V     2012-08-06-14.20.49.277662
BUFFERPOOLS                     SYSCAT          V     2012-08-06-14.20.49.281563
CASTFUNCTIONS                   SYSCAT          V     2012-08-06-14.20.49.309007
CHECKS                          SYSCAT          V     2012-08-06-14.20.49.314078
...............................................................................
...............................................................................
...............................................................................
...............................................................................
...............................................................................
...............................................................................
ROUTINES                        SYSSTAT         V     2012-08-06-14.20.52.502569
TABLES                          SYSSTAT         V     2012-08-06-14.20.52.510027
HMON_ATM_INFO                   SYSTOOLS        T     2012-08-06-14.35.41.029633
HMON_COLLECTION                 SYSTOOLS        T     2012-08-06-14.35.41.208925
POLICY                          SYSTOOLS        T     2012-08-06-14.35.40.156347

  396 record(s) selected.

[db2inst1@localhost ~]$

16.删除表中的数据 :
[db2inst1@localhost ~]$ db2 delete from student where id=3
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 "select * from student"

ID          FNAME                          AGE      
----------- ------------------------------ -----------
          1 Tom                                     22
          2 Jack                                    21

  2 record(s) selected.

[db2inst1@localhost ~]$

17.删除一个数据库的表
[db2inst1@localhost ~]$ db2 drop table student
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 list tables

Table/View                      Schema          Type  Creation time           
------------------------------- --------------- ----- --------------------------

  0 record(s) selected.

[db2inst1@localhost ~]$

18.删除一个数据库test
[db2inst1@localhost ~]$ db2 list db directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = TEST
 Database name                        = TEST
 Local database directory             = /home/db2inst1
 Database release level               = d.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =
[db2inst1@localhost ~]$ db2 drop db test
SQL1035N  The database is currently in use.  SQLSTATE=57019
SQL1025N  The database manager was not stopped because databases are still active.
[db2inst1@localhost ~]$ db2 connect reset
DB20000I  The SQL command completed successfully.
[db2inst1@localhost ~]$ db2 drop db test
DB20000I  The DROP DATABASE command completed successfully.
[db2inst1@localhost ~]$ db2 list db directory
SQL1057W  The system database directory is empty.  SQLSTATE=01606
[db2inst1@localhost ~]$
注:删除数据库首先要断开数据库的连接

19.显示当前数据库连接有哪些应用程序
[root@localhost ~]# su - db2inst1
[db2inst1@localhost DB2]$ db2 list application
SQL1611W  No data was returned by Database System Monitor.
[db2inst1@localhost DB2]$ db2 connect to test

   Database Connection Information

 Database server        = DB2/LINUX 9.7.1
 SQL authorization ID   = DB2INST1
 Local database alias   = TEST

[db2inst1@localhost DB2]$ db2 list application

Auth Id  Application    Appl.      Application Id                                                 DB       # of
         Name           Handle                                                                    Name    Agents
-------- -------------- ---------- -------------------------------------------------------------- -------- -----
DB2INST1 db2bp          35         *LOCAL.db2inst1.120807014245                                   TEST     1  

[db2inst1@localhost DB2]$

20.查看DB2全部受支持的注册表变量列表
[db2inst1@localhost DB2]$ db2set -lr
DB2_OVERRIDE_BPF
DB2_PARALLEL_IO
DB2ACCOUNT
DB2ADMINSERVER
DB2BQTIME
DB2BQTRY
.........................................
.........................................
.........................................
.........................................
.........................................
.........................................
DB2TCP_CLIENT_KEEPALIVE_TIMEOUT
DB2_PMODEL_SETTINGS
DB2_PMAP_COMPATIBILITY
DB2_HADR_ROS
DB2_STANDBY_ISO
[db2inst1@localhost DB2]$

linux
相关资讯       DB2 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2017/10/17 13:53:35
是是