InterSystems 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.
InterSystems TSQL also contains a few proprietary extensions not found in either of these implementations. These are described in the Commands
Regardless of which Caché interface is used, TSQL code is used to generated corresponding Caché SQL executable code. Caché does not provide system-level support for native TSQL.
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 for InterSystems Caché™.
To migrate existing TSQL applications to InterSystems TSQL, you need to perform three operations: configure Caché for TSQL, migrate the TSQL source code, and migrate the data.
To configure your system for TSQL:
The initial application migration is simple:
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.
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.
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:
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()
Create a class method stored procedure and enter the language as tsql. You can use the following template as a starting point:
ClassMethod MyTestMethod() As %Integer
[ Language = tsql, ReturnResultSets, SqlName=name, SqlProc ]
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.
TSQL procedures are converted to Caché methods or queries with a Language
type equal to TSQL
. Use the following command:
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.
Caché Dynamic SQL can be used to execute TSQL code queries and a limited subset of other DML and DDL statements.
You can create a Dynamic SQL statement class instance, then set the %Dialect property
to Sybase or MSSQL. You then prepare and execute a TSQL command within that object instance.
You can execute Dynamic SQL without creating a statement class instance by invoking the %SYSTEM.SQL.Execute()
method, which both prepares and executes an SQL command. This method provides a Dialect
When entering SQL code interactively, the TSQL Shell supports, but does not require, the semicolon (;) statement delimiter at the end of each SQL statement.
The InterSystems SQL Shell can be used to execute lines of TSQL code by using the SET DIALECT
command to set the Shell’s dialect to Sybase or MSSQL.
When the Shell’s dialect is set to Sybase or MSSQL, the SQL Shell supports, but does not require, the semicolon (;) statement delimiter at the end of each SQL statement. When the Shell’s dialect is set to Cache, a semicolon (;) statement delimiter results in an SQLCODE -25 error.
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. You can use the Language=tsql
class definition keyword to specify that a trigger is written in TSQL. The UpdateColumnList
class definition keyword is only supported for TSQL. Row-level triggers are not supported for TSQL. See Using Triggers
in the Using Caché SQL
© 1997-2019 InterSystems Corporation, Cambridge, MA