Partager via


USE SCHEMA (U-SQL)

Summary

In order to simplify using names of objects in other schemas than the default context schema in a script, U-SQL provides the ability to set a different schema as the context schema with the USE SCHEMA statement.

The statement sets the specified schema as the new context schema (within the existing context database) for all metadata object names in the remainder of the script until it gets changed with another USE statement. All names that are not fully qualified will be resolved with respect to the new context.

Syntax

Use_Schema_Statement :=                                                                                  
     'USE' 'SCHEMA' Schema_Name.
Schema_Name := Quoted_or_Unquoted_Identifier.

Remarks

  • Schema_Name
    Specifies the name of the schema in form of a quoted or unquoted U-SQL identifier. If the schema does not exist in the current database context or the user has no permissions to at least enumerate the schema, an error is raised.

Examples

  • 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 schema My Schema within the current database context will allow the subsequent SELECT and DROP statements to operate on a table SampleTable within the My Schema schema.

USE SCHEMA [My Schema];  
@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 two-parts names to refer to the table in the current database context without setting the schema context:

@r = 
    SELECT * FROM [My Schema].SampleTable;  
    DROP TABLE [My Schema].SampleTable;  
    OUTPUT @r TO "output.txt" USING Outputters.Csv();  

See Also