USE DATABASE (U-SQL)
In order to simplify using names of objects in other databases than the default context database, U-SQL provides the ability to set a different database as the context database with the USE DATABASE statement. This sets the specified database as the new context database for all metadata object names in the remainder of the script until it gets changed with another USE
statement. It also automatically sets the schema context to the database’s dbo schema. Therefore all names that are not fully qualified will be resolved with respect to the new context.
Use_Database_Statement := 'USE' ['DATABASE'] DB_Name.
DB_Name := Quoted_or_Unquoted_Identifier.
The keyword DATABASE
is optional to provide familiarity to T-SQL users.
DB_Name
Specifies the name of the database in form of a quoted or unquoted U-SQL identifier. If the database does not exist or the user has no permissions to at least enumerate the database, an error is raised.
- The examples can be executed in Visual Studio with the Azure Data Lake Tools plug-in.
- The scripts can be executed locally. An Azure subscription and Azure Data Lake Analytics account is not needed when executed locally.
The following script shows how using a database, TestReferenceDB
, will allow the subsequent SELECT
and DROP TABLE
statements to operate on a table, SampleTable
, within the TestReferenceDB's
default schema context.
USE DATABASE TestReferenceDB;
@r =
SELECT * FROM SampleTable;
DROP TABLE SampleTable;
OUTPUT @r TO "output.txt" USING Outputters.Csv();
This script is equivalent to the following script that uses fully qualified names without setting the database context:
@r =
SELECT * FROM TestReferenceDB.dbo.SampleTable;
DROP TABLE TestReferenceDB.dbo.SampleTable;
OUTPUT @r TO "output.txt" USING Outputters.Csv();