USE statement
- Last UpdatedSep 29, 2022
- 1 minute read
- PI System
- PI OLEDB Enterprise 2019
- Developer
The statement dynamically sets the default Catalog (PI AF database). It overwrites the Initial Catalog initialization property.
Syntax
USE database_name
Remarks
Because Catalog names are custom, the statement allows generalizing queries and making them portable to other systems or allows queries being used with different Catalogs (AF databases).
For example, the statement:
SELECT et.Name ElementTemplate
FROM NuGreen.Asset.Category c
INNER JOIN NuGreen.Asset.ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN NuGreen.Asset.ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'
can be shortened to:
SELECT et.Name ElementTemplate
FROM Asset.Category c
INNER JOIN Asset.ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN Asset.ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'
and because Asset is the default schema it can be even shorter:
SELECT et.Name ElementTemplate
FROM Category c
INNER JOIN ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'