IBM Books

SQL Getting Started


Connecting to a Database

You need to connect to a database before you can use SQL statements to query or manipulate it. The CONNECT statement associates a database connection with a user name.

For example, to connect to the SAMPLE database, type the following command in the DB2 command line processor :

  CONNECT TO SAMPLE USER USERID USING  PASSWORD

(Be sure to choose values for USER and USING that are valid on the server system.)

In this example, USER is USERID and USING is PASSWORD.

The following message tells you that you have made a successful connection:

        Database Connection Information                   
                                                    
           Database product       = DB2/6000 6.1.0                
           SQL authorization ID   = USERID                     
           Local database alias   = SAMPLE                     
 

When a connection is set through the CONNECT statement an explicit connection is established. In an implicit connection the default server has been set. In this case you can use CONNECT or you can just start issuing statements and a connection will automatically be established.

Once you are connected, you can start manipulating the database. For details on implicit and explicit connections refer to the CONNECT statement in the SQL Reference.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]