Catalog / IBM Db2 Cheatsheet
IBM Db2 Cheatsheet
A quick reference guide for IBM Db2, covering essential commands, data types, SQL syntax, and administrative tasks.
Basic SQL Commands
Data Definition Language (DDL)
|
Creates a new table. Example:
|
|
Modifies an existing table. Example:
|
|
Deletes a table. Example:
|
|
Creates an index on a table. Example:
|
|
Deletes an index. Example:
|
|
Creates a virtual table based on the result-set of an SQL statement. Example:
|
Data Manipulation Language (DML)
|
Inserts data into a table. Example:
|
|
Updates existing data in a table. Example:
|
|
Deletes data from a table. Example:
|
|
Retrieves data from a table. Example:
|
|
Performs insert, update, or delete operations based on a condition. Example:
|
Advanced SQL and Functions
Common Functions
|
Returns the number of rows. Example:
|
|
Returns the average value. Example:
|
|
Returns the sum of values. Example:
|
|
Returns the minimum value. Example:
|
|
Returns the maximum value. Example:
|
|
Converts a string to uppercase. Example:
|
|
Converts a string to lowercase. Example:
|
|
Returns the length of a string. Example:
|
Joins
|
Returns rows when there is a match in both tables. Example:
|
|
Returns all rows from the left table, and the matched rows from the right table. Example:
|
|
Returns all rows from the right table, and the matched rows from the left table. Example:
|
|
Returns all rows when there is a match in one of the tables. Example:
|
Db2 Administration
Basic Administration Commands
|
Starts the Db2 database manager. Example:
|
|
Stops the Db2 database manager. Example:
|
|
Connects to a specific database. Example:
|
|
Disconnects from a database. Example:
|
|
Lists all databases known to the Db2 instance. Example:
|
|
Backs up a database to a specified location. Example:
|
|
Restores a database from a backup. Example:
|
User and Permissions
|
Creates a new user (typically managed at the OS level). |
|
Grants privileges to a user or role. Example:
|
|
Revokes privileges from a user or role. Example:
|
Data Types
Common Data Types
|
Stores integer values. Example:
|
|
Stores small integer values. Example:
|
|
Stores large integer values. Example:
|
|
Stores exact numeric values with precision Example:
|
|
Stores single-precision floating-point numbers. Example:
|
|
Stores double-precision floating-point numbers. Example:
|
|
Stores variable-length character strings with a maximum length of Example:
|
|
Stores fixed-length character strings with a length of Example:
|
|
Stores dates. Example:
|
|
Stores times. Example:
|
|
Stores date and time values. Example:
|
|
Stores Binary Large Objects (BLOBs). Example:
|
|
Stores Character Large Objects (CLOBs). Example:
|