Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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