Skip to main content

This version of the product is no longer supported, and this documentation is no longer updated regularly. See the latest version of this content.Opens in a new tab

Overview

Caché TSQL is an implementation of Transact-SQL which supports many of the features of both the Microsoft and Sybase implementations. Transact-SQL is used with Microsoft SQL Server (MSSQL) and Sybase Adaptive Server.

Caché TSQL also contains a few proprietary extensions not found in either of these implementations. These are described in the Commands chapter.

This document will help you to quickly migrate schemas and stored procedures from Microsoft or Sybase databases and it will provide you with an understanding of the TSQL (Transact-SQL) implementation in Caché.

Getting Started

To migrate existing TSQL applications to Caché TSQL, you need to perform three operations: configure Caché for TSQL, migrate the TSQL source code, and migrate the data.

Configuring TSQL

To configure your system for TSQL:

  • Go into the Caché Management Portal. Select System Administration, Configuration, SQL and Object Settings, then select TSQL Compatibility Settings. Here you can specify the dialect (Sybase or MSSQL), and turn on or off the ANSI_NULLS, CASEINSCOMPARE, and QUOTED_IDENTIFIER settings. The default for all three is “off”. These values are used to set the ^%SYS(“tsql”,”SET”,...) global array values.

  • From the Management Portal, select System Administration, Configuration, SQL and Object Settings, then General SQL Settings. From here, you can set the Default SQL Schema Name. This is the system-wide default schema name (which maps to a package) for all unqualified DDL entities.

  • From the Management Portal, select System Administration, Configuration, SQL and Object Settings, then User-defined DDL Mappings. You can use this option to map any needed user-defined data types.

Migrating Source Code

The initial application migration is simple:

  1. Migrate the DDL: Import table and view definitions using either the %SYSTEM.SQL.DDLImport()Opens in a new tab method (for single files) or the %SYSTEM.SQL.DDLImportDir()Opens in a new tab method (for multiple files in a directory). Set the DDLMode parameter to either "MSSQLServer" or "Sybase". For further details, see the InterSystems Class Reference.

    Alternatively, you can invoke $SYSTEM.SQL.TSQL()Opens in a new tab, $SYSTEM.SQL.Sybase()Opens in a new tab or $SYSTEM.SQL.MSSQLServer()Opens in a new tab method to import the schema. For further details, see the InterSystems Class Reference.

    If the TSQL source contains CREATE PROC statements, then a class method containing the CREATE PROC source is created. Caché places this class method in either an existing class or in a new class whose name is based on the schema and procedure name. If the procedure already exists, then the existing version is replaced by the new version. If a class matching the class name generated from the schema and procedure already exists, then this class name is used — if it was previously generated by the TSQL utility. If not, then a unique class name is generated, based on the schema and procedure name. The resulting class is compiled once the procedure has been successfully created. If logging is requested then the source statements are logged along with the name of the containing class, class method, and the formal arguments generated. Any errors encountered by the process are also reported in the log. If an error is detected during CREATE PROC processing, Caché deletes any new class that was generated for that procedure.

  2. Inspect the log file for errors: Search by Error #. A summary count of errors and successful imports will appear at the end of the log. In most cases, errors can be worked around or addressed by using information found in this document.

  3. Compile: When you import DDL, table and view definition compilation is automatically performed. To compile other TSQL source code, it is best to use the command as follows:

      DO $SYSTEM.OBJ.CompileAll("-l")

    The lowercase “L” qualifier flag specifies that locking is not applied for the duration of the compile. For a full list of flag qualifiers, call DO $SYSTEM.OBJ.ShowFlags().

Migrating the Data

In the Management Portal select System Explorer, SQL, then select the Data Migration Wizard.

TSQL Language Implementation

TSQL procedures are converted to Caché methods or queries with a Language type equal to TSQL. Use the following command:

DO ##class(%TSQL.Manager).load("sybase",<filename>,<logname>)

When compiling TSQL methods, ObjectScript code is generated. There is no system-level support for native TSQL. It is best to maintain the methods in TSQL to retain the familiar look of the original stored procedures.

  • Using TSQL in Studio

    You can write and maintain TSQL stored procedures (SPs) in Studio. A TSQL SP can be either a class method or a query. A class method takes parameters and returns a single scalar result, a query takes parameters and returns rows. If you put plain SELECT statements into a class method they will be executed but you won't be able to get the rows.

  • Writing a TSQL class method

    Create a class method stored procedure and enter the language as tsql. You can use the following template as a starting point:

    ClassMethod Example() As %Integer 
       [ Language = tsql, ReturnResultSets, SqlName=name, SqlProc ]
    {
    }
    
  • Using the TSQL Shell

    A TSQL interpreter shell is useful for debugging and experimentation. See “Using the TSQL Shell” for more information.

  • Using the Caché SQL Shell

    The Caché SQL Shell can be used to execute lines of TSQL code by setting the DIALECT parameter to Sybase or MSSQL. You can execute a TSQL script file from the Caché SQL Shell by using the Shell’s RUN command, See “Using the SQL Shell Interface” in the Using Caché SQL manual.

  • Using Dynamic SQL

    Caché Dynamic SQL can be used to execute TSQL code queries and a limited subset of other DML and DDL statements. In Dynamic SQL you set the %Dialect property to Sybase or MSSQL. See “Using Dynamic SQL” in the Using Caché SQL manual.

  • Using Triggers

    You can write and maintain triggers, which are sets of instructions that appear in TSQL code and that are executed in response to certain SQL events. See “Using Triggers” in the Using Caché SQL manual.

  • TSQL Language Reference

    Microsoft has good TSQL reference material at:

    http://msdn.microsoft.com/en-us/library/bb545450.aspxOpens in a new tab

FeedbackOpens in a new tab