438 lines
8.8 KiB
HTML
438 lines
8.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Using DB2 </TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="IBM DB2 Express-C for Linux HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Removing DB2 Express-C"
|
|
HREF="uninstalling.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Installation and operation test plan"
|
|
HREF="tests.html"></HEAD
|
|
><BODY
|
|
CLASS="sect1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>IBM DB2 Express-C for Linux HOWTO</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="uninstalling.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
></TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="tests.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="using"
|
|
></A
|
|
>20. Using DB2</H1
|
|
><P
|
|
>This section gives you the basic information you need to start working
|
|
with DB2 Express-C on Linux. It includes instructions on issuing DB2 commands and SQL
|
|
statements from the command line, as well as the commands you need to start
|
|
the DB2 Control Center and the DB2 Information Center. For more information
|
|
about general DB2 usage, please investigate the DB2 manuals and Information
|
|
Center.</P
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="AEN971"
|
|
></A
|
|
>20.1. DB2 Control Center</H2
|
|
><P
|
|
>To start the DB2 Control Center:
|
|
<P
|
|
></P
|
|
><OL
|
|
TYPE="1"
|
|
><LI
|
|
><P
|
|
> Ensure you are logged on to your Linux workstation using either
|
|
the DB2 Administration Server user ID (dasusr1 by default) or the DB2
|
|
instance user ID (db2inst1 by default). If you use the
|
|
<B
|
|
CLASS="command"
|
|
>su</B
|
|
> command to change to one of those users, ensure
|
|
you include the -l parameter to initialize the proper user
|
|
environment.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Start the X server, if it is not already started.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Start a terminal session, or type <B
|
|
CLASS="command"
|
|
>Alt + F2</B
|
|
> to bring
|
|
up the Linux "<B
|
|
CLASS="command"
|
|
>Run Command</B
|
|
>" dialog.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> Type <B
|
|
CLASS="command"
|
|
>db2cc</B
|
|
> to start the DB2 Control Center.
|
|
</P
|
|
></LI
|
|
></OL
|
|
>
|
|
</P
|
|
><P
|
|
>The left side of the DB2 Control Center provides an
|
|
object based view of the database objects that you have catalogued,
|
|
including DB2 instances and databases on other DB2 servers.
|
|
</P
|
|
><P
|
|
>One way to add, edit, or drop database objects is to right-click on
|
|
the object to bring up a context menu.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="AEN989"
|
|
></A
|
|
>20.2. DB2 Information Center</H2
|
|
><P
|
|
>As mentioned above, the new DB2 Information Center is a revamped
|
|
documentation display system that now encapsulates the task, concept and
|
|
reference information required to properly run DB2 . It can be installed
|
|
locally, on an intranet server, or accessed directly from the ibm.com
|
|
hosting service.</P
|
|
><P
|
|
>To start the DB2 Information Center:
|
|
<P
|
|
></P
|
|
><OL
|
|
TYPE="1"
|
|
><LI
|
|
><P
|
|
>Ensure you are logged on to your Linux workstation using either
|
|
the DB2 Administration Server user ID (dasusr1 by default) or the DB2
|
|
instance user ID (db2inst1 by default). If you use the
|
|
<B
|
|
CLASS="command"
|
|
>su</B
|
|
> command to change to one of those users, ensure
|
|
you include the -l parameter to initialize the proper user
|
|
environment.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Ensure that the X server is started, as the Information
|
|
Center requires a Web browser.</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
>Issue one of the launch commands:
|
|
<P
|
|
></P
|
|
><UL
|
|
><LI
|
|
>db2icdocs</LI
|
|
><LI
|
|
>db2help</LI
|
|
><LI
|
|
>db2ic</LI
|
|
><LI
|
|
>db2cc -ic</LI
|
|
></UL
|
|
>
|
|
</P
|
|
></LI
|
|
></OL
|
|
>
|
|
Alternatively, you can launch the Information Center from within the
|
|
Control Center (or any of the other GUI tools), by clicking an item under
|
|
the "Help" menu, or by clicking on the "?" (question mark) icon.</P
|
|
><P
|
|
>If you did not install the DB2 Information Center, or have not
|
|
configured your tools to use a different server, then these commands will launch
|
|
a detected browser, and take you directly to the IBM hosted DB2 Information
|
|
Center at <A
|
|
HREF="http://publib.boulder.ibm.com/infocenter/db2help/"
|
|
TARGET="_top"
|
|
>http://publib.boulder.ibm.com/infocenter/db2help/</A
|
|
>.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="AEN1008"
|
|
></A
|
|
>20.3. DB2 command line processor (CLP)</H2
|
|
><P
|
|
>If you are logged on to your Linux workstation using either the
|
|
DB2 Administration Server user ID or the DB2 instance user ID, you can
|
|
issue DB2 commands and SQL statements from the command line.</P
|
|
><P
|
|
>If this is your first time using DB2 , I would suggest creating
|
|
the DB2 sample database. The sample database is used
|
|
throughout the DB2 documentation and is required by most of the sample
|
|
applications.</P
|
|
><P
|
|
>To create the sample database, you can either select the <B
|
|
CLASS="command"
|
|
>Create
|
|
the SAMPLE database</B
|
|
> option from the DB2 First Steps launchpad, or by
|
|
issuing the <B
|
|
CLASS="command"
|
|
>db2sampl</B
|
|
> command from the command line.</P
|
|
><P
|
|
>Before you can issue an SQL statement, you have to connect to a
|
|
database. To connect to a database, enter the command:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>db2 CONNECT TO database USER userID USING password</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>To connect to a database, and have DB2 prompt you for the password,
|
|
issue the command:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>db2 CONNECT TO database USER userID</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>To connect to a database using the default user ID, issue the
|
|
command:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>db2 CONNECT TO database</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>Once you have connected to a database, you can then issue SQL
|
|
statements or DB2 commands against that database. For example, to select
|
|
all of the rows from the EMPLOYEE table in the SAMPLE database, issue
|
|
this command:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>db2 "SELECT * FROM employee"</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>You can avoid typing db2 as the prefix for every SQL statement and
|
|
DB2 command by issuing DB2 commands using the Command Line Processor
|
|
(CLP). To start the CLP, issue the <B
|
|
CLASS="command"
|
|
>db2</B
|
|
> command by itself
|
|
from a Linux command line terminal. DB2 provides the following prompt:
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="screen"
|
|
>You can issue database manager commands and SQL statements
|
|
from the command prompt. For example:
|
|
db2 => connect to sample
|
|
db2 => bind sample.bnd
|
|
|
|
For general help, type: ?.
|
|
For command help, type: ? command, where command can be
|
|
the first few keywords of a database manager command. For example:
|
|
? CATALOG DATABASE for help on the CATALOG DATABASE command
|
|
? CATALOG for help on all of the CATALOG commands.
|
|
|
|
To exit db2 interactive mode, type QUIT at the command prompt. Outside
|
|
interactive mode, all commands must be prefixed with 'db2'.
|
|
To list the current command option settings, type LIST COMMAND OPTIONS.
|
|
|
|
For more detailed help, refer to the Online Reference Manual.
|
|
|
|
db2 =></PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
</P
|
|
><P
|
|
>Some users prefer to avoid the CLP because it prevents using the
|
|
command line history features of the shell.</P
|
|
><P
|
|
>Some users claim that running the CLP within an Emacs shell gives
|
|
them the best of both worlds: they get command line history, and they
|
|
don't have to escape commands that contain lots of quotation marks and
|
|
brackets, but your mileage may vary.</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="uninstalling.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="tests.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Removing DB2 Express-C</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
> </TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Installation and operation test plan</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |