Explain the commands for DB2 database

Command line processor for DB2 database

Following are the DB2 command run from direct command prompt:

CLP – Command Line Processor
Command Center: Control Center

db2cmd – Open DB2 Command Window
db2eva – Event Analyzer
db2evmon – Event Monitor Productivity Tool
db2exfmt – Explain Table Format Tool
db2ckbkp – Check Backup
db2cc – Start Control Center
db2admin – DB2 Administration Server
db2icrt – Create Instance
db2idrop – Remove Instance
db2ilist – List Instances
db2trc – Trace
db2start – Start DB2
db2stop – Stop DB2
db2sync – Start DB2 Synchronizer
db2tbst – Get Tablespace State

The db2 command starts the command line processor (CLP). The CLP is used to execute database utilities, SQL statements and online help. Common commands include:

RESTART DATABASE
CREATE DATABASE
DROP DATABASE
GET DATABASE CONFIGURATION
RESET DATABASE CONFIGURATION
UPDATE DATABASE CONFIGURATION
LIST DATABASE DIRECTORY
LIST ODBC DATA SOURCES
BACKUP DATABASE
RESTORE DATABASE
TERMINATE
QUIT

Example of using DB2 command line:

Launch Control Center for: Privileges, Authorities and Access Rights
 
SQL: (Connect to a Database).
connect to <dbname> user <username> using <userpswd>

ex: connect to TEST user db2admin using db2admin

View a tables structure
Connect to the DB first.
describe table <schema>.<tablename>

Backup and Restore (also Copy a DB). 
Create a directory to backup to: 
Ex: C:\db2\mybackup 
Backup your DB:
Ex: db2 => backup database SAMPLE TO c:\db2\mybackup
Restore the DB:
db2 => restore database SAMPLE from C:\db2\mybackup
Restore the DB to another name (ie: Copy DB):
db2 => restore database SAMPLE from C:\db2\mybackup into MYSAMPLE 

Run SQL Commands
db2=> (examples)
list database directory - lists databases on DB2 server
connect to sample user db2admin using db2admin - connects to a db.
list tables - lists tables in the DB.
describe select * from emp_act - lists the structure of a table.
select * from EMP_ACT - list the contents in the table.

disconnect <database name> - clears connection
This entry was posted in DB2 on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply