Friday, June 29, 2012

Working with IBM DB2 Express 10.1

IBM's DB2 database is not like any of the other RDBMS products I've used in the past.
It's a monster.

I'll try to relive some of the things I've learnt while trying to find my way around it for the past 2 days now.

I strongly recommend reading the DB2 documentation thoroughly when you run into a snag as it will immensely help you in crafting the right blend of keywords to use when searching for a quick solution. At the very least, you should read this page table space design which is a nice intro on the design philosophy used by DB2. A lot of DB2 documentation will refer to the terms you'll learn from that page so it is important you understand them.


While doing a database import:
db2 -stvf C:\Code\BOT.ddl > C:\Code\BOT.log | more

I got bitten by a silly block commenting mistake described in this question.
I was using "/*" and  "*/" which sometimes worked but most of the time didn't. It often failed with:

SQL0104N An unexpected token "*/" was found following "BEGIN-OF-
STATEMENT".
Expected tokens may include: "". SQLSTATE=42601
 

The fix is to use a pair of "(=" and "=)" block comment delimiters since the SQL block that I intended to comment out was being executed from the Command Line Processor (CLP).

Link to the very well written DB2 documentation regarding CLP options is here.