- Created by: Andres Gomez Casanova @angoca
- Version: 2021-02-23
Get the most recent version at https://angoca.github.com/db2-cheat-sheet
- Execution of a file in the console (db2clp).
- Define a terminator character:
- List all databases (aliases):
- Connect to a database (alias):
- Disconnect from a database:
- Get values from the environment (registry values).
- Current timestamp:
- Connected user:
- Current database:
- List all tables:
- Change current schema:
- Change the isolation level (RR, RS, CS, UR):
- List all tablespaces with their status:
- Describe the structure of the table:
- Describe the result of a query:
- Get help for a Db2 command:
- Get help for a SQL code (SQLXXXX) or SQLstate (YYYYY):
- Create a schema:
- Create a table specifying primary key:
- Create a table specifying tablespaces:
- Create a table specifying schema:
- Create a table with auto incremental column:
- Create a table like another one:
- Comment on table and column:
- Declare a temporary table (session schema):
- Create a global temporary tablespace:
- Create an index:
- Create a unique index:
- Drop an index:
- Add a column (requires Reorg table):
- Change nullability:
- Drop nullability:
- Rename a column:
- Drop column:
- Create a primary key constraint:
- Drop primary key:
- Add identity:
- Restart identity:
- Drop identity:
- Create a foreign key:
- Create a check constraint:
- Enforce a constraint:
- Not enforce a constraint:
- Change the granularity of the locks:
- Drop a table:
- Rename a table:
- Truncate a table:
- Create a sequence:
- Restart sequence:
- Create a stored procedure:
- Create a trigger:
- Create a view:
- Grant on a table:
- Grant execution on a stored procedure:
- Revoke on a table:
- Insert values on a table:
- Insert certain columns:
- Insert values from a select:
- Insert in temporary table:
- Update fields:
- Merge (upsert):
- Delete rows:
- Export:
- Import:
- Cursor:
- Load:
- Query the status of the load in a table:
- Set integrity:
- Ingest:
- Get the next value from a sequence:
- VALUES NEXT VALUE FOR seq
- INSERT INTO tbl3 (col1) VALUES (NEXT VALUE FOR seq)
- Commit changes:
- Create a savepoint:
- Undo changes until savepoint:
- Undo changes:
- Put a lock at table level:
- Execute a query without regard of commit rows:
- Execute a query with only 5 rows:
- Perform a query to a dummy table (dual):
- SELECT 'Any string' FROM SYSIBM.SYSDUMMY1
- Perform a query calling a function:
- SELECT HEX(col2) FROM tbl5
- Call a function:
- VALUES HEX('AnyText')
- Perform a cast:
- VALUES CAST('123' AS INTEGER)
- Concatenate:
- Escape a single quote in a text field:
- Query the database catalog:
- SELECT * FROM SYSCAT.TABLES
- SELECT * FROM SYSCAT.TABAUTH
- SELECT * FROM SYSCAT.ROUTINES
- Create a compound statement – Anonymous block:
- Call a stored procedure with an IN and an OUTPUT parameter:
- Perform a reorg via ADMIN_CMD (Sometimes required after “alter table”):
- CALL SYSPROC.ADMIN_CMD('REORG TABLE tbl1')
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.