2

In SQL server I can use the USE statement to switch between working databases. Is there a similar command for DB2?

4

The concept of a "database" in SQL Server is much closer to a schema in DB2. An entire MS SQL database engine is much closer to a DB2 database:

master database <======> SYSIBM/SYSCAT schema
msdb   database <======> SYSPROC       schema

It's not a perfect comparison; there are a number of differences:

  • DB2 does not have an equivalent to the model database.
  • tempdb doesn't really map to a schema; its purpose is handled by system temporary tablespace(s) like TEMPSPACE1.
  • Each database in MS SQL has separate log files, where DB2 uses a single set of transaction logs for the entire database

Therefore, technically the closest equivalent to MS SQL's USE statement is SET SCHEMA. Issuing the SET SCHEMA x statement tells DB2 where to look for unqualified objects.

However, it's not a requirement to issue the SET SCHEMA statement if you fully qualify your object names. The following statements:

set schema x;
select c1, c2 from mytable;

are equivalent to:

select c1, c2 from x.mytable

Using set schema simply allows you to use unqualified objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.