Once you have finished installing and configuring your Db2® Community Edition
Docker image on your Linux machine, you can test it against the Db2 SAMPLE
database.
About this task
You will create the Db2 SAMPLE database
from the command line, after which you can run simple SQL commands against it to verify that your
Db2
Community Edition instance is working inside the Docker container.
Procedure
-
Enter the following commands to create a sample database and begin executing SQL commands:
db2sampl -force -sql i
This command may cause the following error:
Creating database "SAMPLE"...
Connecting to database "SAMPLE"...
Creating tables and data in schema "DB2INST1"...
--ERROR------------------
SQLSTATE = 38503
Native Error Code = -1131
[IBM][CLI Driver][DB2/LINUXX8664] SQL1131N A stored procedure process
has been terminated abnormally. Routine name: "SYSPROC.CREATE_SQL_SAMPLE".
Specific name: "CREATE_SQL_SAMPLE". SQLSTATE=38503
-------------------------
--ERROR------------------
SQLSTATE = 08007
Native Error Code = -1224
[IBM][CLI Driver] SQL1224N The database manager is not able to accept
new requests, has terminated all requests in progress, or has terminated
the specified request because of an error or a forced interrupt. SQLSTATE=55032
-------------------------
'db2sampl' processing complete.
If this error occurs, enter the following commands:
db2 deactivate db sample
db2 drop db sample
db2 connect to sample
The output
should now
read
SQL1013N The database alias name or database name "SAMPLE" could not be found. SQLSTATE=42705" 4
Re-enter
db2sampl -force -sql i
to generate the sample database.
- Run
db2 connect to sample
.
Once you are
connected to the sample database, you can begin executing SQL statements, such as:
db2 "select * from department"
to selects all the rows (* means all rows)
from the table "department", or
db2 "select * from department fetch first 1 rows only"
to select the first
row from the table "department". To change the number of rows retrieved, simply increase the number
in the command.
- If the database returns the expected results, you can enter
db2 connect reset
9
to terminate the Db2 database
connection.
- Enter
logout
to end your Docker session.