Sybase Migracion A db2
Sybase Migracion A db2
Table of Contents
INTRODUCTION......................................................................................................................................................................1
ADMINISTRATION ISSUES.................................................................................................................................................11
ENVIRONMENTS ......................................................................................................................................................................11
DATABASE DEVICES ...............................................................................................................................................................11
LOG FILES ...............................................................................................................................................................................12
DATABASE SECURITY .............................................................................................................................................................12
DUMP/LOAD ...........................................................................................................................................................................13
JOBS........................................................................................................................................................................................14
SYSTEM STORED PROCEDURES ...............................................................................................................................................14
IMPLEMENTATION DIFFERENCES.................................................................................................................................14
ISOLATION LEVELS .................................................................................................................................................................15
LOCKING MECHANISMS ..........................................................................................................................................................15
SYSTEM DATABASES ..............................................................................................................................................................15
SQL........................................................................................................................................................................................16
TABLES ...................................................................................................................................................................................16
TEMPORARY TABLES ..............................................................................................................................................................17
INDEXES .................................................................................................................................................................................17
IDENTITY COLUMNS ............................................................................................................................................................17
CONSTRAINTS .........................................................................................................................................................................17
SCROLLABLE CURSORS ...........................................................................................................................................................18
ANSI JOIN OPERATORS ..........................................................................................................................................................18
TRANSACTIONS .......................................................................................................................................................................18
TRIGGERS ...............................................................................................................................................................................18
STORED PROCEDURES.............................................................................................................................................................19
GLOBAL VARIABLES ...............................................................................................................................................................19
PROGRAMMING INTERFACES.........................................................................................................................................20
EMBEDDED SQL.....................................................................................................................................................................21
OPEN CLIENT AND OPEN SERVER LIBRARIES ..........................................................................................................................21
TERMINOLOGY MAP ..........................................................................................................................................................22
CONVERSION TOOLS..........................................................................................................................................................23
SQL CONVERSION WORKBENCH (SQL-CW) .........................................................................................................................23
DATA JUNCTION......................................................................................................................................................................23
PLATINUM ERWIN...............................................................................................................................................................24
RESOURCES AND REFERENCES ......................................................................................................................................25
TRADEMARKS.......................................................................................................................................................................26
Introduction
DB2® Universal Database (DB2 UDB) can help improve the performance of database applications. Many
solution developers have already chosen DB2 UDB as their primary development database environment,
and have ported and continue to enable applications to it to take advantage of its unique features.
DB2 UDB is a true cross-platform DBMS, running on a wide variety of systems including Windows NT and
95, Solaris, HP-UX, AIX®, SCO UnixWare and OS/2®. It scales from single-processor workstations or
servers, to symmetrical multiprocessor (SMP) servers, and on up to massively parallel processing (MPP)
computers.
A real database leader in several technologies, it provides integrated support for complex data such as
text documents; images; video and audio clips; integrated Web access through native support for Java,
JDBC, SQLJ and Net.Data; integrated system management tools; and data replication service.
This paper introduces DB2 Universal products and their capabilities, discusses porting databases and
applications and describes the most important aspects of porting applications from Sybase Adaptive
Server to DB2 UDB. It also describes the differences in database options, data definition language (DDL),
data model, SQL considerations, data conversion and application conversion.
Note: All information contained in this document is based on publicly available information as of October 5,
1998 and is subject to change. IBM® disclaims all warranties as to the accuracy, completeness, or
adequacy of such information. IBM shall have no liability for errors, omissions or inadequacies in the
information contained herein or for interpretations thereof.
On December 1, 1998, the IBM Personal Systems Group and the IBM Software Group published a 100GB
TPC-D benchmark (Transaction Processing Performance Council Benchmark D) using DB2 UDB 5.2.0
under Windows NT on an IBM Netfinity 7000 M10 server with four Pentium II Xeon 400 MHz processors.
This benchmark achieved a multi-user throughput result of 831.2 QthD@100GB, a price/performance
result of $130/QphD@100GB, and a power result of 3450 QppD@100GB. It has also since been
published by TPC (For more details, see the section “Resources and References” on page 25).
In addition to affordability and performance, DB2 UDB offers the following advantages:
• Journal, to view all available information in the history and alter a message in the log files about
jobs that are pending, being executed or completed. It can also be used to review the results of
unattended jobs.
• Alert Center, to monitor the system for early warnings of potential problems or to automate
actions to correct problems that are discovered.
• DB2 Performance Monitor, to monitor the performance of a DB2 system and to create
snapshots of data over a period of time or data for a particular event, which can be used to
monitor activities.
• Visual Explain, to graphically analyze and tune SQL statements, as well as analyze query access
plans.
• SmartGuides, to help perform administration tasks. For example, a SmartGuide is available to
help tune the performance of the database server.
• The Web Control Center, the Java version of the DB2 UDB Control Center. The Web Control
Center is implemented as a Java applet that uses DB2 JDBC support. Currently, the Web Control
Center requires Netscape Navigator 4.04 for Windows 95 or Windows NT, and the JDK 1.1.4
patch for Navigator 4.04.
Data Replication
DB2 UDB includes a complete data replication solution by supporting sources and targets that include the
DB2 family, IMS, VSAM, Oracle, Sybase, Microsoft, Lotus Notes, and others to ensure timely, reliable, and
consistent data across an enterprise. IBM offers the following data replication tools:
• IBM Replication – the DataPropagator® Relational Version 1 (DPROPR V1) products have been
updated for Version 5 (V5) of the DB2 database.
• DB2 Universal Database V5 replication tools – the Control Center replication administration
features and the Capture and Apply programs.
• IBM Capture and Apply for MVS V5.1
• Capture for VSE and VM V5.1 – integrated with IBM DB2 Server for VSE and VM V5.1.
• DPROPR V1 for support of DataJoiner
• DataPropagator Relational Capture and Apply for OS/400 V3.1
• IBM DataPropagator NonRelational
• IBM DataJoiner®
• Lotus NotesPump
JDBC can be used to create applications or applets that access data in DB2 databases. These applets
can be run inside HTML web pages on any system with a Java-enabled browser, independent of the
client’s platform. The processing of JDBC applets is shared between the client and the server.
DB2 SQLJ support facilitates the creation, building and running of SQLJ programs against DB2 UDB
databases.
DB2 Net.Data enables application developers to create Internet applications that access data from DB2
databases, are stored on a web server and are viewable from any web browser. While viewing these
documents, users can either select automated queries or define new ones that retrieve the specified
information directly from a DB2 UDB database.
Each extender defines a new type of data in DB2 UDB by using built-in support for user-defined types and
user-defined functions. Each extender also exploits DB2 Version 5 support for large objects of up to 2
gigabytes, and uses DB2 triggers to ensure referential integrity of image data.
The DB2 Extenders exploit the DB2 client/server model. Supported platforms are AIX, OS/2, Windows
NT, HP-UX and Solaris Operating Environment.
• Hardware and software discounts, equipment lease and loaner programs and business discounts
to reduce development costs
• On-site and remote access to fully equipped testing and porting facilities at full-service IBM
Solution Partnership Center (SPC) locations around the world
• Exclusive, focused development support
• Examples of how to interface with and exploit the newest technologies
• Technical information based on actual development experience in the form of “Frequently Asked
Questions” and “Hints And Tips”
• The IBM Developer Connection, which is loaded with development tools, software and late-
breaking news from IBM
• The Global Software Solutions Guide, an online catalog providing worldwide exposure to new
customers for partners' solutions
• In-depth technical seminars and hands-on workshops
• Partners In Development specialty areas, with specialized technical, business, marketing and
information services for areas of expertise
• A technical library, complete with the latest white papers, road maps and a calendar of upcoming
events
• The IBM Solution Developer Program worldwide web site, http://www.developer.ibm.com/, which
is a dynamic, 24-hour, 7-day-a-week service that provides information about all services.
DB2 UDB version 5.2 database software servers run on the following software environments: AIX, HP-UX,
OS/2, SCO UnixWare, SINIX, Linux, Sun Solaris, Windows NT, Windows 98 and Windows 95.
Client access is provided for all these platforms, as well as for DOS, Apple MacOS, and Silicon Graphics
IRIX. In addition, web access is provided with popular browsers and Java applications using DB2's native
Java/JDBC support and Net.Data.
The DB2 SDK can be used to develop applications that use the following interfaces:
DB2 SDK supports several programming languages (including COBOL, FORTRAN, Java, C, and C++) for
application development, and provides precompilers for the supported languages. It is available on all DB2
UDB-supported platforms. The same application does not require any source changes to run against DB2
UDB on any Intel or UNIX platform; therefore, only one base code allows support for several platforms.
DB2 SDK also supports SQLJ. Along with DB2 JDBC support provided by the DB2 Client Application
Enabler (DB2 CAE), DB2 SQLJ support allows for the creation, build, and run of embedded SQL for Java
applications, applets, stored procedures and user-defined functions (UDFs). These contain static SQL and
use embedded SQL statements that are bound to a DB2 database.
• DB2® Connect Personal Edition, which provides access from a single workstation to DB2
databases residing on host systems such as MVS/ESA, OS/390, OS/400, VM and VSE, as well
as access to DB2 Universal Databases. This product is available for the OS/2, Windows 3.1x,
Windows NT, and Windows 95 operating systems. DB2 Connect Enterprise Edition provides
similar capabilities in a multi-user environment including UNIX systems, OS/2, and Windows NT.
• DB2® OLAP (online analytical processing) Server, which is designed for multidimensional
planning, analysis, and reporting applications.
• DB2 for Domino, which extends the capabilities of DB2 Universal Database to Lotus Notes and
Domino users.
• DB2 DataJoiner 2.1.1, which provides a single interface to heterogeneous databases. It provides
global query optimization, and supports most relational and non-relational database systems.
Note: Some DB2 UDB datatypes not available in Sybase have been included on the table.
1
float(p) storage is 4 bytes if p < 8; 8 bytes if 8 < p < 16.
2
datetime values are accurate to 1/300 of a second on platforms that support this level of granularity. Storage size is 8
bytes: 4 bytes for the number of days since the base date of January 1, 1900 and 4 bytes for the time of day.
3
smalldatetime values are accurate to the minute. Storage size is 4 bytes: 2 bytes for the number of days since January 1,
1900 and 2 bytes for the number of minutes since midnight
4
timestamp is a Sybase SQL Server-supplied, user-defined datatype that is defined as varbinary(8) NULL. Used in tables
that are to be browsed in Client-Library applications (see "Browse Mode" for more information). SQL Server automatically
updates the timestamp column each time its row is modified. A table can have only one column of timestamp datatype.
5
allows national character set, where 1 character uses > 1 byte
6
0 until initialized, a page is 2K.
7
DB2 UDB time stamp format is YYYY-MM-DD-HH-MM-SS-NNNNNN (year-month-day-hour-minutes-seconds-
microseconds).
8
date is a three-part value, YYYY-MM-DD (year, month, and day), where year = 0001 to 9999, month = 1 to 12, and day =
1 to 31.
9
time is a three-part value, HH:MM:SS (hour, minute, and second), designating a time of day under a 24-hour clock.
10
Special restrictions apply to an expression resulting in a varying-length string data type whose maximum length is greater
than 254 bytes. Such expressions are not permitted in: a SELECT DISTINCT statement's SELECT list, a GROUP BY
clause, an ORDER BY clause, a column function with DISTINCT and a subselect of a set operator other than UNION
ALL.
11
FOR BIT DATA specifies that the contents of the column are to be treated as bit (binary) data. During data transfer with
other systems, code page conversions are not performed. Comparisons are done in binary, irrespective of the database
collating sequence.
Administration Issues
This section compares the administrative features available in Sybase Adaptive Server version 11.5 and
DB2 UDB version 5.2.
Environments
In Sybase, several SQL servers can be created to define different environments. Sybase has a separate
server process for Backup.
DB2 UDB uses instances to provide separate environments within the same machine. Other instances
can also be used to restrict access to sensitive information or to limit the impact of instance unavailability.
However, multiple instances require additional system resources (memory and disk space) and more
administration. Backups are performed by a special instance called the administration server instance.
Database Devices
Sybase SQL Server uses database devices to store data for a Database. DB2 UDB stores data on table
spaces (Figure 3). A table space can be either a system managed space (SMS) or a database managed
space (DMS). For an SMS tablespace, each container is a directory within the operating system, and the
operating system's file manager controls the allocation of storage space. For a DMS tablespace, each
container is either a fixed-size pre-allocated file or a physical device such as a disk, and DB2 UDB
controls the storage space. A container is a physical storage device (directory, file, or device).
DB2 UDB has three table space types: regular, temporary and long. Regular table spaces are used for
tables, indexes, and system catalog tables. Temporary table spaces are used during SQL operations that
required disk space, such as sorting or reorganizing tables, creating indexes and joining tables. Long table
spaces are used to store Large Object Data (LOB).
A single table space may consist of several containers. A database can use different table spaces for
indexes, tables and LOBs. The create table command is used to associate a table to a tablespace. It is
recommended that users allocate a container for each physical disk to enable I/O parallelism.
Log Files
Sybase log data is recorded on the database device or on a separate log device. DB2 UDB databases
have log files (devices) associated with them; table spaces are not used for log data. These logs record all
database changes. Active logs are used during crash recovery to prevent a failure (such as a system
power failure or an application error) from leaving a database in an inconsistent state. After a failure, the
following actions are taken to ensure the integrity of the database: changes already made but
uncommitted are removed from the database (rolled back), and all committed units of work, which may
not have been physically written to disk, are redone.
Circular and archive logging are two recovery methods available in DB2 UDB. Circular logging is the
default. It uses a number of online logs for crash recovery. Only full database off-line backups are valid for
recovery, and roll forward from the last backup is not allowed. The other type of recovery, archive logging,
enables forward recovery using active and archived logs to any point in time before the failure. A database
can be rolled forward after a full database backup has been restored up to the last completed transaction.
Once archive logging is enabled, online database backups can be performed.
Database Security
Sybase authentication is controlled by users, logins and groups, which are objects defined in the SQL
Server. DB2 UDB authentication of a user is completed using an external security facility such as the
native operating system security or distributed computing environment (DCE). A user must have a valid
login system name in order to gain access to a database.
Sybase authorization is defined by means of roles and privileges. The roles are as follows: SA, SSO and
OPER. Additionally, each database has a special user called database owner (dbo).
DB2 UDB authorization (Figure 4) is defined by means of a system of authorities and privileges. Each
authority has a group name assigned that can be managed using the operating system facility. Four
authorities are available: system administration, system control, system maintenance and database
administration. Sybase roles can be mapped to DB2 authorities, and assigned to users by becoming a
member of the group with the proper authority.
Sybase uses permissions to restrict access to objects and commands based on a user's identity or group
membership. The commands grant and revoke are used to give users permission to create databases
and objects within a database, as well as access specified tables, views and columns.
In DB2 UDB, privileges enable users to create or access database resources. The following types of
object privileges exist: database, schema, table, view, package, and index. Most of Sybase permissions
can be mapped to privileges such as create table, create database, create view, and all object
permissions. DB2 UDB has privileges not available in Sybase, such as package and schema privileges.
Sybase stored procedure privileges can be mapped to DB2 UDB package privileges.
Sybase has a special system administrator user (SA) who is responsible for administrative tasks to setup
and maintain the Server. In DB2, the System Administration (SYSADM) authority is the highest level of
authority within the database manager, and controls all database objects. This parameter defines the
group name with SYSADM authority for the database. In UNIX, the initial value is null and defaults to the
primary group of the instance owner. In Windows NT, the value defaults to the Administrator Group.
Following installation, a different group name can be assigned to SYSADM within DB2 UDB.
Dump/Load
The dump/load commands on Sybase are limited to databases and transaction logs only. The dump
command can be executed while the database is active. It does not reflect any data changes made to the
database after the command begins. It supports point-in-time recovery and maintains a history of
database backups.
DB2 UDB backup/restore procedures can be performed on databases and tablespaces. Online backups
can be performed when archived logging is enabled. Point-in-time recovery is available. When recovering
from a system failure, the time specified should a time prior to the system failure.
Jobs
Sybase allows suspended execution through the waitfor command in stored procedures and triggers. DB2
UDB offers a graphical user interface called Script Center to schedule a script to run at a later date or at a
regular interval. This is particularly useful for scheduling administrative tasks such as making backups.
DB2 UDB provides APIs for performing administration tasks such as creating, activating, backing up or
restoring a database. These APIs can also be invoked from DB2 SQL applications.
Sybase Central is the new graphical user interface (available on version 11.5) for managing Sybase
products. Sybase Central runs on Windows 95 or Windows NT 4.0.
DB2 UDB provides the Control Center, which is a graphical interface for OS/2, Windows 95, or Windows
NT, to manage a local database server or multiple remote database servers and the database objects
within.
From the Control Center, the following tasks can be performed on database objects:
DB2 UDB SmartGuides are also available on OS/2, Windows 95 or Windows NT as an aid to performing
common administration tasks. SmartGuides are available for adding or creating a database, creating
tables, creating tablespaces, backing up and restoring databases, configuring performance and tuning
parameters.
Implementation Differences
This section compares implementation features available in Sybase Adaptive Server version 11.5 and
DB2 UDB version 5.2.
Isolation Levels
Sybase supports four isolation levels that are defined by numbers. Level 0 prevents other transactions
from changing data already modified, while other transactions can still read the uncommitted data ("dirty
reads"). Level 1, the default level, prevents dirty reads. Level 2 prevents non-repeatable reads and Level 3
prevents phantoms.
DB2 isolation levels refer to locking data in row units (occurs at the base table row). The DB2 UDB
supports four isolation levels: Read Stability, Repeatable Read, Cursor Stability, and Uncommitted Read.
Regardless of the isolation level, the database manager places exclusive locks on every row that is
inserted, updated, or deleted. Thus, all isolation levels ensure that any row that is changed by this
application process during a unit of work is not changed by any other application processes until the unit of
work is complete.
Sybase DB2 UDB
0 Uncommitted Read
1 (default) Cursor Stability (default)
2 Read Stability
3 Repeatable Read
Locking Mechanisms
Sybase has two levels of locking: page locks and table locks (row level locking is an option only in version
11.9). Lock promotion is controlled by the configuration parameter lock promotion and the system-stored
procedure sp_setpglockpromote to define the number of page locks that SQL Server acquires on a table
before it attempts to escalate to a table lock on a server-wide, per database and per table basis. In
previous versions, the number of page locks setting is 200 and could not be configured.
DB2 UDB employs row-level locking by default (page-level locking is not an option). The database
manager, however, can escalate a lock to the table level. DB2 UDB lock escalation can be influenced by
modifying the value of the maxlocks and/or the locklist parameters in the database configuration file.
System Databases
The master database controls the operation of the SQL Server as a whole and stores information about all
user databases and their associated database devices. DB2 UDB has a catalog table space
SYSCATSPACE, which contains all the system catalog tables for a single database. All other aspects of
database configuration can be controlled by the DB2 command interface or the Control Center. The
operating system security facility should be used to manage user accounts.
Sybase system procedures are stored in the database sybsystemprocs. The tasks automated by these
procedures can be performed using the DB2 UDB graphical interface Control Center to administer local
and remote databases or DB2 API’s (See section “System Stored Procedures” on page 14).
Sybase model database provides a template, or prototype, for new user databases. Typically, changes
made to the model database are adding user-defined datatypes, rules or defaults; adding users who
should have access to all databases; and granting default privileges, particularly for guest accounts. DB2
UDB does not require a model database: a script can be written to create a database, define datatypes
and grant privileges. Users that are already created can have access to all databases by use of group
membership or trusted connections.
Sybase temporary database tempdb provides a storage area for temporary tables and other temporary
working storage needs such as intermediate results of group by and order by. In DB2 UDB, each
database has one or more temporary table spaces for such purposes. Having a table space instead of a
database provides the following advantages: applications running on different databases use different
table spaces (storage areas) and system managed space (SMS) table spaces need very little
administration (limited by file system free space).
Sybase provides sample databases pubs2 and pubs3, which can be optionally installed. DB2 UDB
provides a sample database called Sample, along with the API db2sampl to create this database. It also
provides First Steps, a graphic tool for Intel platforms that helps with creating and manipulating the
Sample database. The product documentation and sample programs refer to this database.
SQL
Sybase is compliant with the SQL92 Entry level. This complaint behavior is set by default for embedded
applications. The command set in Transact-SQL can be used to change it. Also to be compliant with the
entry-level SQL92, identifiers must not exceed 18 characters, begin with a pound sign (#) or contain
lowercase letters. Sybase Transact-SQL extensions allows ‘#’, lower case letters and 30-character
identifiers.
DB2 UDB is also compliant with the SQL92 Entry level, but includes features from the Intermediate and
Full levels, as well as the future SQL3. Identifiers cannot exceed 18 characters in length; however, the
SQL3 standard for allowing identifiers with 128 characters length is not yet implemented.
Tables
The following table summarizes the different limitations for tables between Sybase and DB2 UDB:
Temporary Tables
Sybase supports local and global temporary tables. DB2 UDB does not currently support temporary
tables, but they can be implemented with DB2 UDB common table expressions or with the not logged
initially clause on the create table and alter table commands to provide temporary table characteristics.
Indexes
In Sybase, indexes are all created in ascending order: no clause exists in the command create index to
specify ordering. In version 11.9, the create index command has been modified to allow ordering
specification. In DB2 UDB, indexes can be defined in ascending or descending order. Bi-directional
indexes are not currently supported. The ordering property can be useful in executing queries with order
by and group by clauses.
Sybase uses a B-tree model to represent the cluster index in a sparse index (not every row has an index
entry). DB2 UDB creates indexes on a separate structure that replicate the key values. The cluster factor
of a clustering index is maintained or improved dynamically as data is inserted into the associated table by
attempting to insert new rows physically close to the rows for which the key values of this index are in the
same range. In both databases, only one clustered index per table is permitted.
Sybase has a fillfactor clause on create index to specify a percentage value as to how full SQL Server will
make each page when it is creating a new index on existing data. The default is 0 which completely fills
the pages. DB2 UDB has a pctfree clause on the create index command to specify the percentage of free
space. The default is 10%. This clause is for performance only since the index will continue to work with
slightly degraded performance.
IDENTITY Columns
Sybase SQL Server supports the IDENTITY constraint on numeric columns with a scale of 0. IDENTITY
columns start with 1 and increment by 1. DB2 UDB does not currently support this type of constraint, but
allows it to be implemented by using a combination of triggers and user-defined functions (UDFs), or by
using the generate_unique() function.
Constraints
Sybase allows the creation of defaults and rules for columns in a database to define default and check
constraints. Rules cannot be defined for an SQL Server-supplied datatype or to a column of type text,
image, or timestamp. In DB2 UDB, check and default constraints are defined only in the commands create
table and alter table at the column or table level. There are no restriction on data types.
Sybase integrity constraint definitions can indicate whether the index to be created is nonclustered
(default) or clustered. DB2 UDB creates a unique index, using ascending order for every column in the
key; if a cluster index is required, the command reorganize table, specifies an index, then uses that index
to physically reorder the records in the table.
Sybase referential constraints cannot cascade changes through related tables in the database. Triggers
must be used for this purpose. DB2 UDB referential constraint definitions have a rule clause to specify
what action to take on dependent tables. The delete rule has four possible actions : NO ACTION (default),
RESTRICT, CASCADE, and SET NULL. If RESTRICT or NO ACTION is specified, an error occurs and no
rows are affected. If CASCADE is specified, the operation is propagated to all the dependents rows. If
SET NULL is specified, each nullable column of the foreign key of each dependent row is set to null. NO
ACTION and RESTRICT are the only possible actions on update.
Scrollable Cursors
Sybase does not support scrollable cursors. DB2 Call Level Interface (CLI) supports read-only scrollable
cursors to navigate forward, backward, or to an absolute position within the result set. This feature can be
very useful in GUI applications for displaying information in scroll boxes.
Transactions
Sybase defines a transaction by enclosing SQL statements and/or system procedures within the phrases
begin transaction, savepoint and commit. Savepoint provides a mechanism for selectively rolling back
portions of a batch. If chained transaction mode is enabled, SQL Server implicitly invokes a begin
transaction before the following statements: delete, insert, open, fetch, select, and update. A commit must
still explicitly close the transaction.
DB2 UDB Compound SQL (begin compound) allows you to group several SQL statements into a single
executable block. No savepoint mechanism is provided. Two types of compound SQL are available:
• Atomic – returns a response when all sub-statements have been executed successfully or when
one of them ends in an error. When an error occurs, the entire block is rolled back.
• Not Atomic – returns a response when all sub-statements have been executed, regardless of
whether or not a preceding sub-statement failed. The entire block is rolled back only when the unit
of work that contains it is rolled back.
Compound SQL is supported through embedded static SQL and the DB2 Call Level Interface.
Triggers
Sybase Triggers are coded using Transact-SQL and stored in the database. SQL Server allows nested
triggers by default.
DB2 UDB triggers are also stored in the database, and are compiled at runtime with the SQL statement
associated with the trigger. Multiple triggers can be created for the same event, activation time and subject
tables. The first trigger that is created is the first to be executed. A triggered action is composed of one or
more SQL statements or by an optional condition for the execution of the SQL statements. The maximum
depth of cascaded triggers is 16. Adding a trigger to a table that already has rows in it will not cause any
triggered actions to be activated.
DB2 UDB triggers provide referencing: correlation names are specified for the transition variables, and
table names for the transition tables. Correlation names identify a specific row in the set of rows affected
by the triggering SQL operation, while table names identify the complete set of affected rows. Each row or
set of rows affected by the triggering SQL operation is available to the triggered action by qualifying
columns with correlation names and table names. The MS SQL Server if update (column) can be
converted to WHEN (old.column != new.column). DB2 UDB triggers cannot call stored procedures: if this
is required, it can be implemented by invoking UDFs from the trigger.
Stored Procedures
Sybase stored procedures are coded using Transact-SQL and stored in the database. The maximum
number of parameters in a stored procedure is 255.
DB2 UDB stored procedures (Figure 5) are compiled code libraries. DB2 does not provide a proprietary
4GL to program storedprocedures. 3GL languages, including C, C++, COBOL and Java, can be used to
code stored procedures using embedded static or dynamic SQL, CLI, or JDBC. Procedural logic can be
easily implemented in any of the programming languages to match Transact-SQL logic. The maximum
number of parameters is 32,767. Nested stored procedures are not currently supported.
Global Variables
Sybase provides global variables to report system or connection information. DB2 UDB uses special
registers such as CURRENT SERVER, CURRENT DATE, CURRENT TIME, and USER for that purpose.
Programming Interfaces
DB2 UDB provides the following programming interfaces to develop applications:
Embedded SQL
Embedded SQL uses SQL statements that are precompiled before a program is compiled. The SQL
statements can be static or dynamic.
Portability - DB2 CLI applications use a standard set of functions to pass SQL statements to the
database. It is only necessary to compile and link DB2 CLI applications before execution: no precompile or
bind is needed.
No binding - There is no need to bind individual DB2 CLI applications to each database they access; only
one binding is needed to the bind files that are shipped with DB2 CLI, for all DB2 CLI applications.
Array fetching and input - DB2 CLI functions can retrieve multiple rows in the database into an array
with a single call. An SQL statement can be executed many times, using an array of input variables.
Consistent interface to catalog - DB2 CLI provides a consistent interface among systems to query
catalog information about tables, columns, foreign and primary keys, and user privileges.
Extended data conversion - DB2 CLI automatically converts data between SQL and C data types.
No global data areas - DB2 CLI eliminates the need for application-controlled global data areas, such as
SQLDA and SQLCA. Instead, it automatically allocates and controls the necessary data structures, and
provides a handle to let an application reference them.
Retrieve result sets from stored procedures - DB2 CLI applications can retrieve multiple rows and
result sets generated from a stored procedure residing on the server.
Scrollable cursors - DB2 CLI supports server-side scrollable cursors that can be used in conjunction with
array output. Only read-only scrollable cursors can be declared.
Embedded SQL
Sybase provides precompilers for C and COBOL. DB2 UDB supports the C, C++, COBOL and FORTRAN
programming languages through its precompilers. It also supports the REXX language through a dynamic
interpreter, as well as the Java language.
Sybase uses the variables SQLCODE, SQLCA, and SQLSTATE to communicate between the SQL
Server and the application. When using DB2 UDB, the LANGLEVEL precompile option should be set to
SQL92E to declare SQLSTATE and SQLCODE fields explicitly as variables:
With a few exceptions, Sybase allows the use of all Transact-SQL statements, functions and control-of-
flow language in Embedded SQL. DB2 UDB SQL and Transact-SQL extensions are different; therefore,
some Transact-SQL statements are not valid in DB2 UDB.
In Sybase, statements can be used to associate the descriptor with a SQL statement and with the
appropriate cursor associated with the SQL statement (allocate descriptor, get descriptor, set descriptor).
The DB2 UDB describe command obtains information about a prepared SQL statement.
In Sybase, the connect statement is used to establish a connection between an application program and
SQL Server. The connect statement is also available in DB2 UDB, but the syntax is slightly different: a
database name specification is mandatory, but the user specification is optional.
Sybase offers two ways to group statements: ANSI/ISO SQL and Transact-SQL transaction mode.
Transact-SQL transaction mode provides a save transaction or begin transaction statement. DB2 UDB
employs the ANSI/ISO SQL transaction mode for all programming APIs. A transaction begins implicitly
with the first executable SQL statement and ends with either a commit or a rollback statement, or ends
when the program ends.
DB2 UDB CLI is a callable SQL interface that can be used to program client applications as well as server
applications. The same application does not require any source changes to run against DB2 UDB on any
Intel or UNIX platform; therefore, only one base code allows support for several platforms.
These programming interfaces are very different, but the effort of porting applications to DB2 can be
significantly reduced by using conversion tools (see “Conversion Tools” on page 23).
Terminology Map
The following table provides a list of basic DB2 UDB administration-related terms that are equivalent to
terms used by Sybase:
Conversion Tools
The most common approaches to converting a database applications are manual conversion, dynamic
call translation, and automated conversion. In general, conversion tools take in source code and translate
data management calls to an equivalent SQL call. Information from the source and target databases, as
well as program code, is used to build the new SQL statements. Some tools use an “expert” system to
make decisions over the generated SQL statements by cross-referencing the original and the new
databases.
• Provides metrics for the source database in order to estimate cost and effort
• Allows modifications to the design and data definition of the target database
• Generates DDL for the target database
• Unloads database data and creates load scripts
• Allows code re-engineering
• Generates procedural code for stored procedures and triggers
• Generates application code for DB-Lib, Client-Lib, and E-SQL applications
Data Junction
Data Junction offers a transformation tool for DB2 UDB data migration and application integration. It is a
visual design tool for building and testing data transformations that work between DB2 and other data
formats such as Microsoft SQL Server. Microsoft SQL Server is supported via a native API, a Massive
Insert API and the bcp command.
Projects and transformations designed with Data Junction can be executed by the DJEngine. This tool is
an engine that executes data transformations on demand or as scheduled. The graphic interface allows
the definition of source-to-target mapping and transformation rules. It accounts for data type differences,
and can set various filters to dynamically modify target columns during the conversion process.
PLATINUM ERwin
ERwin is a database design tool that aids in designing and maintaining database applications. A logical
model, along with business rules, defines the database, and a physical model represents the target
database. ERwin allows visualization of the structure, key elements and design of a database. It
automatically generates tables, stored procedures and trigger code for leading databases such as DB2
UDB and Microsoft SQL Server.
ERwin can also be used to reverse-engineer database objects using a DDL script or existing database.
The physical model allows users to select different target databases and generate DDL script for every
target. Using this feature, DDL scripts for different databases and versions can be easily supported.
For more information, contact PLATINUM Technologies Inc.
(http://www.platinum.com/products/ap_dev.htm).
Trademarks
The following terms are trademarks or registered trademarks of the IBM Corporation in the United States
and/or other countries:
AIX IMS
AIXwindows MVS/ESA
AS/400 MVS/XA
C Set++ OS/400
C/370 OS/390
DATABASE 2 OS/2
DataJoiner RISC System/6000
DataPropagator SQL/DS
DataRefresher SQL/400
DB2 S/370
DB2 Connect System/370
DB2 Universal Database System/390
DB2 OLAP Server VisualAge
Distributed Relational Database Architecture VM/ESA
DRDA VSE/ESA
IBM VTAM
WIN-OS/2
The following terms are trademarks or registered trademarks of the companies listed:
Microsoft, Windows, Windows NT, Windows 95 and the Windows 98 are trademarks or registered
trademarks of Microsoft Corporation.
Sybase, Adaptive Server, SQL Server, Transact-SQL, Open Client, and Open Server are trademarks of
Sybase, Inc. or its subsidiaries.
UNIX is a registered trademark in the United States and other countries licensed exclusively through
X/Open Company Limited.
TPC Benchmark, TPC-D, QppD, QthD, and QphD are trademarks of the Transaction Processing
Performance Council.
Other trademarks and trade names mentioned herein are the property of their respective owners.