This section gives you the basic information you need to start working with DB2 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.
This section assumes that you have followed the instructions in Section 11. |
The left side of the DB2 Control Center provides an object-oriented view of the database objects that you have catalogued, including DB2 instances and databases on other DB2 servers. One way to add, edit, or drop database objects is to right-click on an object to bring up a menu.
To start the DB2 Control Center
Ensure you are logged on to your Linux workstation using either the DB2 Administration Server user ID or the DB2 instance user ID. If you use the su command to become the user, ensure you include the -l parameter to initialize the environment for the user.
Start the X server, if it is not already started.
Issue the db2cc command to start the DB2 Control Center. Depending on the speed of your system, it may take a few seconds for the splash screen to appear, and longer before the full DB2 Control Center appears.
The DB2 Information Center provides tree views of the information about DB2 that is installed on your system, as well as a number of links to web sites with further information. If you did not install the DB2 documentation, the tree views contain fewer links.
To start the DB2 Information Center
Ensure you are logged on to your Linux workstation using either the DB2 Administration Server user ID or the DB2 instance user ID. If you use the su command to become the user, ensure you include the -l parameter to initialize the environment for the user.
Ensure that the X server is started.
Issue the db2ic command to start the DB2 Information Center. Depending on the speed of your system, it may take a few seconds for the splash screen to appear, and longer before the full DB2 Information Center appears.
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.
If this is your first time using DB2, I would suggest creating the sample database that ships with DB2. The sample database is used throughout the DB2 documentation and is required by most of the sample applications. To create the sample database, you can either select the Create the sample database option when you create a DB2 instance, or issue the db2sampl command from the DB2 command line.
Before you can issue an SQL statement, you have to connect to a database. To connect to a database:
db2 CONNECT TO database USER userID USING password
To connect to a database, and have DB2 prompt you for the password:
db2 CONNECT TO database USER userID
To connect to a database using the default user ID:
db2 CONNECT TO database
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 columns from the EMPLOYEE table in the SAMPLE database, issue the following command:
bash$ db2 "SELECT * FROM employee" |
You can avoid typing db2 as the prefix for every SQL statement and DB2 command by issuing commands using the Command Line Processor (CLP). To start the CLP, issue the db2 command by itself. DB2 provides the following prompt:
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. |