Escolar Documentos
Profissional Documentos
Cultura Documentos
Reference
iii
The Server Location utility .................................................... 116
The Spawn utility................................................................... 117
The Stop utility ...................................................................... 118
The Transaction Log utility.................................................... 120
The Uncompression utility..................................................... 124
The Unload utility .................................................................. 126
The Upgrade utility................................................................ 133
The Validation utility.............................................................. 136
The Write File utility .............................................................. 139
iv
8 SQL Functions ............................................................... 291
Function types....................................................................... 292
Alphabetical list of functions.................................................. 301
v
CREATE VARIABLE statement............................................ 468
CREATE VIEW statement .................................................... 469
CREATE WRITEFILE statement .......................................... 471
DEALLOCATE DESCRIPTOR statement [ESQL] ................ 472
Declaration section [ESQL]................................................... 473
DECLARE statement ............................................................ 474
DECLARE CURSOR statement [ESQL] [SP] ....................... 475
DECLARE CURSOR statement [T-SQL].............................. 480
DECLARE LOCAL TEMPORARY TABLE
statement .............................................................................. 481
DELETE statement ............................................................... 482
DELETE (positioned) statement [ESQL] [SP]....................... 484
DESCRIBE statement [ESQL] .............................................. 486
DISCONNECT statement
[ESQL][Interactive SQL]........................................................ 490
DROP statement................................................................... 491
DROP DATABASE statement............................................... 493
DROP CONNECTION statement ......................................... 494
DROP EXTERNLOGIN statement........................................ 495
DROP OPTIMIZER STATISTICS statement ........................ 496
DROP SERVER statement ................................................... 497
DROP STATEMENT statement [ESQL] ............................... 498
DROP VARIABLE statement ................................................ 499
EXECUTE statement [ESQL]................................................ 500
EXECUTE statement [T-SQL]............................................... 502
EXECUTE IMMEDIATE statement [SP] ............................... 504
EXIT statement [Interactive SQL] ......................................... 506
EXPLAIN statement [ESQL] ................................................. 507
FETCH statement [ESQL] [SP]............................................. 509
FOR statement...................................................................... 514
FORWARD TO statement..................................................... 516
FROM clause ........................................................................ 518
GET DATA statement [ESQL]............................................... 521
GET DESCRIPTOR statement [ESQL] ................................ 523
GET OPTION statement [ESQL] .......................................... 524
GOTO statement [T-SQL] ..................................................... 525
GRANT statement................................................................. 526
HELP statement [Interactive SQL]........................................ 530
IF statement .......................................................................... 531
IF statement [T-SQL] ............................................................ 533
INCLUDE statement [ESQL]................................................. 535
INPUT statement [Interactive SQL] ...................................... 536
INSERT statement ................................................................ 540
INSTALL statement............................................................... 542
LEAVE statement.................................................................. 544
LOAD TABLE statement ....................................................... 546
vi
LOCK TABLE statement ....................................................... 551
LOOP statement ................................................................... 553
MESSAGE statement ........................................................... 554
OPEN statement [ESQL] [SP]............................................... 556
OUTPUT statement [Interactive SQL]................................... 559
PARAMETERS statement [Interactive SQL] ........................ 563
PREPARE statement [ESQL] ............................................... 564
PREPARE TO COMMIT statement ...................................... 566
PRINT statement [T-SQL]..................................................... 567
PUT statement [ESQL] ......................................................... 568
RAISERROR statement [T-SQL] .......................................... 570
READ statement [Interactive SQL] ....................................... 572
READTEXT statement [T-SQL] ............................................ 573
RELEASE SAVEPOINT statement ....................................... 574
REMOVE statement.............................................................. 575
RESIGNAL statement ........................................................... 576
RESTORE statement............................................................ 577
RESUME statement .............................................................. 578
RETURN statement .............................................................. 579
REVOKE statement .............................................................. 581
ROLLBACK statement .......................................................... 583
ROLLBACK TO SAVEPOINT statement .............................. 584
ROLLBACK TRIGGER statement......................................... 585
SAVEPOINT statement......................................................... 586
SELECT statement ............................................................... 587
SET statement ...................................................................... 591
SET statement [T-SQL]......................................................... 593
SET CONNECTION statement
[Interactive SQL][ESQL]........................................................ 594
SET DESCRIPTOR statement [ESQL] ................................. 595
SET OPTION statement ....................................................... 596
SET OPTION statement [Interactive SQL] ........................... 599
SET SQLCA statement [ESQL] ............................................ 600
SETUSER statement ............................................................ 601
SIGNAL statement ................................................................ 603
START DATABASE statement ............................................. 604
START ENGINE statement [Interactive SQL]....................... 606
START JAVA statement ....................................................... 607
START LOGGING statement [Interactive SQL].................... 608
STOP DATABASE statement ............................................... 609
STOP ENGINE statement..................................................... 610
STOP JAVA statement ......................................................... 611
STOP LOGGING statement [Interactive SQL]...................... 612
SYSTEM statement [Interactive SQL]................................... 613
TRIGGER EVENT statement................................................ 614
TRUNCATE TABLE statement ............................................. 615
vii
UNION operation .................................................................. 617
UNLOAD statement .............................................................. 618
UNLOAD TABLE statement.................................................. 619
UPDATE statement............................................................... 621
UPDATE (positioned) statement........................................... 625
VALIDATE INDEX statement................................................ 627
VALIDATE TABLE statement ............................................... 628
WHENEVER statement [ESQL]............................................ 630
WHILE statement [T-SQL] .................................................... 631
WRITETEXT statement [T-SQL]........................................... 632
viii
SYSARTICLECOL system table ........................................... 968
SYSCAPABILITY system table............................................. 969
SYSCAPABILITYNAME system table .................................. 970
SYSCOLLATION system table ............................................. 971
SYSCOLLATIONMAPPINGS system table .......................... 972
SYSCOLPERM system table................................................ 973
SYSCOLUMN system table .................................................. 974
SYSDOMAIN system table ................................................... 976
SYSEXTENT system table ................................................... 977
SYSEXTERNLOGINS system table ..................................... 978
SYSFILE system table .......................................................... 979
SYSFKCOL system table...................................................... 980
SYSFOREIGNKEY system table .......................................... 981
SYSGROUP system table .................................................... 983
SYSINDEX system table....................................................... 984
SYSINFO system table ......................................................... 986
SYSIXCOL system table....................................................... 988
SYSJAR system table ........................................................... 989
SYSJARCOMPONENT system table ................................... 990
SYSJAVACLASS system table............................................. 991
SYSLOGIN system table ...................................................... 993
SYSOPTION system table.................................................... 994
SYSPROCEDURE system table........................................... 995
SYSPROCPARM system table............................................. 996
SYSPROCPERM system table............................................. 998
SYSPUBLICATION system table.......................................... 999
SYSREMOTEOPTION system table .................................. 1000
SYSREMOTEOPTIONTYPE system table ......................... 1001
SYSREMOTETYPE system table....................................... 1002
SYSREMOTEUSER system table ...................................... 1003
SYSSERVERS system table .............................................. 1005
SYSSQLSERVERTYPE system table ................................ 1006
SYSSUBSCRIPTION system table..................................... 1007
SYSTABLE system table .................................................... 1008
SYSTABLEPERM system table.......................................... 1010
SYSTRIGGER system table ............................................... 1012
SYSTYPEMAP system table .............................................. 1014
SYSUSERMESSAGES system table ................................. 1015
SYSUSERPERM system table ........................................... 1016
SYSUSERTYPE system table ............................................ 1018
ix
SYSCATALOG system view ............................................... 1026
SYSCOLAUTH system view ............................................... 1027
SYSCOLUMNS system view .............................................. 1028
SYSFOREIGNKEYS system view ...................................... 1029
SYSGROUPS system view................................................. 1030
SYSINDEXES system view ................................................ 1031
SYSOPTIONS system view ................................................ 1032
SYSPROCAUTH system view ............................................ 1033
SYSPROCPARMS system view......................................... 1034
SYSPUBLICATIONS system view...................................... 1035
SYSREMOTEOPTIONS system view ................................ 1036
SYSREMOTETYPES system views ................................... 1037
SYSREMOTEUSERS system view .................................... 1038
SYSSUBSCRIPTIONS system view................................... 1039
SYSTABAUTH system view ............................................... 1040
SYSTRIGGERS system view ............................................. 1041
SYSUSERAUTH system view ............................................ 1042
SYSUSERLIST system view............................................... 1043
SYSUSEROPTIONS system view...................................... 1044
SYSUSERPERMS system view ......................................... 1045
SYSVIEWS system view..................................................... 1046
Views for Transact-SQL Compatibility ................................ 1047
Index..............................................................................1073
x
About This Manual
Subject
This manual provides reference material for all aspects of Adaptive Server
Anywhere, including SQL statements, administration utilities, error
messages, system tables, and so on.
While other manuals provide more motivation and context for how to carry
out particular tasks, this manual is the place to look for complete listings of
available syntax, utility command-line options, and so on.
Audience
This manual is for all users of Adaptive Server Anywhere. It is to be used in
conjunction with other manuals in the documentation set.
Contents
Topic Page
Related documentation xii
Documentation conventions xiii
The sample database xvi
xi
Related documentation
Adaptive Server Anywhere is a part of SQL Anywhere Studio. For an
overview of the different components of SQL Anywhere Studio, see
Introducing SQL Anywhere Studio.
The Adaptive Server Anywhere documentation consists of the following
books:
♦ Getting Started Intended for all users of Adaptive Server Anywhere,
this book describes the following:
♦ New features in Adaptive Server Anywhere
♦ Behavior changes from previous releases
♦ Upgrade procedures
♦ Introductory material for beginning users.
♦ Programming Interfaces Guide Intended for application developers
writing programs that directly access the ODBC, Embedded SQL, or
Open Client interfaces, this book describes how to develop applications
for Adaptive Server Anywhere.
This book is not required for users of Application Development tools
with built-in ODBC support, such as Sybase PowerBuilder.
♦ User’s Guide A comprehensive guide to using SQL, administering
databases, and using Adaptive Server Anywhere features.
♦ Quick Reference A handy printed booklet with complete SQL syntax
and other key reference material in a concise format.
♦ Read Me First (UNIX only) A separate booklet is provided with UNIX
versions of Adaptive Server Anywhere, describing installation and
adding some UNIX-specific notes.
The format of these books (printed or online) may depend on the product in
which you obtained Adaptive Server Anywhere. Depending on which
package you have purchased, you may have additional books describing
other components of your product.
xii
Documentation conventions
This section lists the typographic and graphical conventions used in this
documentation.
Syntax conventions
The following conventions are used in the SQL syntax descriptions:
♦ Keywords All SQL keywords are shown in UPPER CASE. However,
SQL keywords are case insensitive, so you can enter keywords in any
case you wish; SELECT is the same as Select is the same as select.
♦ Placeholders Items that must be replaced with appropriate identifiers
or expressions are shown in italics.
♦ Continuation Lines beginning with ... are a continuation of the
statements from the previous line.
♦ Repeating items Lists of repeating items appear with an element of
the list followed by an ellipsis (three dots). One or more list elements are
allowed. If you specify more than one, they must be separated by
commas.
♦ Optional portions Optional portions of a statement are enclosed by
square brackets. For example,
RELEASE SAVEPOINT [ savepoint-name ]
indicates that the savepoint-name is optional. Do not type the square
brackets.
♦ Options When none or only one of a list of items must be chosen, the
items are separated by vertical bars and the list enclosed in square
brackets. For example,
[ ASC | DESC ]
indicates that you can choose one of ASC, DESC, or neither. The square
brackets should not be typed.
♦ Alternatives When precisely one of the options must be chosen, the
alternatives are enclosed in curly braces. For example,
QUOTES { ON | OFF }
indicates that exactly one of ON or OFF must be provided. Do not type
the braces.
xiii
Graphic icons
The following icons are used in this documentation:
Icon Meaning
A client application.
If the icon is used to represent a particular application
or kind of application, the name is indicated in the
bottom right corner.
A database.
In some high-level diagrams, the icon may be used to
represent both the database and the database server
that manages it.
xiv
Installed files
The following terms are used throughout the manual:
♦ Installation directory The directory into which you install Adaptive
Server Anywhere.
♦ Executable directory The executables and other files for each
operating system are held in an executable subdirectory of the
installation directory. This subdirectory has the following name:
♦ Windows NT and Windows 95/98 win32
♦ UNIX bin
♦ Windows 3.x win
♦ NetWare and Windows CE The executables are held in the
Adaptive Server Anywhere installation directory itself on these
platforms.
xv
The sample database
There is a sample database included with Adaptive Server Anywhere. Many
of the examples throughout the documentation use this sample database.
The sample database represents a small company. It contains internal
information about the company (employees, departments, and financial data)
as well as product information (products), sales information (sales orders,
customers, and contacts), and financial information (fin_code, fin_data).
The following figure shows the tables in the sample database and how they
are related to each other.
asademo.db
product employee
id <pk> integer sales_order_items
emp_id <pk> integer
name char(15) id <pk,fk> integer
manager_id integer
description char(30) line_id <pk> smallint
emp_fname char(20)
size char(18) id = prod_id prod_id <fk> integer
emp_lname char(20)
color char(6) quantity integer
dept_id <fk> integer
quantity integer ship_date date
street char(40)
unit_price numeric(15,2)
city char(20)
state char(4)
id = id
emp_id = sales_rep zip_code char(9)
phone char(10)
customer status char(1)
ss_number char(11)
id <pk> integer sales_order
salary numeric(20,3)
fname char(15) id <pk> integer start_date date
lname char(20) cust_id <fk> integer termination_date date
address char(35) order_date date birth_date date
city char(20) id = cust_id fin_code_id <fk> char(2) bene_health_ins char(1)
state char(2) region char(7) bene_life_ins char(1)
zip char(10) sales_rep <fk> integer bene_day_care char(1)
phone char(12)
sex char(1)
company_name char(35) code = fin_code_id
fin_code
code <pk> char(2)
contact dept_id = dept_id
type char(10)
id <pk> integer description char(50) emp_id = dept_head_id
last_name char(15)
first_name char(15)
title char(2) code = code
street char(30)
city char(20) fin_data
state char(2) year <pk> char(4) department
zip char(5) quarter <pk> char(2) dept_id <pk> integer
phone char(10) code <pk,fk> char(2) dept_name char(40)
fax char(10) amount numeric(9) dept_head_id <fk> integer
xvi
C H A P T E R 1
About this chapter This chapter describes the installation and operating system settings used by
Adaptive Server Anywhere. Depending on the operating system, these
settings may be stored as environment variables, initialization file entries, or
registry entries.
Contents
Topic Page
Installation directory structure 2
How Adaptive Server Anywhere locates files 4
Environment variables 6
Registry entries and INI files 10
1
Installation directory structure
2
Chapter 1 File Locations and Installation Settings
♦ h directory The h directory contains header files for ESQL and ODBC
database development.
Novell NetWare file On Novell NetWare, all files are installed to a single directory on the server.
locations Throughout this documentation, when reference is made to files in
subdirectories of the installation directory, the file on NetWare is in the
installation directory itself.
Windows CE file On Windows CE, all files are installed to the installation directory, and no
locations subdirectories are created. The exception is that all DLLs are installed into
the \Windows directory. To make identification easy, the DLL names all have
the prefix ASA_.
3
How Adaptive Server Anywhere locates files
4
Chapter 1 File Locations and Installation Settings
5
Environment variables
Environment variables
Adaptive Server Anywhere uses a set of environment variables to store
various types of information. Not all variables need to be set in all
circumstances. These environment variables are listed in this section.
6
Chapter 1 File Locations and Installation Settings
7
Environment variables
8
Chapter 1 File Locations and Installation Settings
9
Registry entries and INI files
10
Chapter 1 File Locations and Installation Settings
Registry structure
On Windows 95/98 and Windows NT, you can access the registry directly
with the registry editor. The Adaptive Server Anywhere registry entries are
held in either the HKEY_CURRENT_USER or
HKEY_LOCAL_MACHINE registries, in the following location:
Software
Sybase
Adaptive Server Anywhere
7.0
Sybase Central
4.0
Profiles
Providers
11
Registry entries and INI files
12
C H A P T E R 2
About this chapter This chapter describes the command-line options for the Adaptive Server
Anywhere database server.
It also contains information for the command-line options of the client
executable (provided for compatibility with Version 5 software).
Contents
Topic Page
The database server 14
13
The database server
Switch Description
@filename Read in switches from a configuration file. See "@filename
command-line option" on page 19.
@environment- Read in switches from an environment variable. See
variable "@environment-variable command-line option" on page 19.
-? Display usage information. See "–? command-line option" on
page 20.
-b Run in bulk operations mode. See "–b command-line option" on
page 20.
-c size Set initial cache size. See "–c command-line option" on page 21.
-ca 0 Disable dynamic cache sizing [Windows NT, Windows 95/98].
See "–ca command-line option" on page 22.
-ch size Set the cache size upper limit [Windows NT, Windows 95/98].
See "–ch command-line option" on page 22.
-cl Set the cache size lower limit [Windows NT].
-cs Display cache usage in database server window. For more
information, see "–cs command-line option" on page 23.
-ct Enable character-set translation [Not NetWare or Windows CE].
See "–ct command-line option" on page 23.
-d Disable asynchronous I/O [Windows NT, NetWare]. See "–d
command-line option" on page 24.
-e Enable packet encryption [network server]. See "–e command-
line option" on page 24.
-ga Automatically unload the database after the last connection
closed. In addition, shut down after the last database is closed
[Not NetWare]. See "–ga command-line option" on page 24.
-gb level Set database process priority class to level [Windows NT]. See "–
gb command-line option" on page 25.
-gc minutes Set maximum checkpoint timeout period to num minutes. See "–
gc command-line option" on page 25.
-gd level Set database starting permission. See "–gd command-line option"
on page 25.
14
Chapter 2 The Database Server
Switch Description
-ge size Set the stack size for threads that run external functions [not
UNIX]. See "–ge command-line option" on page 26.
-gf Disable firing of triggers. See "–gf command-line option" on
page 27.
-gl level Set the permission required to load or unload data. See "–gl
command-line option" on page 27.
-gk level Set the permission required to stop the server. See "–gk
command-line option" on page 27.
-gm num Limit the maximum number of connections. See "–gm command-
line option" on page 28.
-gn num Set the number of threads. See "–gn command-line option" on
page 28.
-gp size Set the maximum page size to size bytes. See "–gp command-line
option" on page 28.
-gr minutes Set the maximum recovery time to num minutes. See "–gr
command-line option" on page 29.
-gss size Set the thread stack size to size bytes. See "–gss command-line
option" on page 29.
-gt num Set the number of CPUs for request processing. See "–gt
command-line option" on page 29.
-gu level Set the permission level for utility commands: utility_db, all,
none, dba. See "–gu command-line option" on page 30.
-gw Set the interval (in milliseconds) for background processing. See
"–gw command-line option" on page 30.
-gx Modify operating system threading [Windows 95/98 and
Windows NT]. See "–gx command-line option" on page 30.
-m Truncate the transaction log after each checkpoint, for all
databases. See "–m command-line option" on page 31.
-n name Use name as the name of the database server. See "–n command-
line option" on page 31.
-o filename Output messages to the specified file. See "–o command-line
option" on page 32.
-os size Limit the size of the log file for messages. See "–os command-
line option" on page 32.
-p packet-size Set the maximum network packet size [network server]. See "–p
command-line option" on page 33.
-q Quiet mode—suppress output. See "–q command-line option" on
page 33.
15
The database server
Switch Description
-r Opens database in read-only mode. See "–r command-line
option" on page 33.
-s Set the syslog facility ID [UNIX]. See "–s command-line option"
on page 34.
-sc Disable the shared memory port, and enable Named Pipes.
[Windows NT]. See "–sc command-line option" on page 34.
-ti minutes Client idle time before shutdown—default 240 minutes [network
server]. See "–ti command-line option" on page 34.
-tl seconds Default liveness timeout for clients in seconds—default 120
seconds [network server]. See "–tl command-line option" on
page 35.
-tmf Force transaction manager recovery for distributed transactions.
See "–tmf command-line option" on page 35.
-tmt Set the reenlistment timeout for distributed transactions. See "–
millisecondst tmt command-line option" on page 35.
-tq time Set quitting time [network server]. See "–tq time command-line
option" on page 36.
-u Use buffered disk I/O. See "–u command-line option" on
page 36.
-ud Run as a daemon [UNIX]. See "–ud command-line option" on
page 36.
-ut minutes Touch temporary files every min minutes [UNIX]. See "–ut
command-line option" on page 37.
-v Display database server version and stop. See "–v command-line
option" on page 37.
-x list Comma-separated list of communication links to try. See "–x
command-line option" on page 37.
-y Run as a Windows 95/98 service [Windows 95/98]. See "–y
command-line option" on page 39.
-z Provide diagnostic information on communication links [network
server]. See "–z command-line option" on page 39.
-zo filename Redirect request-level logging information to a separate file. See
"–zo command-line option" on page 39.
-zr { all | SQL | Turn on logging of SQL operations. The default is NONE. See "–
none } zr command-line option" on page 40.
-zs size Limit the size of the log file used for request-level logging. See
"–zs command-line option" on page 40.
16
Chapter 2 The Database Server
See also
"Running the Database Server" on page 3 of the book ASA User’s Guide
"Network communications parameters" on page 61
Description The dbeng7 command starts a personal database server. The dbsrv7
command starts a network database server.
Cache size The amount of cache memory available to the database server can be a key
factor in affecting performance. The database server takes an initial amount
of cache memory that is either specified by the -c command-line option or is
a default value. For information on the default cache size, see "–c command-
line option" on page 21.
On Windows NT, Windows 95/98, and UNIX the database server
automatically takes more memory for use in the cache as needed, determined
by a heuristic algorithm
$ For more information, see "Using the cache to improve performance"
on page 785 of the book ASA User’s Guide.
You can use database command-line options to configure the upper limit: see
"–ch command-line option" on page 22. You can force the cache to remain at
its initial amount: see "–ca command-line option" on page 22.
Server differences The personal database server has a maximum of ten concurrent connections,
uses at most two CPUs for request processing, and does not support network
client/server connections.
In addition, there are other minor differences, such as the default permission
level that is required to start new databases, or the permissions required to
execute the CHECKPOINT statement.
Platform availability Both personal and network database servers are supplied for each supported
operating system, with the following exceptions:
17
The database server
Caution
The database file must be on the same machine as the database server.
Managing a database file that is located on a network drive can lead to
file corruption.
Suppressing If you run the database server as a Windows NT service, you can suppress
Windows NT event NT event log entries by setting a registry entry. The registry entry is
log messages
Software\Sybase\Adaptive Server Anywhere\7.0
18
Chapter 2 The Database Server
To control event log entries, set the EventLogMask key, which is of type
REG_DWORD. The value is a bit mask containing the internal bit values for
the different types of event messages:
errors EVENTLOG_ERROR_TYPE 0x0001
warnings EVENTLOG_WARNING_TYPE 0x0002
information EVENTLOG_INFORMATION_TYPE 0x0004
For example, if the EventLogMask is set to zero, no messages appear at all.
A better setting would be 1, so that informational and warning messages do
not appear, but errors do. The default setting (no entry present) is for all
message types to appear.
19
The database server
Description The environment variable may contain any set of command line switches.
For example, the first statement sets an environment variable that holds
command line switches for a database server that starts with a cache size of
4Mb and loads the sample database. The second statement starts the database
server:
set envvar=-c 4096 c:\asa6\asademo.db
dbsrv7 @envvar
–? command-line option
Function Display usage information.
Syntax [ dbsrv7 | dbeng7 ] -?
Applies to All operating systems and servers.
Description Display a short description of each command-line option. The database does
not carry out any other task.
–b command-line option
Function Use bulk operation mode.
Syntax [ dbsrv7 | dbeng7 ] -b ...
Applies to All operating systems and servers.
Description This is useful for using the Interactive SQL INPUT command to load large
quantities of data into a database.
The -b option should not be used if you are using LOAD TABLE to bulk
load data.
When you use this option, the database server allows only one connection by
one application. It does not keep a rollback log or a transaction log, and the
multi-user locking mechanism is turned off.
When you first start the database server after loading data with the -b
switch, you should use a new log file.
Bulk operation mode does not disable the firing of triggers.
20
Chapter 2 The Database Server
–c command-line option
Function Set the initial memory reserved for caching database pages and other server
information.
Syntax [ dbsrv7 | dbeng7 ] -c [integer | integerK | integerM | integerP ] ...
Applies to All operating systems and servers.
Description The amount of memory available for use as a database server cache is one of
the key factors controlling performance. You can set the initial amount of
cache memory using the -c command-line option
The more cache memory that can be given the server, the better will be its
performance.
The units K and M can be either lower case or upper case. If K or M is not
supplied, any integer less than 10000 is assumed to be in kilobytes, and any
integer 10000 or greater is assumed to be in bytes. For example, -c 4096
means 4096KB or 4 194 304 bytes. Whereas, -c 200 000 means (an
unreasonably small) cache of 200 000 bytes.
The unit P is a percentage of the physical system memory, and if you use
this, the argument is a percentage. You can use % as an alternative to P, but
as most non-UNIX operating systems use % as an environment variable
escape character, you must escape the % character. To use 50 percent of the
physical system memory, you would use the following:
dbeng7 -c 50%% ...
21
The database server
22
Chapter 2 The Database Server
Description This option limits the cache that the database server can take during
automatic cache growth. By default the upper limit is approximately the
lower of 256 Mb and 90% of the physical memory of the machine.
$ For the meaning and usage of the cache size arguments and the K, M,
and P characters, see "–c command-line option" on page 21.
See also "–c command-line option" on page 21
"–ca command-line option" on page 22
"–cl command-line option" on page 23
23
The database server
Description Character set translation converting strings between character sets that
represent the same characters, but at different values. This is useful when the
client machine and the database use different character sets.
$ For more information, see "Starting a database server using character
set translation" on page 314 of the book ASA User’s Guide.
–d command-line option
Function Disable asynchronous I/O.
Syntax [ dbsrv7 | dbeng7 ] -d ...
Applies to Windows NT, NetWare
Description Use synchronous I/O rather than asynchronous I/O. Asynchronous I/O is
generally the preferred option.
This option applies only to Windows NT and NetWare systems, which use
asynchronous I/O by default.
–e command-line option
Function Encrypt all packets transmitted to and from all clients.
Syntax [ dbsrv7 | dbeng7 ] -e...
Applies to All operating systems and servers.
Description By default, communication packets are not encrypted, thus posing a potential
security risk. If you are concerned about the security of network packets, use
the -e switch. Encryption does marginally affect performance.
24
Chapter 2 The Database Server
25
The database server
Description This is the permission required for a user to cause a new database file to be
loaded by the server. The level can be one of the following:
♦ dba Only users with DBA authority can start new databases.
♦ all All users can start new databases.
♦ none Starting new databases is not allowed.
The default setting is ALL for the personal database server and DBA for the
network database server. Both uppercase and lowercase syntax is acceptable.
Example The following set of steps illustrates how to use the –gd option for the
network database server.
1 Enter a password in the util_db.ini file in your SQL Anywhere win32
directory:
[UTILITY_DB]
pwd=mypwd
2 Start the network database server:
dbsrv7 -x tcpip -n myserver -gd dba
3 Connect to the utility database from Interactive SQL.
The following command assumes that myserver is the default database
server:
dbisql -c "uid=dba;pwd=mypwd;dbn=utility_db "
4 Start a database:
start database asademo
on myserver;
5 Connect to the database you have started:
connect
to myserver
database asademo
user DBA identified by SQL
26
Chapter 2 The Database Server
27
The database server
The default settings are all for personal database servers on non-Unix
operating systems, and dba for the network database server and the Unix
personal server. These settings reflect the fact that, on non-UNIX platforms,
the personal database server is running on the current machine, and so the
user already has access to the file system.
If you do not use this switch, then the page size of the first database on the
command line is used.
The minimum page size on all UNIX platforms is 2048 bytes. You can still
use databases with smaller page sizes, but cache memory is used very
inefficiently. If you do not use this switch and start a server with no
databases loaded, the default value is 2048.
On all other platforms, if you do not use this switch and start a server with no
databases loaded, the default value is 1024.
29
The database server
The utility_db level restricts the use of these commands to only those users
who can connect to the utility database. The all, none, and dba levels permit
all users , no users, or users with dba authority to execute utility commands.
30
Chapter 2 The Database Server
On UNIX, each task is executed in its own thread, so that the number of
tasks (-gn) also determines the number of threads.
–m command-line option
Function Delete the transaction log when a checkpoint is done.
Syntax [ dbsrv7 | dbeng7 ] -m ...
Applies to All operating systems and servers.
Description This option deletes the transaction log when a checkpoint is done, either at
shutdown or as a result of a checkpoint scheduled by the server.
Caution
When this option is selected, there is no protection against media failure
on the device that contains the database files.
This provides a way to automatically limit the growth of the transaction log.
Checkpoint frequency is still controlled by the CHECKPOINT_TIME and
RECOVERY_TIME options (which you can also set on the command line).
This option is useful where high volume transactions that require fast
response times are being processed, and the contents of the transaction log
are not being relied upon for recovery or replication.
Replicated databases
Do not use the -m option with databases that are being replicated.
Replication inherently relies on transaction log information.
–n command-line option
Function Set the name of the database server.
Syntax [ dbsrv7 | dbeng7 ] -n string ...
Applies to All operating systems and servers.
See also "Identifiers" on page 211
"EngineName connection parameter" on page 55
31
The database server
Description By default, the database server receives the name of the database file with
the path and extension removed. For example, if the server is started on the
file c:\sybase\asa6\asademo.db and no -n switch is specified, the name of
the server is asademo.
The server name is interpreted according to the character set of the machine,
as no database collation exists at startup time. It must be a valid identifier,
and long engine names are truncated to 40 characters. On NetBIOS, 16
characters is the maximum length.
The server name specifies the name to be used in the EngineName parameter
of client application connection strings or profiles. In all environments, there
is a default database server that will be used if no server name is specified,
provided at least one database server is running on the computer.
–o command-line option
Function Print all server window output to a file.
Syntax [ dbsrv7 | dbeng7 ] -o filename ...
Applies to All operating systems and servers.
Description Print all server message window output to a file.
32
Chapter 2 The Database Server
–p command-line option
Function Set the maximum size of communication packets.
Syntax [ dbsrv7 | dbeng7 ] -p integer...
Applies to All operating systems and servers.
Description The default is 512 bytes. The minimum value is 280 bytes and the maximum
is 16000.
–q command-line option
Function Do not display the server screen or its output.
Syntax [ dbsrv7 | dbeng7 ] -q...
Applies to All operating systems and servers, except NetWare.
–r command-line option
Function Opens a database in read-only mode. No changes to the database are
allowed. The database file and transaction log files are not modified by the
server.
Syntax [ dbsrv7 | dbeng7 ] -r ...
Applies to All operating systems and servers.
Description Opens all database files as read-only with the exception of the temporary file.
You can make changes on temporary tables, but ROLLBACK has no effect,
since the transaction and rollback logs are disabled.
Databases distributed on CD-ROM devices, and compressed databases are
examples of database files that cannot be modified. You can either create a
write file to allow changes to the database outside the database file, or run in
read-only mode.
If you attempt to modify the database, for example with an INSERT or
DELETE statement, a SQLSTATE_READ_ONLY_DATABASE error is
returned.
Databases that require recovery cannot be started in read-only mode. For
example, database files created using an online backup cannot be started in
read-only mode if there were any open transactions when the backup was
started, since these transactions would require recovery when the backup
copy is started.
33
The database server
–s command-line option
Function Set the user ID for syslog messages.
Syntax [ dbsrv7 | dbeng7 ] -s { none | user | login-id...}
Applies to UNIX
Description Sets the system user ID used in messages to the syslog facility. The default
is user, which uses the user ID for the database server process. A value of
none prevents any syslog messages from being logged.
34
Chapter 2 The Database Server
The -tl switch on the server sets the liveness timeout for all clients that do
not specify a liveness period.
35
The database server
Caution
If you use this option, distributed transactions are not recovered properly.
It is not for routine use.
–u command-line option
Function Open files using the operating system disk cache.
Syntax [ dbsrv7 | dbeng7 ] -u ...
Applies to Windows NT, Windows 95/98, UNIX
Description Files are opened using the operating system disk cache in addition to the
database cache.
While the operating system disk cache may improve performance in some
cases, in general better performance is obtained without this switch, using the
database cache only.
If the server is running on a dedicated machine, you should not use the -u
option, as the database cache itself is generally more efficient. You may want
to use the -u option if the server is running on a machine with several other
applications (so that a large database cache may interfere with other
applications) and yet IO-intensive tasks are run intermittently on the server
(so that a large cache will improve performance).
36
Chapter 2 The Database Server
–v command-line option
Function Display the software version.
Syntax [ dbsrv7 | dbeng7 ] -v
Applies to All operating systems and servers.
Description Supplies the database server version in a message box, and then stops.
–x command-line option
Function Specify communications links.
Syntax [ dbsrv7 | dbeng7 ] -x {
all
| none
| { [ipx | namedpipes | netbios | spx | tcpip ] parmlist,... }
} ...
parmlist:
{ keyword=value;...}
Applies to All operating systems and servers.
See also "CommLinks connection parameter" on page 50
Description For example,
-x tcpip,spx
37
The database server
The default set of communications links is to try all settings that are
supported by the database server that you are running on your operating
system, with the following exceptions:
♦ On Windows CE; the TCP/IP protocol is not started unless it is
explicitly requested.
♦ The IPX protocols is not started unless they are explicitly requested. It is
recommended that you use SPX instead of IPX.
The list is a comma-separated list of settings taken from the following case-
insensitive list:
♦ ALL Start all communications links that are supported on this platform
by the server that you are starting. This is the default.
♦ IPX Supported by NetWare, Windows NT, and Windows 95/98
network servers. This protocol is deprecated, and is not started by
default, as SPX provides a faster and more robust solution for IPX/SPX
communications.
♦ NamedPipes (NP) Supported on Windows NT, as an alternative
means of same-machine communication.
♦ NetBIOS Supported by Windows NT and Windows 95/98 network
database servers.
♦ NONE Do not start any communications links except for the shared
memory link.
♦ SPX Supported by NetWare, Windows NT, and Windows 95/98
network servers.
♦ TCPIP (TCP) Supported by the network server on all operating
systems. This communications link is also supported by the personal
database server for same-machine communications.
The database server always listens on port 2638, even if you specify a
different port using a network communication parameter. Hence,
applications can connect to the database server without specifying a port
number. For information, see "ServerPort parameter" on page 66.
An exception is the HP-UX operating system, on which the server does
not listen on port 2638 if it is started on another port.
38
Chapter 2 The Database Server
For UNIX, quotation marks are required if more than one parameter is
supplied:
-x "tcpip(PARM1=value1;PARM2=value2;...)"
$ For a description of available parameters, see "Network
communications parameters" on page 61.
–y command-line option
Function Run as a Windows 95/98 service.
Syntax [ dbsrv7 | dbeng7 ] -y ...
Applies to Windows 95/98
Description If the server registered as a Windows 95/98 service, it continues to operate
whether users log on or off, and shutdown commands are ignored.
–z command-line option
Function Display communications operations on startup for troubleshooting purposes.
Syntax [ dbsrv7 | dbeng7 ] -z ...
Applies to All operating systems and servers.
Description This should only be used when tracking problems. The information is
displayed in the database server window.
39
The database server
Recovery switches
These switches are for use in recovery situations only.
–a command-line option
Function Apply the named transaction log.
Syntax [ dbsrv7 | dbeng7 ] -a log-filename...
Applies to All operating systems and servers.
Description This is used to recover from media failure on the database file. When this
option is specified, the database server applies the log and then terminates—
it will not continue to run.
$ For information on recovery, see "Backup and Data Recovery" on
page 627 of the book ASA User’s Guide.
40
Chapter 2 The Database Server
–f command-line option
Function Force the database server to start after the transaction log has been lost.
Syntax [ dbsrv7 | dbeng7 ] -f ...
Applies to All operating systems and servers.
Description If there is no transaction log, the database server carries out a checkpoint
recovery of the database and then terminates—it does not continue to run.
You can then restart the database server without the -f option for normal
operation.
If there is a transaction log in the same directory as the database, the database
server carries out a checkpoint recovery, and a recovery using the transaction
log, and then terminates—it does not continue to run. You can then restart
the database server without the -f option for normal operation.
$ For more information see "Backup and Data Recovery" on page 627 of
the book ASA User’s Guide.
Database switches
These switches are entered after the database name, and apply only to that
database.
–m command-line option
Function Truncate the transaction log when a checkpoint is done.
Syntax [ dbsrv7 | dbeng7 ] [ server-switches ]. database-file -m ..
Applies to All operating systems and servers.
Description Truncate (delete) the transaction log when a checkpoint is done, either at
shutdown or as a result of a checkpoint scheduled by the server. This
provides a way to automatically limit the growth of the transaction log.
Checkpoint frequency is still controlled by the CHECKPOINT_TIME and
RECOVERY_TIME options (which you can also define on the command
line).
41
The database server
Replicated databases
Do not use the -m option with databases that are being replicated.
Replication inherently relies on transaction log information.
–n command-line option
Function Set the name of the database.
Syntax [ dbsrv7 | dbeng7 ] [ server-switches ]. database-file -n string ..
Applies to All operating systems and servers.
Description Both database servers and databases can be named. Since a database server
can load several databases, the database name is used to distinguish the
different databases.
By default, the database receives the name of the database file with the path
and extension removed. For example, if the database is started on
c:\asa7\asademo.db and no -n switch is specified, the name of the database
is asademo.
42
C H A P T E R 3
About this chapter This chapter provides a reference for the parameters that establish and
describe connections from client applications to a database.
Contents
Topic Page
Connection parameters 44
Network communications parameters 61
43
Connection parameters
Connection parameters
This section describes each connection parameter. Connection parameters are
included in connection strings. They can be entered in the following places:
♦ In an application’s connection string. For more information, see
"Assembling a list of connection parameters" on page 65 of the book
ASA User’s Guide.
♦ In an ODBC data source. For more information, see "Working with
ODBC data sources" on page 47 of the book ASA User’s Guide.
♦ In the Adaptive Server Anywhere connection window. For more
information, see "Connecting from Adaptive Server Anywhere utilities"
on page 46 of the book ASA User’s Guide.
The ODBC configuration dialog and the Adaptive Server Anywhere
connection window for Windows operating systems share a common format.
Some of the parameters correspond to checkboxes and fields in these
windows, others can be entered in the text box at the end of the Advanced
tab.
Notes ♦ Connection parameters are case-insensitive.
♦ The Usage for each connection parameter describes the circumstances
under which the parameter is to be used. Common usage entries include
the following:
♦ Embedded databases When Adaptive Server Anywhere is used
as an embedded database, the connection starts a personal server
and loads the database. When the application disconnects from the
database, the database is unloaded and the server stops.
♦ Running local databases This refers to the case where an
Adaptive Server Anywhere personal server is already running, and
the database is already loaded on the server.
♦ Network servers When Adaptive Server Anywhere is used as a
network server, the client application must locate a server already
running somewhere on the network and connect to a database.
♦ You can use the dbping utility to test connection strings. For example, if
the database file MyDB.db is not currently running, the following string
returns the message Ping database successful:
dbping -d -c "dbf=c:\Databases\MyDB.db;astart=yes"
The following command, however, returns the message Ping database
failed – Database server not running, because Adaptive Server
Anywhere is unable to find a server for MyDB.db:
44
Chapter 3 Connection and Communication Parameters
dbping -d -c "dbf=c:\Databases\MyDB.db;astart=no"
$ For more information, see "The Ping utility" on page 114.
45
Connection parameters
Clients can also specify their own string, which is appended to the generated
string. The AppInfo property string is a sequence of semi-colon-delimited
key=value pairs. The valid keys are as follows:
♦ IP The IP address of the client machine (Unix and NetWare only)
♦ HOST The host name of the client machine
♦ OS The operating system name and version number (for example,
Windows NT 4.0, NetWare 3.12)
♦ PID The process ID of the client (Windows and Unix only)
♦ THREAD The thread ID of the client (Windows and Unix only)
♦ EXE The name of the client executable (Windows and NetWare only)
♦ VERSION The version of the connection protocol in use, including
major and minor values, and a build number (for example 7.0.00.3642)
♦ APPINFO If you specified APPINFO in the connection string, the
string entered
Examples ♦ Connect to the default database from the C++ version of
Interactive SQL:
46
Chapter 3 Connection and Communication Parameters
dbisqlc -c uid=dba;pwd=sql
View the application information:
select connection_property(’appinfo’)
The result is as follows (in a single string):
HOST=machine-name;
OS=Windows NT 4.0;
PID=0x11b;
THREAD=0x102;
VERSION=7.0.00.3642
♦ Connect to the default database from the C++ version of
Interactive SQL, appending your own information to the AppInfo
property:
dbisqlc -c "uid=dba;pwd=sql;app=ISQL connection"
View the application information:
select connection_property(’appinfo’)
The result is as follows (in a single string):
HOST=machine-name;
OS=Windows NT 4.0;
PID=0x10e;
THREAD=0xe1;
VERSION=7.0.00.3642;
APPINFO=ISQL connection
47
Connection parameters
48
Chapter 3 Connection and Communication Parameters
49
Connection parameters
You can set this parameter by entering its value in the Buffer space text box
of the Network tab of the connection window.
The shared memory protocol is used for communication between a client and
server running under the same operating system on the same machine, as is
typical for applications connecting to the personal database server.
50
Chapter 3 Connection and Communication Parameters
51
Connection parameters
Caution
The database file must be on the same machine as the database server.
Managing a database file that is located on a network drive can lead to
file corruption.
52
Chapter 3 Connection and Communication Parameters
53
Connection parameters
Usage Anywhere
Default There is no default data source name.
See also "FileDataSourceName connection parameter" on page 56
Description It is common practice for ODBC applications to send only a data source
name to ODBC. The ODBC driver manager and ODBC driver locate the data
source, which contains the remainder of the connection parameters.
In Adaptive Server Anywhere, Embedded SQL applications can also use
ODBC data sources to store connection parameters.
Examples ♦ The following parameter uses a data source name:
DSN=Dynamo Demo
54
Chapter 3 Connection and Communication Parameters
Description By default, when the database server gets a simple fetch request, the
application asks for extra rows. You can disable this behavior by setting this
parameter to ON.
$ For more information, see "Using cursors in procedures and triggers"
on page 458 of the book ASA User’s Guide.
$ Setting the DisableMultiRowFetch parameter to ON is equivalent to
setting the PREFETCH option to OFF. For more information, see
"Prefetching rows" on page 272 of the book ASA User’s Guide.
Examples ♦ The following connection string fragment prevents prefetching:
DMRF=Yes
55
Connection parameters
Usage Anywhere
Default None
Description Data sources are stored on disk as a file or in the registry. Storing passwords
on disk may present a security problem. For this reason, when you enter a
password into a data source, it is stored in an encrypted form.
If both Password and EncryptedPassword are specified, Password takes
precedence.
Using the -e switch on the dbsrv7 command line encrypts packets for all
clients regardless of whether the Encryption parameter is used at the client.
Similarly, if the client asks for encryption, the server will encrypt.
56
Chapter 3 Connection and Communication Parameters
57
Connection parameters
LTO=60
Alternatively, you can set this parameter by entering its value in the Liveness
timeout text box of the Network tab of the connection window.
58
Chapter 3 Connection and Communication Parameters
59
Connection parameters
60
Chapter 3 Connection and Communication Parameters
61
Network communications parameters
DoBroadcast parameter
Usage TCP/IP, IPX, SPX (Windows 95/98 and NT only)
Description On the client side, with DOBROADCAST=YES, a broadcast is performed to
search for a server if the server is not found in the bindery.
With DOBROADCAST=NO, 0, or OFF, no broadcast is performed to search
for a database server. In this case, you must specify the server host with the
HOST option.
For IPX only, you can also supply an address for the DOBROADCAST
argument. The address serves as a mask for the HOST parameter, and allows
you to specify a non-zero network number. This is intended for use when
broadcasting over a router. The network number is assigned by the network
administrator.
62
Chapter 3 Connection and Communication Parameters
In IPX, a node address consists of six numbers (up to 255 each) and the
network address consists of four digits, separated by colons.
Default Yes
Example ♦ The following command starts a client without broadcasting to search
for a database server. Instead, the server is looked for only on the
computer named silver.
CommLinks=tcpip(DOBROADCAST=NO;HOST=silver) asademo
♦ On an IPX network, the following parameter specifies a broadcast over
network 2:
CommLinks=ipx(dobroadcast=255:255:255:255:255:255/0:
0:0:2)
DLL parameter
Usage TCP/IP, SPX (Windows 95/98, Windows NT)
Description To support untested TCP/IP protocol stacks where the required networking
interface functions are in DLLs that differ from the default protocol stack.
The client or server looks for its required functionality in the named DLLs.
Default ♦ On Windows NT, the default is ws2_32.dll (Winsock 2.0).
♦ On Windows 95/98 the default is wsock32.dll (Winsock 1.1).
Example ♦ The following command starts a server using Winsock 1.1:
dbsrv7 -x tcpip(dll=wsock32.dll) asademo
ExtendedName parameter
Usage IPX (platforms other than Windows 95/98 or NT)
Description According to the Novell standard for legal SAP names, the following
characters are not allowed:
\ / : ; , * ? + -
If you start a server named "asademo-1", the default behavior is to strip out
the - and try to start a server asademo1. By turning on ExtendedName, the
name is left untouched.
63
Network communications parameters
Caution
Users should be wary of using this option as it is contrary to the SAP
standard.
Default No.
Example ♦ The following command starts a NetWare server with name asademo-1.
load dbsrv7.nlm -x ipx(ExtendedName=Yes) asademo-1
MaxLANA parameter
Usage NetBIOS
64
Chapter 3 Connection and Communication Parameters
Description Each path through a NetBIOS protocol stack is assigned a LAN adapter
number. By default, the server looks through all possible numbers up to 255.
To speed up server startup, you can truncate the search for valid LAN
adapters at a specified value using the MAXLANA parameter.
Default 255
Example ♦ The following command line looks only at LAN adapters with numbers
less than 10 to identify active protocol stacks:
dbsrv7 -x netbios(MaxLANA=10) asademo
MyIP parameter
Usage TCP/IP
Description The MyIP parameter is provided for machines with more than one network
adapter.
Each adapter has an IP address. By default, the database server uses the first
network card it finds. If you wish your database server to use more than one
network card, specify the address of each card in the MyIP parameter.
If the keyword NONE is supplied as the IP number, no attempt is made to
determine the addressing information. The NONE keyword is intended for
clients on machines where this operation is expensive, such as machines with
multiple network cards or remote access (RAS) software and a network card.
It is not intended for use on the server.
Under Windows 95/98 or Windows NT, this option can be used multiple
times for machines with multiple IP addresses.
You can optionally append a port number to the IP address, separated by a
colon.
Example ♦ The following command line (entered all on one line) instructs the
server to use two network cards, one with a specified port number.
dbsrv7 -x
tcpip(MyIP=192.75.209.12:2367,192.75.209.32)
c:\asa7\asademo.db
♦ The following connection string fragment instructs the client to make no
attempt to determine addressing information.
Links= tcpip(MyIP=NONE)
65
Network communications parameters
ReceiveBufferSize parameter
Usage TCP/IP
Description Sets the size for a buffer used by the TCP/IP protocol stack. You may want
to increase the value if blob performance over the network is important.
Default Machine-dependent.
SendBufferSize parameter
Usage TCP/IP
Description Sets the size for a buffer used by the TCP/IP protocol stack. You may want
to increase the value if blob performance over the network is important.
Default Machine-dependent.
66
Chapter 3 Connection and Communication Parameters
Description The Internet Assigned Numbers Authority has assigned the Adaptive Server
Anywhere database server port number 2638 to use for TCP/IP
communications. However, applications are not disallowed from using this
reserved port, and this may result in an addressing collision between the
database server and another application.
In the case of the database server, the ServerPort option designates the port
number on which to communicate using TCP/IP.
In a data source, the ServerPort option informs the client of the port or ports
on which database servers are listening for TCP/IP communication. The
client broadcasts to every port that is specified on the ServerPort parameter
to find the server.
The database server always listens on port 2638, even if you specify a
different port using a network communication parameter. Hence,
applications can connect to the database server without specifying a port
number. An exception is the HP-UX operating system, on which the server
does not listen on port 2638 if it is started on another port.
Default 2638
Example 1 Start a network database server:
dbsrv7 -x tcpip -n server1
Port number 2638 is now taken.
2 Attempt to start another database server:
dbsrv7 -x tcpip -n server2
The default port is currently allocated, and so the server starts on another
port.
Sessions parameter
Usage NetBIOS. Server side only.
Description Sets the maximum number of clients that can communicate with the server at
one time through a single LAN adapter. The default setting is operating-
system specific. The value is an integer, with maximum value 254.
NetBIOS network software has a limit to the number of commands allowed
per machine. Adaptive Server Anywhere uses these NetBIOS commands,
and disallows further connections if the system has no more commands
available, even if this is less than the value of the Sessions parameter.
Default Operating system specific. On Windows NT, the default is 16.
67
Network communications parameters
Example ♦ The following statement starts a server with a database named asademo,
allowing 200 NetBIOS connections.
dbsrv7 -x netbios(sessions=200) asademo.db
TDS parameter
Usage TCP/IP, NamedPipes. Server side only.
Description To disallow TDS connections to a database server, set TDS to NO. If you
want to ensure that only encrypted connections are made to your server,
these port options are the only way to disallow TDS connections.
Default YES
Example ♦ The following command starts a database server using the TCP/IP
protocol, but disallowing connections from Open Client or jConnect
applications.
dbsrv7 -x tcpip(TDS=NO) ...
Threads parameter
Usage IPX (Windows 95/98 and Windows NT)
Description THREADS specifies the number of threads that are used for reading network
communications. Integers from one to ten are allowed. It has been found that
two threads produces good performance, but the option is provided as a
performance parameter that you can tune.
Default 2
Example ♦ The following command starts a database server to use the IPX protocol
only, using three threads.
dbsrv7 -x ipx(threads=3) c:\asa7\asademo.db
68
Chapter 3 Connection and Communication Parameters
Example ♦ The following statement places the statistics in the file ipxstat.txt in the
current directory.
dbsrv7 -x ipx(threadstats=ipxstat.txt)
c:\asa7\asademo.db
69
Network communications parameters
On the server side, you can avoid the use of UDP by specifying
DoBroadcast=NO, since the only UDP packets the server uses are to
broadcast to check for other servers with the same name.
Setting UDP=NO also implicitly sets DoBroadcast to NO, since UDP
packets are used for broadcasting.
When specifying UDP=NO, you must specify one or more IP addresses
where the server may be located, using the HOST parameter and the PORT
parameter. Each possible combination of host:port is attempted one at a time
until the requested server name is found.
When using UseUDP in conjunction with the ClientPort option, it is
recommended that multiple ports be supplied to the ClientPort option, for
example:
Examples Restrict the client application to ports 5050 through 5060, disable UDP
packets, and connect to the server named myeng running on the machine at
address myhost using the server port 2020.
Links=tcpip{UDP=no;ClientPort=5050-5060;Host=myhost;Port=2020;Eng=myeng}
70
C H A P T E R 4
About this chapter Adaptive Server Anywhere includes a set of utility programs for backing up
databases and performing other database administration tasks. This chapter
provides reference information for each of the database administration
utilities.
Contents
Topic Page
Administration utilities overview 73
The Backup utility 74
The Collation utility 78
The Compression utility 81
The Console utility 83
The Data Source utility 84
The Erase utility 88
The Information utility 90
The Initialization utility 92
The Interactive SQL utility 99
The License utility 101
The Log Transfer Manager 103
The Log Translation utility 109
The Ping utility 114
The REBUILD utility 115
The Server Location utility 116
The Spawn utility 117
The Stop utility 118
The Transaction Log utility 120
The Uncompression utility 124
The Unload utility 126
71
Administration utilities overview
72
Chapter 4 Database Administration Utilities
73
The Backup utility
74
Chapter 4 Database Administration Utilities
Switch Description
–c "keyword=value; ..." Supply database connection parameters
–d Only back up the main database file
–l file Live backup of the transaction log to a file
–n Change the naming convention for the backup
transaction log
–o filename Log output messages to a file
–q Quiet mode—do not print messages
–r Rename and start a new transaction log
–t Only back up the transaction log
–w Only back up the write file
–x Delete and restart the transaction log
–xo Delete and restart the transaction log without
making a backup
–y Replace files without confirmation
Description If none of the switches -d, -t, or -w are used, all database files are backed
up.
$ For more information about the command-line switches, see "Backup
utility options" on page 75.
75
The Backup utility
Backup main database only (–d) Back up the main database files only,
without backing up the transaction log file or a write file, if one exists.
Log output messages to file (–o) Write output messages to the named
file.
Rename and start new transaction log (–r) This option forces a
checkpoint and the following three steps to occur:
♦ Step 1 The current working transaction log file is copied and saved to
the directory specified in the command line.
76
Chapter 4 Database Administration Utilities
♦ Step 2 The current transaction log remains in its current directory, but
is renamed using the format yymmddxx.log, where xx is a number from
00 to 99 and yymmdd represents the current year, month and day. This
file is then no longer the current transaction log.
♦ Step 3 A new transaction log file is generated that contains no
transactions. It is given the name of the file that was previously
considered the current transaction log, and is used by the database server
as the current transaction log.
Back up the transaction log file only (–t) This can be used as an
incremental backup since the transaction log can be applied to the most
recently backed up copy of the database file(s).
Back up the database write file only (–w) For a description of database
write files, see "The Write File utility" on page 139.
Delete and restart the transaction log (–x) Back up the existing
transaction log, then delete the original log and start a new transaction log.
This option causes the backup to wait for a point when all transactions from
all connections are committed.
Delete and restart the transaction log without a backup (–xo) Delete
the current transaction log and start a new one. This operation does not carry
out a backup; its purpose is to free up disk space in non-replication
environments.
77
The Collation utility
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Create a Custom Collation.
78
Chapter 4 Database Administration Utilities
Switch Description
–c "keyword=value; ..." Supply database connection parameters
–d mapping-file Convert the definition file to INSERT statements
with collation mapping placed in mapping-file
–e Include empty mappings
–o filename Log output messages to a file
–q Quiet mode — do not print messages
–x Use hex for extended characters (7F-FF)
–y Replace the file without confirmation
–z col-seq Specify a collating sequence label
79
The Collation utility
Log output messages to file (–o) Write output messages to the named
file.
Without the –x option, only characters from \x00 to \x1F, \x7F and \xFF are
written in hexadecimal form.
If this option is specified with one of the available collation labels, then
dbcollat does not connect to a database. Otherwise, it connects to a database
and extracts the collation of that database. If the collation label does not
match the collation label of the database, an error is returned.
80
Chapter 4 Database Administration Utilities
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Compress Database.
Switch Description
–o filename Log output messages to a file
–q Quiet mode—do not print messages
–y Replace an existing output file without confirmation
81
The Compression utility
Description The dbshrink utility reads database-file and creates a compressed database
file. The compressed filename defaults to the same name as the original
database file, but with an extension of .cdb. The output filename (with
extension) must not be same as the input filename (with extension).
$ For more information about the command-line switches, see
"Compression utility options" on page 82.
82
Chapter 4 Database Administration Utilities
Switch Description
–c "keyword=value; ..." Supply database connection parameters
83
The Data Source utility
Details-switch Description
–c "keyword=value;…" Supply database connection parameters
–e Encrypt all network packets
–o filename Write client message to filename
–p size Set maximum network packet size
–r Disable multiple record fetching
–s size Set network buffer size
–t1 seconds Client liveness timeout period
–x list List network drivers to run
–z Display debugging information
server-name Connect to named database server
See also "Working with ODBC data sources" on page 47 of the book ASA User’s
Guide
"Using ODBC data sources on UNIX" on page 55 of the book ASA User’s
Guide
84
Chapter 4 Database Administration Utilities
Delete the named data source (–d ) Deletes the named data source.
You are prompted for confirmation unless you modify the instruction with –
y.
List (get) details of the named data source (–g ) List the definition of
the named data source. You can modify the format of the output using the –b
or –v switches.
Create (write) a data source definition (–w) Creates a new data source,
or overwrites one if one of the same name exists. If you supply –y, any
existing data source is overwritten without confirmation.
85
The Data Source utility
The remainder of the details switches are supplied for users familiar with the
dbcli6.exe utility shipped with Adaptive Server Anywhere version 6.
Encrypt network packets (–e) Encrypt packets sent between the client
application and the server.
$ For more information, see "Encryption connection parameter" on
page 56.
Log output messages to file (–o) Write output messages to the named
file. By default, messages are written to the console.
$ For more information, see "Logfile connection parameter" on page 58.
Operate quietly (–q) Do not display output messages. This option is
available only from the command-line utility.
Set maximum network packet size (–p) The maximum packet size for
network communications, in bytes. The value must be greater than 300, and
less than 16000. The default setting is 1024.
$ For more information, see "CommBufferSize connection parameter" on
page 48.
Set network buffer size (–s) Sets the memory for network
communications buffers in kb. The value must be at least 10 and no more
than 1000. The default is 100.
$ For more information, see "CommBufferSpace connection parameter"
on page 49.
Set client liveness timeout (–tl) Terminates connections when they are
no longer intact. The value is in seconds.
The default is server setting, which in turn has a default of 120 seconds.
$ For more information, see "LivenessTimeout connection parameter" on
page 57.
86
Chapter 4 Database Administration Utilities
List all known data sources, one data source name per line:
dbdsn -l
List all data sources along with their associated connection string:
dbdsn -l -b
Report the connection string for data source ASA 7.0 Sample:
dbdsn -g "ASA 7.0 Sample"
Delete the data source BadDSN, but first list the connection parameters for
BadDSN and prompt for confirmation:
dbdsn -d foo -v
Delete the data source BadDSN without prompting for confirmation.
dbdsn -d foo -y
Create a data source named NewDSN for the database server MyServer:
dbdsn -w foo -c "uid=dba;pwd=sql;eng=bar"
If a NewDSN already exists, the previous definition is overwritten.
The following example connects to the sample database server. The server
name sample overrides the previous specified value of MyServer:
dbdsn -w foo -c "uid=dba;pwd=sql;eng=MyServer" sample
List all connection parameter names and their aliases:
dbdsn -cl
87
The Erase utility
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Erase Database.
88
Chapter 4 Database Administration Utilities
Switch Description
–o filename Log output messages to a file
–q Operate quietly—do not print messages
–y Erase files without confirmation
Description The database-file may be a database file, write file, or transaction log file.
The full filename must be specified, including extension. If a database file or
write file is specified, the associated transaction log file (and mirror, if one is
maintained) is also erased.
$ For more information about the command-line switches, see "Erase
utility options" on page 89.
89
The Information utility
Switch Description
–c "keyword=value; ..." Database connection parameters
–o filename Log output messages to a file
–q Operate quietly
–u Output page usage statistics
Description The dbinfo command-line utility allows you to display information about a
database. It reports the time when the database was created, the name of any
transaction log file or log mirror, the page size, and other information.
Optionally, it can also provide table usage statistics and details.
$ For more information about the command-line switches, see
"Information utility options" on page 90.
Log output messages to file (–o) Write output messages to the named
file.
90
Chapter 4 Database Administration Utilities
Page usage statistics (–u) Display information about the usage and size
of all tables, including system and user-defined tables.
You can only request page usage statistics if no other users are connected to
the database.
91
The Initialization utility
v To create a database:
1 Open the Utilities folder in the left panel.
2 Double-click Create Database in the right panel. The Database Creation
wizard appears.
3 Follow the instructions in the wizard.
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Create Database.
92
Chapter 4 Database Administration Utilities
Switch Description
–b Blank padding of strings for comparisons and fetching
–c Case sensitivity for all string comparisons
–e Encrypt the database
–i Do not install Sybase jConnect support
–j Do not install Sybase runtime Java classes
–k Omit Watcom SQL compatibility views SYS.SYSCOLUMNS
and SYS.SYSINDEXES
–l List the available collating sequences
–m file-name Use a transaction log mirror (default is no mirror)
–n No transaction log
–o filename Log output messages to a file
–p page-size Set page size
–q Quiet mode—do not print messages
–t log-name Transaction log filename (default is the database name with .log
extension)
–z col-seq Collation sequence used for comparisons
Description For example, the database test.db can be created with 1024 byte pages as
follows:
dbinit -p 1024 test.db
93
The Initialization utility
’Smith’
’Smith ’
would be treated as equal in a database created with blank-padding.
This option is provided for compatibility with the ISO/ANSI SQL standard,
which is to ignore trailing blanks in comparisons. The default is that blanks
are significant for comparisons.
$ For related information, see "ANSINULL option" on page 160.
Case sensitivity for all string comparisons (–c) For databases created
with this option, all values are considered to be case sensitive in comparisons
and string operations. Identifiers in the database are case insensitive, even in
case sensitive databases.
This option is provided for compatibility with the ISO/ANSI SQL standard.
The default is that all comparisons are case insensitive.
Do not install Sybase jConnect support (–i) If you wish to use the
Sybase jConnect JDBC driver to access system catalog information, you
need to install jConnect support. Use this switch if you wish to exclude the
jConnect system objects. You can still use JDBC, as long as you do not
access system information. If you want, you can add Sybase jConnect
support at a later time using Sybase Central.
Do not install Sybase runtime Java classes (–j) If you wish to use
Java in your database, you must install the Sybase runtime Java classes. By
default, these classes are installed. The runtime classes add several
megabytes to the size of a database, so if you do not intend to use Java
classes, you can specify the -j switch to avoid installing them. If you want,
you can add Sybase runtime Java classes at a later time using Sybase Central.
94
Chapter 4 Database Administration Utilities
List the available collating sequences (–l) dbinit lists the available
collating sequences and then stops. No database is created. The list of
available collating sequences is automatically presented in Sybase Central
Create Database wizard.
Log output messages to file (–o) Write output messages to the named
file.
Page size (–p) The page size for a database can be (in bytes) 1024, 2048,
4096, 8192, 16384, or 32768, with 2048 being the default. Any other value
for the size will be changed to the next larger size.
Large databases usually benefit from a larger page size. For example, the
number of I/O operations required to scan a table is generally lower, as a
whole page is read in at a time. Also, the number of levels in an index may
be reduced as more entries can be stored on each page.
However, there are additional memory requirements for large page sizes.
Also, the maximum number of rows stored on a page is 255, so that tables
with small rows will not fill each page. For example, with 8 kb pages the
average row size must be at least 32 bytes to fully use each page. You should
only use page sizes of 16 kb or 32 kb in productions systems when you can
be sure that a large database server cache is always available, and when you
have investigated the memory and disk space costs and the performance
benefits.
95
The Initialization utility
Set the transaction log filename (–t) The transaction log is a file where
the database server logs all changes, made by all users, no matter what
application system is being used. The transaction log plays a key role in
backup and recovery (see "The transaction log" on page 633 of the book ASA
User’s Guide), and in data replication. If the filename has no path, it is placed
in the same directory as the database file. If you run dbinit without specifying
-t or -n, a transaction log is created with the same filename as the database
file, but with extension .log.
Collating sequence (–z) The collation sequence is used for all string
comparisons in the database.
If you want to create a custom collation, use the Collation utility to create a
file containing the collation. Once you have modified the collation and
inserted it into the appropriate scripts, you use the Initialization utility to
create the database and specify the new collation.
You must change the collation label in the custom collation file. Otherwise,
the Initialization utility prevents the insertion of the new collation, since it
conflicts with an existing collation.
$ For more information on custom collating sequences, see "International
Languages and Character Sets" on page 279 of the book ASA User’s Guide.
For information on the Collation utility, see "The Collation utility" on
page 78.
In order to change the collation that an existing database uses, it is necessary
to unload the database, create a new database using the appropriate collation,
then reload the database. It may be necessary to translate the data as well.
If -z is not specified, the default collation is used. Normal ASCII (binary)
ordering is used for the lower 128 characters, subject to the case sensitivity
setting (-c). For the upper 128 characters (also called the extended
characters), any character that is an accented form of a letter in the lower 128
are sorted to the same position as the unaccented form. The determination of
whether or not an extended character is an accented letter is based upon code
page 850 (multilingual code page).
The following table identifies the available collating sequence labels.
96
Chapter 4 Database Administration Utilities
97
The Initialization utility
98
Chapter 4 Database Administration Utilities
Switch Description
–c "keyword=value; ..." Supply database connection parameters
–datasource dsn-name Specify an ODBC data source to connect to.
–host hostname Specify the hostname or IP address of the machine
running a database server.
–nogui Run in command-prompt mode.
–ODBC
–port portnumber
–q Quiet mode—no windows or messages
–x Syntax check only—no commands executed
Description Interactive SQL provides the user with an interactive environment for
database browsing and for sending SQL statements to the database server.
Interactive SQL allows you to type SQL commands, or run command files. It
also provides feedback about the number of rows affected, the time required
for each command, the execution plan of queries, and any error messages.
If dbisql-command is specified, Interactive SQL executes the command. You
can also specify a command file name. If no dbisql-command is specified,
SQL enters interactive mode, where you can type a command into a
command window.
Switches –c Specify connection parameters. See "Connection parameters" on
page 60 of the book ASA User’s Guide for a description of the connection
parameters. If Interactive SQL cannot connect, you are presented with a
dialog where you can enter the connection parameters.
–ODBC Connect using the JDBC/ODBC bridge. If you do not specify this
option, Interactive SQL connects using jConnect.
99
The Interactive SQL utility
–port Specify the port number on which the database server is running.
The default port number for Adaptive Server Anywhere is 2638.
–x Scan commands but do not execute them. This is useful for checking
long command files for syntax errors.
$ For or detailed descriptions of SQL statements and Interactive SQL
commands, see "SQL Language Elements" on page 207.
Examples ♦ The following command, entered at a system prompt, runs the command
file mycom.sql against the current default server, using the user ID DBA
and the password SQL.
dbisql -c "uid=DBA;pwd=SQL" mycom.sql
♦ The following command, when entered on a single line at a system
prompt, adds a user to the current default database:
dbisql -c "uid=DBA;pwd=SQL" grant connect to joe identified by passwd
100
Chapter 4 Database Administration Utilities
Switch Description
–l type License type. Allowed values are perseat or
concurrent
–o filename Log output messages to a file
–p operating-system Target operating system. Allowed values are
NetWare, UNIX, WIN32, WINNT
–q Operate quietly—do not print messages
–u license-number Total number of users for license
Description The dblic command-line utility adds licensed users to your network database
server. You must only use this utility in accordance with your Sybase license
agreement, to license the number of users to which you are entitled. Running
this command does not grant you license.
Repeated running of the dblic command updates the license information.
Switches License type (–l) Enter the license type that matches the licensing model
described in your software license agreement. Valid entries are perseat and
concurrent.
Log output messages to file (–o) Write output messages to the named
file.
Operating system (–p) Enter the operating system for which you are
licensed. Allowed values are as follows:
♦ NetWare Novell NetWare operating system.
♦ UNIX A UNIX operating system.
♦ WIN32 Windows 95/98 or Windows CE operating system.
♦ WINNT Windows NT operating system.
Executable name Enter the path and file name of the network database
server executable (dbsrv6.exe) you are licensing. The path can be relative.
101
The License utility
User name A user name for the license. This name appears on the
database server window on startup. If there are spaces in the name, enclose it
in double quotes.
Company name The company name for the license. This name appears
on the database server window on startup. If there are spaces in the name,
enclose it in double quotes.
Example The following command, executed in the same directory as the database
server executable, applies a license for 50 concurrent users, in the name of
"Sys Admin", for company "My Co", to a Windows NT network database
server. The command must be entered all on one line:
dblic -l concurrent -p WINNT -u 50 dbsrv6.exe "Sys
Admin" "My Co"
The following message appears on the screen to indicate the success of the
license:
Licensed nodes: 50
User: Sys Admin
Company: My Co
102
Chapter 4 Database Administration Utilities
Description The Log Transfer Manager (LTM) is also known as a replication agent.
The LTM is required for any Adaptive Server Anywhere database that
participates in a Replication Server installation as a primary site. The
Adaptive Server Anywhere LTM reads a database transaction log and sends
committed changes to Replication Server. The LTM is not required at
replicate sites.
The LTM sends messages to Replication Server in a language named Log
Transfer Language (LTL).
By default, the LTM uses a log file named DBLTM.LOG to hold status and
other messages. You can use the command-line options to change the name
of this file and to change the volume and type of messages that are sent to it.
Switches Use configuration file (–C) Use the configuration file config_file to
determine the LTM settings. The default configuration file is dbltm.cfg. The
format of the configuration file is described in "The LTM configuration file"
on page 105.
103
The Log Transfer Manager
Use interface file (–I) (Upper case i.) Use the named interfaces file. The
interfaces file is the file, created by SQLEDIT (or sybinit on NetWare),
which holds the connection information for Open Servers. The default
interfaces file is sql.ini in the ini subdirectory of your Sybase directory. On
NetWare, the default interfaces file is named interfaces.
Specify LTM name (–S) Provides the server name for this LTM. The
default LTM_name is DBLTM_LTM. The LTM_name must correspond to
the Open Server name for the LTM that was entered in SQLEDIT.
Do not filter updates (–A) Do not filter updates. By default, all changes
made by the maintenance user are not replicated. If the -A switch is set, these
changes are replicated. This may be useful in non-hierarchical Replication
Server installations, where a database acts as both a replicate site and as a
primary site.
Recover mode (–M) This is used to initiate recovery actions. The LTM
starts reading logs from the earliest available position. If the offline directory
is specified in the configuration file, the LTM reads from the oldest offline
log file.
Log output messages to file (–o) Use a log file different from the
default (dbltm.log). Write output messages from log transfer operations to
this file.
Limit size of output file (–os) Specify the maximum size of the output
file, in bytes. The minimum value is 10000 (ten thousand). If the log file
grows to the point where it would exceed this limit, it is renamed to
yymmdd00.log, and a new file named yymmdd01.log is started. The value of
nn in yymmddnn.log is incremented for each file on a given day.
Truncate log file and use named log file (–ot) Use a log file different
from the default (dbltm.log), and truncate the log file (all existing content is
deleted) when the LTM starts. Output messages from log transfer operations
are sent to this file for later review.
Operate quietly (–q) Minimize the window when the LTM is started.
Log all LTL commands (–s) Log all LTL commands that are generated
by the LTM. This should be used only to diagnose problems, and is not
recommended in a production environment. It carries a significant
performance penalty.
104
Chapter 4 Database Administration Utilities
Run as a daemon (–ud) You can run the LTM as a daemon on UNIX
operating systems. If you run in this manner, output is logged to the log file.
Parameter Description
APC_pw The password for the APC_user login name. This
entry is present only in Adaptive Server
Anywhere LTM configuration files.
APC_user A user ID that is used when executing
asynchronous procedures at the primary site.
This user ID must have permissions appropriate
for all asynchronous procedures at the primary
site. This entry is present only in Adaptive Server
Anywhere LTM configuration files.
backup_only By default, this is off. If set to on, the LTM will
replicate only backed-up transactions.
batch_ltl_cmds Set to on (the default) to use batch mode. Batch
mode can increase overall throughput, but may
lead to longer response times.
batch_ltl_sz The number of commands that are saved in the
buffer before being sent to Replication Server,
when batch_ltl_cmds is on. The default is 200.
batch_ltl_mem The amount of memory that the buffer can use
before its contents are sent to Replication Server,
when batch_ltl_cmds is on. The default is
256 kb.
105
The Log Transfer Manager
Parameter Description
continuous By default, this is on. When set to off, the LTM
automatically shuts down as soon as all
committed data has been replicated.
LTM_admin_pw The password for the LTM_admin_user login
name.
LTM_admin_user The system administrator LTM login name that
is used to log in to the LTM. This parameter is
required so that the LTM can check whether a
user logging on to the LTM to shut it down has
the correct login name.
LTM_charset The Open Client/Open Server character set for
the LTM to use.
LTM_language The Open Client/Open Server language for the
LTM to use.
LTM_sortorder The Open Client/Open Server sort order for the
LTM to use to compare user names. You can
specify any Adaptive Server Enterprise-
supported sort order that is compatible with the
LTM’s character set. All sort orders in your
replication system should be the same.
The default sort order is a binary sort.
maint_cmds_to_skip [ ignored ]
rep_func Set to on to use asynchronous procedure calls
(APCs). The default is off.
retry The number of seconds to wait before retrying a
failed connection to an Adaptive Server
Anywhere database server or Replication Server.
The default is 10 seconds.
RS The name of the Replication Server to which the
LTM is transferring the log.
RS_pwd The password for the RS_user login name.
RS_source_db The name of the database whose log the LTM
transfers to the Replication Server. This name
must match the name of the database as defined
within the Replication Server connection
definitions. Most configurations use the same
setting for both RS_Source_db and
SQL_database configuration options.
RS_source_ds The name of the server whose log the LTM
transfers to the Replication Server. This name
must match the name of the server as defined
within the Replication Server connection
106
Chapter 4 Database Administration Utilities
Parameter Description
definitions. Most configurations use the same
setting for both RS_Source_ds and SQL_server
configuration options.
RS_user A login name for the LTM to use to log into
Replication Server. The login name must have
been granted connect source permission in the
Replication Server.
scan_retry The number of seconds that the LTM waits
between scans of the transaction log. This
parameter is somewhat different in meaning to
that of the Adaptive Server Enterprise LTM. The
Adaptive Server Anywhere server does not
"wake up" and scan the log when records arrive
in the log. For this reason, you may wish to set
the scan_retry value to a smaller number then
that for an Adaptive Server Enterprise LTM.
skip_ltl_cmd_err [ ignored ]
SQL_database The primary site database name on the server
SQL_server to which the LTM connects. For
Adaptive Server Enterprise during recovery, this
is the temporary database whose logs the LTM
will transfer to Replication Server. The Adaptive
Server Anywhere LTM uses the SQL_log_files
parameter to locate offline transaction logs.
SQL_log_files A directory that holds off-line transaction logs.
The directory must exist when the LTM starts up.
This entry is present only in Adaptive Server
Anywhere LTM configuration files.
SQL_pw The password for the SQL_user user ID.
SQL_server The name of the primary site Adaptive Server
Anywhere server to which the LTM connects.
For Adaptive Server Enterprise during recovery,
this is a data server with a temporary database
whose logs the LTM will transfer to Replication
Server. The LTM uses the SQL_log_files
parameter to locate offline transaction logs.
SQL_user The login name that the LTM uses to connect to
the database specified by RS_source_ds and
RS_source_db.
107
The Log Transfer Manager
108
Chapter 4 Database Administration Utilities
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Translate Log.
Switch Description
–a Include uncommitted transactions
–c "keyword=value; ..." Supply database connection parameters. Cannot be
used with a transaction log name.
–d Display output in chronological order
–f Output only since the last checkpoint
109
The Log Translation utility
Switch Description
–g Include audit records in output
–id destination,... Include only rows intended for the specified
destinations
–ir offset1,offset2 Include only the portion of the log between the two
specified offsets
–is source,... Include only rows originating from the specified
sources
–it user.table,... Include only operations on specified tables by
specifying a comma-delimited list of user.table
–j date/time Output from the last checkpoint prior to the given time
–n filename Output SQL file, when used against a database server
–o filename Log output messages to a file
–q Run quietly, do not print messages
–r Remove uncommitted transactions (default)
–rsu username,... Override default Replication Server user names
–s Produce ANSI standard SQL UPDATE transactions
–sr Generate SQL Remote comments
–t Include trigger-generated transactions in output
–u userid,... Translate transactions for listed users only
–x userid,... Exclude transactions for listed users
–y Replace file without confirmation
–z Include trigger-generated transactions as comments
only
transaction-log Log file to be translated. Cannot be used together with
–c or -n
sql-file Output file containing the translated information. For
use with transaction-log only
Description The dbtran utility takes the information in a transaction log and places it as a
set of SQL statements and comments into an output file. The utility can be
run in the following ways:
♦ Against a database server Run in this way, the utility is a standard
client application. It connects to the database server using the connection
string specified following the -c option, and places output in a file
specified with the -n option. DBA authority is required to run in this
way.
110
Chapter 4 Database Administration Utilities
♦ Against a transaction log file Run in this way, the utility acts directly
against a transaction log file. You should protect your transaction log
file from general access if you wish to prevent users from having the
capability of running this statement.
dbtran asademo.log asademo.sql
When the dbtran utility runs, it displays the earliest log offset in the
transaction log. This can be an effective method for determining the order in
which multiple log files were generated.
$ For more information about the command-line switches, see "Log
translation utility options" on page 111
Output from last checkpoint only (–f) Only transactions that were
completed since the last checkpoint are output.
111
The Log Translation utility
Include offset range (–ir) Isolate a portion of the transaction log between
two specified offsets.
Output from the last checkpoint prior to a given date (–j) Only
transactions from the most recent checkpoint prior to the given date and/or
time are translated. The user-provided argument can be a date, time or date
and time enclosed in quotes. If the time is omitted, the time is assumed to be
the beginning of the day. If the date is omitted, the current day is assumed.
The following is an acceptable format for the date and time: "YY/MMM/DD
HH:NN".
Output file (–n) When you run the dbtran command-line utility against a
database server, use this option to specify the output file that holds the SQL
statements.
Log output messages to file (–o) Write output messages to the named
file.
112
Chapter 4 Database Administration Utilities
Generate ANSI standard SQL UPDATE (–s) If the switch is not used,
and there is no primary key or unique index on a table, the Translation utility
generates UPDATE statements with a non-standard FIRST keyword in case
of duplicate rows. If the switch is used, the FIRST keyword is omitted for
compatibility with the SQL standard.
Output transactions for listed users only (–u) This switch allows you
to limit the output from the transaction log to include only specified users.
Output transactions except for listed users (–x) This switch allows
you to limit the output from the transaction log to exclude specified users.
113
The Ping utility
Switch Description
–c "keyword=value; ..." Database connection parameters
–d Make a database connection if the server is found
–o filename Log output messages to a file
–q Operate quietly—do not print messages
Make database connection (–d) Ping the database, not just the server.
If you do not supply the -d switch, then dbping reports success if it finds the
server specified by the -c switch. If you do supply the -d switch, then
dbping reports success only if connects to the server and also connect to a
database.
For example, if you have a server named blair running the database sample,
the following succeeds:
dbping -c "eng=blair;dbn=sample"
The following command fails, with the message Ping database failed --
specified database not found:
dbping -d -c "eng=blair;dbn=sample"
Log output messages to file (–o) Write output messages to the named
file.
114
Chapter 4 Database Administration Utilities
115
The Server Location utility
Switch Description
–o filename Log output messages to a file
–q Operate quietly—do not print messages
Description The dblocate command-line utility locates any Adaptive Server Anywhere
database servers running over TCP/IP on the immediate network. It prints a
list of database servers and their addresses.
Depending on your network, the utility may take several seconds before
printing its results.
Switches Log output messages to file (–o) Write output messages to the named
file.
116
Chapter 4 Database Administration Utilities
Switch Description
–f Do not check for a running server
–q Quiet mode—do not print messages
117
The Stop utility
Switch Description
–c "keyword=value; ..." Connection parameters
–o filename Log output messages to a file
–q Quiet mode—do not print messages
–x Do not stop if there are active connections
–y Stop without prompting even if there are active
connections
Description Command-line options let you control whether a server is stopped even if
there are active connections.
$ For more information about the command-line switches, see "Stop
utility options" on page 118.
118
Chapter 4 Database Administration Utilities
Log output messages to file (–o) Write output messages to the named
file.
Operate quietly (–q) Do not print a message if the database was not
running.
Do not stop if there are active connections (–x) Do not stop the server
if there are still active connections to the server.
Stop without prompting (–y) Stop the server even if there are still active
connections to the server.
Examples To stop a database named asademo on the server myserver:
dbstop -c "uid=DBA;pwd=SQL;eng=myserver;dbn=asademo"
To stop a server myserver, regardless of the databases running:
dbstop -c "uid=DBA;pwd=SQL;eng-myserver;dbn=utility_db"
119
The Transaction Log utility
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Change Log File Information.
120
Chapter 4 Database Administration Utilities
Switch Description
–g n Sets the LTM generation number to n
–il Ignores the LTM truncation offset stored in the
database
–ir Ignores the SQL Remote truncation offset stored
in the database
–m mirror-name Set transaction log mirror name
–n No longer use a transaction log or mirror log
–o filename Log output messages to a file
–q Quiet mode—do not print messages
–r No longer use a transaction log mirror
–t log-name Set the transaction log name
–x n Set the transaction log current relative offset to n
–z n Set the transaction log starting offset to n
Description The dblog command line utility allows you to display or change the name of
the transaction log or transaction log mirror associated with a database. You
can also stop a database from maintaining a transaction log or mirror, or start
maintaining a transaction log or mirror.
The utility displays additional information about the transaction log,
including the following:
♦ Version number
♦ Starting offset, for use in replication
♦ Ending offset, for use in replication
♦ Page size
♦ Total number of pages
♦ Number of empty pages
♦ Percentage of the log file in use
$ For more information about the command-line switches, see
"Transaction log utility options" on page 122.
121
The Transaction Log utility
Set the name of the transaction log mirror file (–m) This option sets a
filename for a new transaction log mirror. If the database is not currently
using a transaction log mirror, it starts using one. If the database is already
using a transaction log mirror, it changes to using the new file as its
transaction log mirror.
No longer use a transaction log (–n) Stop using a transaction log, and
stop using a mirror log. Without a transaction log, the database can no longer
participate in data replication or use the transaction log in data recovery.
Log output messages to file (–o) Write output messages to the named
file.
No longer use a transaction log mirror (–r) For databases that maintain
a mirrored transaction log, this option changes their behavior to maintain
only a single transaction log.
Set the name of the transaction log file (–t) This option sets a filename
for a new transaction log. If the database is not currently using a transaction
log, it starts using one. If the database is already using a transaction log, it
changes to using the new file as its transaction log.
122
Chapter 4 Database Administration Utilities
Set the current log offset (–x) For use when reloading a SQL Remote
consolidated database. This option resets the current log offset so that the
database can take part in replication.
$ For information on how to use this option, see "Unloading and
reloading a consolidated database" on page 488 of the book Replication and
Synchronization Guide.
Set the starting log offset (–z) For use when reloading a SQL Remote
consolidated database. This option resets the starting log offset so that the
database can take part in replication.
$ For information on how to use this option, see "Unloading and
reloading a consolidated database" on page 488 of the book Replication and
Synchronization Guide.
123
The Uncompression utility
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Uncompress Database.
Switch Description
–o filename Log output messages to a file
–q Operate quietly—do not print messages
–y Erase an existing output file without confirmation
Description The input filename extension defaults to cdb. The output filename (with
extension) must not have the same name as the input filename (with
extension).
124
Chapter 4 Database Administration Utilities
125
The Unload utility
126
Chapter 4 Database Administration Utilities
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Unload Database.
Switch Description
–ac "keyword=value; ..." Supply connection parameters for the reload
–an database Creates a database file with the same settings as the
database being unloaded, and automatically reloads
it
–ar directory Rebuild and replace database
–c "keyword=value; ..." Supply database connection parameters for unload
–d Unload data only
–e table,... Do not unload listed tables
–ii Internal unload, internal reload (default)
–ix Internal unload, external reload
–j nnn Repeated unload of view creation statements
–n No data—schema definition only
127
The Unload utility
Switch Description
–o filename Log output messages to a file
–p char Escape character for external unloads (default "\")
–q Quiet mode—no windows or messages
–r reload-file Specify name and directory of generated reload
Interactive SQL command file (default reload.sql)
–t table,... Unload only the listed tables
–u Unordered data. Do not use indexes to unload data.
–v Verbose messages
–xi External unload, internal reload
–xx External unload, external reload
–y Replace the command file without confirmation
directory The directory where the unloaded data is to be
placed. Not needed for -an or -ac
Description In the default mode, or if -ii or -xx is used, the directory used by dbunload
to hold the data is relative to the database server, not to the current directory
of the user. For details of how to supply a filename and path in this mode,
see "UNLOAD TABLE statement" on page 619.
If the -x, -xi, or -xx is used, the directory is relative to the current directory
of the user.
The reload.sql command file is always relative to the current directory of the
user.
If no list of tables is supplied, the whole database is unloaded. If a list of
tables is supplied, only those tables are unloaded.
$ For more information about the command-line switches, see "Unload
utility options" on page 128.
$ There are special considerations for unloading databases involved in
replication. For information, see "Unloading and reloading a consolidated
database" on page 488 of the book Replication and Synchronization Guide.
Typically, you would create a new database using the Initialization utility,
and then reload it using this switch. This method is useful when you want to
change the initialization options, such as page size, or collation.
For example, the following command (which should be entered all on one
line) loads a copy of the asademo.db database into an existing database file
named newdemo.db:
dbunload -c "uid=dba;pwd=sql;dbf=asademo.db" -ac
"uid=dba;pwd=sql;dbf=newdemo.db"
If you use this option, no interim copy of the data is created on disk, so you
do not specify an unload directory on the command line. This provides
greater security for your data, but at some cost for performance.
Create a database for reloading (–an) You can combine the operations
of unloading a database, creating a new database, and loading the data using
this option.
Typically, you would use this switch when you do not want to change the
initialization option of your database. The options specified when you
created the source database are used to create the new database.
For example, the following command (which should be entered all on one
line) creates a new database file named asacopy.db and copies the schema
and data of asademo.db into it:
dbunload -c "uid=dba;pwd=sql;dbf=asademo.db" -an
asacopy.db
If you use this option, no interim copy of the data is created on disk, so you
do not specify an unload directory on the command line. This provides
greater security for your data, but at some cost for performance.
Rebuild and replace database (–ar) This option creates a new database
with the same settings as the old database, reloads it, and replaces the old
database. If you use this option, there can be no other connections to the
database, and the database connection must be local, not over a network.
If you specify directory, the transaction log offsets are reset for replication
purposes, and the transaction log from the old database is moved to the
specified directory. The named directory should be the directory that holds
the old transaction logs used by the Message Agent and the Replication
Agent. The transaction log management is handled only if the database is
used in replication: if there is no SQL Remote publisher or LTM check, then
the old transaction log is not needed and is deleted instead of being copied to
the specified directory.
$ For more information on transaction log management, see "Backup
methods for remote databases in replication installations" on page 642 of the
book ASA User’s Guide.
129
The Unload utility
Unload data only (–d) With this option, none of the database definition
commands are generated (CREATE TABLE, CREATE INDEX, and so on);
reload.sql contains statements to reload the data only.
No data output for listed tables (–e) This switch is accessible only from
the command-line utility. If you wish to unload almost all of the tables in the
database, the -e command-line switch unloads all tables except the specified
tables.
Use internal unload, internal reload (–ii) This switch uses the
UNLOAD statement to extract data from the database, and uses the LOAD
statement in the reload.sql file to repopulate the database with data. This is
the default.
Use internal unload, external reload (–ix) This switch uses the
UNLOAD statement to extract data from the database, and uses the
Interactive SQL INPUT statement in the reload.sql file to repopulate the
database with data.
130
Chapter 4 Database Administration Utilities
Unload schema definition only (–n) With this option, none of the data
in the database is unloaded; reload.sql contains SQL statements to build the
structure of the database only.
Log output messages to file (–o) Write output messages to the named
file.
Escape character (–p) The default escape character (\) for external
unloads (dbunload -x switch) can be replaced by another character, using this
option. This option is available only from the command-line utility.
Specify reload filename (–r) Modify the name and directory of the
generated reload Interactive SQL command file. The default is reload.sql in
the current directory. The directory is relative to the current directory of the
client application, not the server.
Output unordered data (–u) Normally, the data in each table is ordered
by the primary key. Use this option if you are unloading a database with a
corrupt index, so that the corrupt index is not used to order the data.
Enable verbose mode (–v) The table name of the table currently being
unloaded, and how many rows have been unloaded, appears. This option is
available only from the command-line utility.
Use external unloading, internal reload (–xi) This switch uses the
Interactive SQL OUTPUT statement to extract data from the database, and
uses the LOAD statement in the generated reload command file, reload.sql,
to repopulate the database with data.
Use external unloading, external reload (–xx) This switch uses the
Interactive SQL OUTPUT statement to extract data from the database, and
uses the Interactive SQL INPUT statement in the generated reload command
file, reload.sql, to repopulate the database with data.
131
The Unload utility
132
Chapter 4 Database Administration Utilities
v To upgrade a database:
1 Open the Utilities folder in the left panel.
2 Double-click Upgrade Database in the right panel. The Upgrade
Database wizard appears.
3 Follow the instructions in the wizard.
Upgrading databases that are too old for the Upgrade utility
133
The Upgrade utility
2 Create a database with the name you wish to use for the upgraded
version, using the Initialization utility.
3 Connect to the new database from Interactive SQL as the DBA user ID,
and read the reload.sql command file to build the new database.
You can also use the dbunload command-line utility to directly rebuild.
Switch Description
–c "keyword=value; ..." Supply database connection parameters
–i Do not install Sybase jConnect support
–j Do not install Sybase runtime Java classes
–o filename Log output messages to a file
–q Quiet mode—no windows or messages
134
Chapter 4 Database Administration Utilities
Do not install Sybase jConnect support (–i) If you wish to use the
Sybase jConnect JDBC driver to access system catalog information, you
need to install jConnect support. Use this option if you wish to exclude the
jConnect system objects. You can still use JDBC, as long as you do not
access system information. If you want, you can add Sybase jConnect
support later using Sybase Central.
Do not install Sybase runtime Java classes (–j) If you wish to use
Java in your database, you must install the Sybase runtime Java classes. By
default, these classes are installed when a database is upgraded to Version 6.
The runtime classes add several megabytes to the size of a database. If you
do not intend to use Java classes, you can specify the -j switch to avoid
installing these classes. If you want, you can add Sybase runtime Java classes
later using Sybase Central.
Log output messages to file (–o) Write output messages to the named
file.
135
The Validation utility
v To validate a database:
1 Open the Utilities folder.
2 Double-click Validate Database.
3 Follow the instructions in the wizard.
136
Chapter 4 Database Administration Utilities
Tip
For validating database, you can also access this wizard by clicking
Tools➤Adaptive Server Anywhere➤Validate Database.
Switch Description
object-name The name of a table or (if -i is used) an index to
validate
–c "keyword=value; ..." Supply database connection parameters
–o filename Log output messages to a file
–f Validate tables with full check
–fd Validate tables with data check
–fi Validate tables with index check
–i Each object-name is an index
–q Quiet mode—do not print messages
–t Each object-name is a table
Description With the command line Validation utility, you can validate the indexes and
keys on some or all of the tables in the database. This utility scans the entire
table, and confirms that each row in the table exists in the appropriate
indexes. It is equivalent to running the VALIDATE TABLE statement on
each table.
$ For information on specific checks made during validation, see
"VALIDATE TABLE statement" on page 628.
$ For more information about the command-line switches, see
"Validation utility options" on page 137.
137
The Validation utility
For example, the following validates the sample database, connecting as user
DBA with password SQL:
dbvalid -c "uid=DBA;pwd=SQL;dbf=c:\asa6\asademo.db"
Data check for each table (–fd) In addition to the default validation
checks, check that all of each LONG BINARY, LONG VARCHAR, TEXT,
or IMAGE data type can be read. This corresponds to the WITH DATA
CHECK option on the VALIDATE TABLE statement. Depending on the
contents of your database, this option may significantly extend the time
required to validate.
Full check for each table (–f) In addition to the default validation
checks, carry out both data checks (-fd) and index checks (-fi). This
corresponds to the WITH FULL CHECK option on the VALIDATE TABLE
statement. Depending on the contents of your database, this option may
significantly extend the time required to validate.
Index check for each table (–fi) In addition to the default validation
checks, validate each index on the table. This corresponds to the WITH
INDEX CHECK option on the VALIDATE TABLE statement. Depending
on the contents of your database, this option may significantly extend the
time required to validate.
Log output messages to file (–o) Write output messages to the named
file.
138
Chapter 4 Database Administration Utilities
v You can access the write file utility in the following ways:
♦ From Sybase Central
♦ From the system command line, using the dbwrite command-line utility.
This is useful for incorporating into batch or command files.
The Write File utility runs against a database file. The database must not be
running on a server when you run the Write File utility.
The database file cannot be modified after the write file is created, otherwise
the write file becomes invalid.
Tip
You can also access this wizard by clicking Tools➤Adaptive Server
Anywhere➤Create Write File.
139
The Write File utility
Switch Description
–c Create a new write file
–d database-file Point a write file to a different database
–f database-file Force the write file to point at a file
–m mirror-name Set the transaction log mirror name
–o filename Log output messages to a file
–q Quiet mode—do not print messages
–s Report the write file status only
–t log-name Set the transaction log name
–y Erase old files without confirmation
Description If any changes are made to the original database (not using the write file), the
write file will no longer be valid. This happens if you start the server using
the original database file, so you should create your write file from an
archived copy of a database.
If a write file becomes invalid, you can discard all of your changes and create
a new write file with the following command.
dbwrite -c db-name write-name
The log-name and mirror-name parameters are used only when creating a
new write file. The write-name parameter is used only with the -c and -d
parameters. Note that the database_file parameter must be specified before
the write-name parameter.
$ For more information about the command-line switches, see "Write file
utility options" on page 140.
140
Chapter 4 Database Administration Utilities
Change the database file to which an existing write file points (–d)
If a database file is moved to another directory, or renamed, this option
allows you to maintain the link between the write file and the database file.
This option is available only from the command-line utility.
Force a write file to point to a file (–f) This option is available only
from the command-line utility. This option is for use when a write file is
being created and the database file is held on a Novell NetWare or other
network path, for operating systems on which they cannot be entered
directly. By providing the full Novell path name for the database file (for
example: SYS:\asademo.db), you can avoid dependencies on local mappings
of the NetWare path. Unlike with the –d option, no checking is done on the
specified path.
Set mirror name (–m) Set the name of the transaction log mirror file.
This can only be used in conjunction with-c.
Log output messages to file (–o) Write output messages to the named
file.
Report the write file status only (–s) This displays the name of the
database to which the write file points. This option is available only from the
command-line utility.
Set the transaction log filename (–t) If you are creating a new write file
(-c), you can use this switch to set the name of the transaction log file.
141
The Write File utility
142
C H A P T E R 5
Database Options
About this chapter This chapter describes the database and Interactive SQL options that can be
set to customize and modify database behavior.
Contents
Topic Page
Introduction to database options 144
General database options 149
Transact-SQL and SQL/92 compatibility options 151
Replication options 154
Interactive SQL options 155
Alphabetical list of options 157
143
Introduction to database options
Setting options
You set options with the SET OPTION statement. It has the following
general syntax:
SET [ EXISTING ] [ TEMPORARY ] OPTION
... [ userid. | PUBLIC. ]option-name = [ option-value ]
Specify a user ID or group name to set the option for that user or group only.
Every user belongs to the PUBLIC group. If no user ID or group is specified,
the option change is applied to the currently logged on user ID that issued the
SET OPTION statement.
For example, the following statement applies an option change to the user
DBA, if DBA is the user that issues it:
SET OPTION login_mode = mixed
The following statement applies a change to the PUBLIC user ID, a user
group to which all users belong.
SET OPTION Public.login_mode = standard
Caution
Changing option settings while fetching rows from a cursor is not
supported, because it can lead to ill-defined behavior. For example,
changing the DATE_FORMAT setting while fetching from a cursor would
lead to different date formats among the rows in the result set. Do not
change option settings while fetching rows.
144
Chapter 5 Database Options
145
Introduction to database options
146
Chapter 5 Database Options
Option classification
Adaptive Server Anywhere provides many options. It is convenient to divide
them into a few general classes. The classes of options are:
♦ "General database options" on page 149
♦ "Transact-SQL and SQL/92 compatibility options" on page 151
♦ "Replication options" on page 154
♦ "Interactive SQL options" on page 155
147
Introduction to database options
148
Chapter 5 Database Options
149
General database options
150
Chapter 5 Database Options
Option Setting
ALLOW_NULLS_BY_DEFAULT OFF
ANSI_BLANKS ON
ANSINULL OFF
CHAINED OFF
CONTINUE_AFTER_RAISERROR ON
DATE_FORMAT YYYY-MM-DD
DATE_ORDER MDY
ESCAPE_CHARACTER OFF
FLOAT_AS_DOUBLE ON
ISOLATION_LEVEL 1
ON_TSQL_ERROR CONDITIONAL
QUOTED_IDENTIFIER OFF
TSQL_VARIABLES ON
TSQL_HEX_CONSTANT ON
TIME_FORMAT HH:NN:SS.SSS
TIMESTAMP_FORMAT YYYY-MM-DD HH:NN:SS.SSS
151
Transact-SQL and SQL/92 compatibility options
List of options The following table lists the compatibility options, their allowed values, and
their default settings.
152
Chapter 5 Database Options
153
Replication options
Replication options
The following options are included to provide control over replication
behavior. Some replication options are useful for SQL Remote replication,
and some are relevant for use with Sybase Replication Server.
154
Chapter 5 Database Options
155
Interactive SQL options
156
Chapter 5 Database Options
ALLOW_NULLS_BY_DEFAULT option
Function Controls whether new columns that are created without specifying either
NULL or NOT NULL are allowed to contain NULL values.
Allowed values ON, OFF
Default ON
OFF for Open Client and JDBC connections
Description The ALLOW_NULLS_BY_DEFAULT option is included for Transact-SQL
compatibility.
$ For more information, see "Setting options for Transact-SQL
compatibility" on page 943 of the book ASA User’s Guide.
ANSI_BLANKS option
Function Controls behavior when character data is truncated at the client side.
Allowed values ON, OFF
Default OFF
ON for Open Client and JDBC connections
Description The ANSI_BLANKS option has no effect unless the database was created
with the -b command-line option. It forces a truncation error whenever a
value of data type CHAR(N) is read into a C char(M) variable for values of N
greater than or equal to M. With ANSI_BLANKS set to OFF, a truncation
error occurs only when at least one non-blank character is truncated.
For Embedded SQL, if ANSI_BLANKS is ON when you supply a value of
data type DT_STRING, you must set the sqllen field to the length of the
value, including space for the terminating null character. With
ANSI_BLANKS off, the length is determined solely by the position of the
null character.
The ANSI_BLANKS setting persists for the life of a connection. Changing it
after a connection has been established does not affect that connection.
157
Alphabetical list of options
ANSI_CLOSE_CURSORS_ON_ROLLBACK option
Function Controls whether cursors that were opened WITH HOLD are closed when a
ROLLBACK is performed.
Allowed values ON, OFF
Default OFF
Description The draft SQL/3 standard requires all cursors be closed when a transaction is
rolled back. By default, on a rollback Adaptive Server Anywhere closes only
those cursors that were opened without a WITH HOLD clause. This option
allows you to force closure of all cursors.
The CLOSE_ON_ENDTRANS option overrides the
ANSI_CLOSE_CURSORS_ON_ROLLBACK option.
ANSI_INTEGER_OVERFLOW option
Function Controls what happens when an arithmetic expression causes an integer
overflow error.
Allowed values ON, OFF
Default OFF
Description The ISO SQL/92 standard requires integer overflow should result in an
SQLSTATE = 22003 - overflow error. Adaptive Server Anywhere behavior
was previously different from this. The ANSI_INTEGER_OVERFLOW
option can be set to OFF to maintain compatibility with previous releases of
the software.
ANSI_PERMISSIONS option
Function Controls permissions checking for DELETE and UPDATE statements.
Allowed values ON, OFF
Scope Can be set for the PUBLIC group only. Takes effect immediately. DBA
authority is required to set this option.
Default ON
Description With ANSI_PERMISSIONS ON, the SQL/92 permissions requirements for
DELETE and UPDATE statements are checked. The default value is OFF in
Adaptive Server Enterprise. The following table outlines the differences.
158
Chapter 5 Database Options
The ANSI_PERMISSIONS option can be set only for the PUBLIC group.
No private settings are allowed.
ANSI_UPDATE_CONSTRAINTS option
Function Controls the range of updates that are permitted.
Allowed values OFF, CURSORS, STRICT
Default CURSORS in new databases.
OFF in databases created before version 7.0.
Description Adaptive Server Anywhere provides several extensions that allow updates
which are not permitted by the ANSI SQL standard. These extensions
provide powerful, efficient mechanisms for performing updates. However, in
some cases, they cause behavior that is not intuitive. This behavior can
produce anomalies such as lost updates if the user application is not designed
to expect the behavior of these extensions.
The ANSI_UPDATE_CONSTRAINTS option controls whether updates are
restricted to those permitted by the SQL/92 standard.
If the option is set to STRICT, the following updates are prevented:
♦ Updates of cursors containing JOINS
159
Alphabetical list of options
ANSINULL option
Function Controls the interpretation of = and != with NULL values.
Allowed values ON, OFF
Default ON
Description With ANSINULL ON, any comparisons with NULL using = or != are
unknown.
Also, aggregate functions on columns that contain NULL values cause the
warning ’null value eliminated in aggregate function’ (SQLSTATE=01003).
Setting ANSINULL to OFF allows comparisons with NULL to yield results
that are not unknown, for compatibility with Adaptive Server Enterprise, and
turns off the warning.
AUDITING option
Function Enables and disables auditing in the database.
Allowed values ON, OFF
Scope Can be set for the PUBLIC group only. Takes effect immediately. DBA
permissions are required to set this option.
Default OFF
Description This option switches auditing on and off.
Auditing is the recording of detailed information about many events in the
database in the transaction log. Auditing provides some security features, at
the cost of some performance.
Example ♦ Turn on auditing
160
Chapter 5 Database Options
AUTOMATIC_TIMESTAMP option
Function Controls interpretation of new columns with the TIMESTAMP data type.
Allowed values ON, OFF
Default OFF
161
Alphabetical list of options
Description Controls whether any new columns with the TIMESTAMP data type that do
not have an explicit default value defined are given a default value of the
Transact-SQL timestamp value as a default. The
AUTOMATIC_TIMESTAMP option is included for Transact-SQL
compatibility. The default is OFF.
$ For more information, see "Setting options for Transact-SQL
compatibility" on page 943 of the book ASA User’s Guide.
BACKGROUND_PRIORITY option
Function To limit impact on the performance of connections other than the current
connection.
Allowed values ON or OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
If you set this option temporarily, that setting applies to the current
connection only. Different connections under the same user ID can have
different settings for this option.
Default OFF
Description When set to ON, it requests that the current connection have minimal impact
on the performance of other connections. This option allows tasks for which
responsiveness is critical to coexist with other tasks for which performance is
not as important.
BLOB_THRESHOLD option
Function Controls the size of value that the Message Agent treats as a long object
(blob).
162
Chapter 5 Database Options
BLOCKING option
Function Controls the behavior in response to locking conflicts.
Allowed values ON or OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default ON
Description If BLOCKING is ON, any transaction attempting to obtain a lock that
conflicts with an existing lock held by another transaction waits until every
conflicting lock is released. At that time, the write goes through. If
BLOCKING is OFF, the transaction that attempts to obtain a conflicting lock
receives an error.
$ For more information, see "Two-phase locking" on page 410 of the
book ASA User’s Guide.
CHAINED option
Function Controls transaction mode in the absence of a BEGIN TRANSACTION
statement.
Allowed values ON, OFF
Default ON
OFF for Open Client and JDBC connections
163
Alphabetical list of options
For all other prefixes, translation is turned on. When the option is set to
DETECT, Interactive SQL displays a message in the status window
indicating the collation label and the display translation setting.
164
Chapter 5 Database Options
CHECKPOINT_TIME option
Function Set the maximum number of minutes that the database server will run
without doing a checkpoint.
Allowed values Integer
Scope Can be set only for the PUBLIC group. DBA authority is required to set the
option. You must shut down and restart the database server for the change to
take effect.
Default 60
Description This option is used with the "RECOVERY_TIME option" on page 195 to
decide when checkpoints should be done.
$ For information on checkpoints, see "Checkpoints and the checkpoint
log" on page 650 of the book ASA User’s Guide.
CIS_ROWSET_SIZE option
Function Set the number of rows that are returned from remote servers for each fetch.
Allowed values Integer
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect when a new connection is made to a remote server.
Default 50
Description This option sets the ODBC FetchArraySize value when using ODBC to
connect to a remote database server.
CLOSE_ON_ENDTRANS option
Function Controls the closing of cursors at the end of a transaction.
Allowed values ON, OFF
Default ON
Description When CLOSE_ON_ENDTRANS is set to ON, cursors are closed whenever
a transaction is committed unless the cursor was opened WITH HOLD. The
behavior when a transaction is rolled back is governed by the
ANSI_CLOSE_CURSORS_AT_ROLLBACK option.
165
Alphabetical list of options
COMPRESSION option
Function Set the level of compression for SQL Remote messages.
Allowed values Integer, from -1 to 9
166
Chapter 5 Database Options
Default 6
Description The values have the following meanings:
♦ -1 Send messages in Version 5 format. Message Agents (both
dbremote and ssremote) from previous versions of SQL Remote cannot
read messages sent in Version 6 format. You should ensure that
COMPRESSION is set to -1 until all Message Agents in your system are
upgraded to Version 6.
♦ 0 No compression.
♦ 1 to 9 Increasing degrees of compression. Creating messages with
high compression can take longer than creating messages with low
compression.
CONTINUE_AFTER_RAISERROR option
Function Controls behavior following a RAISERROR statement.
Allowed values ON, OFF
Default ON
Description
Deprecated option
This option is deprecated in favor of the ON_TSQL_ERROR option.
$ For more information, see "ON_TSQL_ERROR option" on
page 189.
167
Alphabetical list of options
Intermediate RAISERROR statuses and codes are lost after the procedure
terminates. If, at return time, an error occurs along with the RAISERROR,
then the information for the new error is returned and the RAISERROR
information is lost. The application can query intermediate RAISERROR
statuses by examining the @@error global variable at different execution
points.
CONVERSION_ERROR option
Function Controls the reporting of data type conversion failures on fetching
information from the database.
Allowed values ON, OFF
Default ON
Description This option controls whether data type conversion failures, when data is
fetched from the database or inserted into the database, are reported by the
database as errors (CONVERSION_ERROR set to ON) or as a warning
(CONVERSION_ERROR set to OFF).
If conversion errors are reported as warnings only, the NULL value is used
in place of the value that could not be converted. In Embedded SQL, an
indicator variable is set to -2 for the column or columns that cause the error.
COOPERATIVE_COMMITS option
Function Controls when commits are written to disk.
Allowed values ON or OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default ON
Description If COOPERATIVE_COMMITS is set to OFF, a COMMIT is written to disk
as soon as the database server receives it, and the application is then allowed
to continue.
168
Chapter 5 Database Options
COOPERATIVE_COMMIT_TIMEOUT option
Function Governs when a COMMIT entry in the transaction log is written to disk.
Allowed values Integer, in milliseconds
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 250
Description This option has meaning only when COOPERATIVE_COMMITS is set to
ON. The database server waits for the specified number of milliseconds for
other connections to fill a page of the log before writing to disk. The default
setting is 250 milliseconds.
DATE_FORMAT option
Function Sets the format for dates retrieved from the database.
Allowed values String
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default ’YYYY-MM-DD’. This corresponds to ISO date format specifications.
169
Alphabetical list of options
Symbol Description
yy Two digit year
yyyy Four digit year
mm Two digit month, or two digit minutes if following a colon(as in
hh:mm)
mmm[m...] Character short form for months—as many characters as there are
m's
d Single digit day of week, (0 = Sunday, 6 = Saturday)
dd Two digit day of month
ddd[d...] Character short form for day of the week
hh Two digit hours
nn Two digit minutes
ss[.ss..] Seconds and parts of a second
aa AM or PM (12 hour clock)
pp PM if needed (12 hour clock)
jjj Day of the year, from 1 to 366
Each symbol is substituted with the appropriate data for the date that’s being
formatted. Any format symbol that represents character rather than digit
output can be put in upper case which causes the substituted characters to
also be in upper case. For numbers, using mixed case in the format string
suppresses leading zeros.
You can control the padding of numbers by changing the case of the
symbols. Same-case symbols (MM, mm, DD, dd) all pad number with
zeroes. Mixed case (Mm, mM, Dd, or dD) cause the number to not be zero
padded: the value takes as much room as required. For example
SELECT dateformat( ’1998/01/01’, ’yyyy/Mm/Dd’)
returns the following value:
1998/1/1
Examples ♦ The following table illustrates DATE_FORMAT settings, together with
the output from the following statement, executed on Thursday May 21,
1998
SELECT CURRENT DATE
170
Chapter 5 Database Options
DATE_ORDER option
Function Controls the interpretation of date formats.
Allowed values ’MDY’, ’YMD’, or ’DMY’
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default YMD. This corresponds to ISO date format specifications.
For Open Client and JDBC connections, the default is set to MDY.
Description The database option DATE_ORDER is used to determine whether 10/11/12
is Oct 11 1912, Nov 12 1910, or Nov 10 1912. The option can have the value
’MDY’, ’YMD’, or ’DMY’.
DEFAULT_TIMESTAMP_INCREMENT option
Function Specifies the number of microseconds to add to a column of type
TIMESTAMP in order to keep values in the column unique.
Allowed values Integer
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 1
Description Since a TIMESTAMP value is precise to six decimal places in Adaptive
Server Anywhere, by default 1 microsecond (0.000001 of a second) is added
to differentiate between two identical TIMESTAMP values.
Some software, such as Microsoft Access, truncates TIMESTAMP values to
three decimal places, making valid comparisons a problem. Setting this value
to a larger number, such as 0.001 of a second (an option value of 1000),
alleviates this problem.
171
Alphabetical list of options
DELAYED_COMMITS option
Function Determines when the server returns control to an application following a
COMMIT.
Allowed values ON or OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default OFF. This corresponds to ISO COMMIT behavior.
Description When set to ON, the database server replies to a COMMIT statement
immediately instead of waiting until the transaction log entry for the
COMMIT has been written to disk. When set to OFF, the application must
wait until the COMMIT is written to disk.
When this option is ON, the log is written to disk when the log page is full or
according to the DELAYED_COMMIT_TIMEOUT option setting,
whichever is first. There is a slight chance that a transaction may be lost even
though committed if a system failure occurs after the server replies to a
COMMIT, but before the page is written to disk. Setting
DELAYED_COMMITS to ON, and the DELAYED_COMMIT_TIMEOUT
option to a high value, promotes a quick response time at the cost of security.
If both COOPERATIVE_COMMITS and DELAYED_COMMITS are set to
ON, and if the COOPERATIVE_COMMIT_TIMEOUT interval passes
without the pages getting written, the application is resumed (as if the
commit had worked), and the remaining interval
(DELAYED_COMMIT_TIMEOUT -
COOPERATIVE_COMMIT_TIMEOUT) is used as a
DELAYED_COMMIT interval, after which the pages will be written, even if
they are not full.
DELAYED_COMMIT_TIMEOUT option
Function Determines when the server returns control to an application following a
COMMIT.
Allowed values Integer, in milliseconds.
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 500
172
Chapter 5 Database Options
Description This option has meaning only when DELAYED_COMMITS is set to ON. it
governs when a COMMIT entry in the transaction log is written to disk.
With DELAYED_COMMITS set to ON, the database engine waits for the
number of milliseconds set in the DELAYED_COMMIT_TIMEOUT option
for other connections to fill a page of the log before writing the current page
contents to disk.
$ For more information, see "DELAYED_COMMITS option" on
page 172.
DELETE_OLD_LOGS option
Function Controls whether transaction logs are deleted when their messages have been
replicated.
Allowed values ON, OFF
Default OFF
Description This option is used by SQL Remote and by the Adaptive Server Anywhere
Replication Agent. The default setting is OFF. When it is set to ON, the
Message Agent (DBREMOTE) deletes each old transaction log when all the
changes it contains have been sent and confirmed as received.
DIVIDE_BY_ZERO_ERROR option
Function Controls the reporting of division by zero.
Allowed values ON, OFF
173
Alphabetical list of options
Default ON
Description This option indicates whether division by zero is reported as an error. If the
option is set ON, then division by zero results in an error with SQLSTATE
22012.
If the option is set OFF, division by zero is not an error. Instead, a NULL is
returned.
ESCAPE_CHARACTER option
This option is reserved for system use. Do not change the setting of this
option.
EXTENDED_JOIN_SYNTAX option
Function Controls whether queries with an ambiguous syntax for multi-table joins are
allowed, or reported as an error.
Allowed values ON, OFF
Default ON
Description This option reports a syntax error for those queries containing outer joins that
have ambiguous syntax due to the presence of duplicate correlation names on
a null-supplying table.
The following join clause illustrates the kind of query that is reported.
( R left outer join T , T join S on ( C1 ) )
where C1 is a condition. If the option is set to ON, this query is interpreted as
follows.
( R left outer join T on ( C1 ) ) join S on ( C2 )
174
Chapter 5 Database Options
FIRE_TRIGGERS option
Function Controls whether triggers are fired in the database.
Allowed values ON, OFF
Default ON
Description When set to ON, triggers are fired. When set to OFF, no triggers are fired,
including referential integrity triggers (such as cascading updates and
deletes). Only a user with DBA authority can set this option. The option is
overridden by the -gf command-line option, which turns off all trigger firing
regardless of the FIRE_TRIGGERS setting.
FLOAT_AS_DOUBLE option
Function Controls the interpretation of the FLOAT keyword.
Allowed values ON, OFF
Default OFF
ON for Open Client and JDBC connections
Description The FLOAT_AS_DOUBLE option makes the FLOAT keyword behave like
Adaptive Server Enterprise’s FLOAT keyword when a precision is not
specified.
When enabled (set to ON), all occurrences of the keyword FLOAT are
interpreted as equivalent to the keyword DOUBLE within SQL statements.
175
Alphabetical list of options
REAL values are four bytes; DOUBLE values are eight bytes. According to
the ANSI SQL/92 specification, FLOAT can be interpreted based on the
platform. It is up to the database to decide what size the value is, so long as it
can handle the necessary precision. Adaptive Server Enterprise and Adaptive
Server Anywhere exhibit different default behavior.
The FLOAT_AS_DOUBLE option takes effect only when no precision is
specified. For example, the following statement is not affected by the option
setting:
create table t1(
c1 float(5)
)
The following statement is affected by the option setting:
create table t2(
c1 float)
// affected by option setting
GLOBAL_DATABASE_ID option
Function For use in generating unique primary keys in a replication environment.
Controls the beginning of the range of values for columns created with
DEFAULT GLOBAL AUTOINCREMENT.
Allowed values Integer
Default 0
Scope PUBLIC setting only. Takes effect when the database is next started.
See also "CREATE TABLE statement" on page 453
"Database-level properties" on page 1070
"Ensuring unique primary keys" on page 357 of the book Replication and
Synchronization Guide
Description If you create a column with DEFAULT GLOBAL AUTOINCREMENT, its
value is incremented starting from the value of GLOBAL_DATABASE_ID.
A setting of 0 (the default) indicates that GLOBAL DEFAULT
AUTOINCREMENT is disabled, and NULL is generated as a default.
You can find the value of the option in the current database using the
following statement:
select db_property( ’GlobalDBId’ )
You need to shut down and restart the database when you change this option
for it to take effect.
176
Chapter 5 Database Options
177
Alphabetical list of options
178
Chapter 5 Database Options
179
Alphabetical list of options
Example ♦ Set the field separator to a colon in the data exported to c:\employee.txt.
SET TEMPORARY OPTION ISQL_FIELD_SEPARATOR=’:’;
SELECT emp_lname, emp_fname FROM employee WHERE
emp_id < 150;
OUTPUT TO c:\employee.txt FORMAT ASCII
This code places the following data in employee.txt:
’Cobb’:’Matthew’
’Chin’:’Philip’
’Jordan’:’Julie’
The start and end characters (in this case, single quotation marks)
depend on the ISQL_QUOTE setting.
180
Chapter 5 Database Options
Description After you execute a SQL statement in Interactive SQL, the optimizer
provides information in the Messages pane about how it optimized the
execution. To determine the amount of information displayed, you can
choose one of three plans: NONE provides no information; SHORT provides
basic information; LONG provides detailed information.
You can specify whether the time of execution is included with any of these
plans by setting the "ISQL_COMMAND_TIMING option" on page 178.
You can also specify a plan on the Messages page of the Options dialog.
ISOLATION_LEVEL option
Function Controls the locking isolation level.
Allowed values 0, 1, 2, or 3
181
Alphabetical list of options
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 0
1 for Open Client and JDBC connections
Description This option controls the locking isolation level as follows.
♦ 0 Allow dirty reads, nonrepeatable reads, and phantom rows.
♦ 1 Prevent dirty reads. Allow nonrepeatable reads and phantom rows.
♦ 2 Prevent dirty reads and guarantee repeatable reads. Allow phantom
rows.
♦ 3 Serializable. Do not allow dirty reads, guarantee repeatable reads,
and do not allow phantom rows.
$ For more information, see "Isolation levels and consistency" on
page 374 of the book ASA User’s Guide.
JAVA_HEAP_SIZE option
Function To limit the memory used by Java applications for a connection.
Allowed values Integer
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately. DBA permissions are required to set this option for any
connection.
Default 1000000
Description This option sets the maximum size (in bytes) of the memory that is allocated
to Java applications on a per-connection basis. Per-connection memory
allocations typically consist of the user’s working set of allocated Java
variables and Java application stack space.
While a Java application is executing on a connection, the per-connection
allocations come out of the fixed cache of the database server, so it is
important that a run-away Java application is prevented from using up too
much memory.
JAVA_INPUT_OUTPUT option
Function To enable file access from Java in the database
182
Chapter 5 Database Options
JAVA_NAMESPACE_SIZE option
Function To limit the memory used by Java applications for a connection.
Allowed values Integer
Scope Can be set only for the PUBLIC group. Takes effect immediately.
Default 4000000
Description This option sets the maximum size (in bytes) of the memory that is allocated
to Java applications on a per-database basis.
Per-database memory allocations include Java class definitions. Because
class definitions are effectively read-only, they are shared between
connections. Consequently, their allocations come right out of the fixed
cache, and this option sets a limit on the size of these allocations.
LOGIN_MODE option
Function Controls the use of integrated logins for the database.
Allowed values Standard, Mixed, or Integrated
Scope Can be set only for the PUBLIC group. Takes effect immediately.
Default Standard
Description This option specifies whether integrated logins are permitted. The following
values are accepted (the values are case insensitive):
♦ Standard This is the default setting, which does not permit integrated
logins. An error occurs if an integrated login connection is attempted.
183
Alphabetical list of options
♦ Mixed With this setting, both integrated logins and standard logins are
allowed.
♦ Integrated With this setting, all logins to the database must be made
using integrated logins.
Caution
Setting the LOGIN_MODE database option to Integrated restricts
connections to only those users who have been granted an
integrated login mapping. Attempting to connect with a user ID
and password generates an error. The only exceptions to this are
users with DBA authority (full administrative rights).
LOGIN_PROCEDURE option
Function A login procedure that sets connection compatibility options at startup. By
default the procedure calls the sp_login_environment procedure to determine
which options to set.
Allowed values String
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default sp_login_environment
Description This login procedure calls the sp_login_environment procedure at run time to
determine the database connection settings.
You can customize the default database option settings by creating a new
procedure and setting LOGIN_PROCEDURE to call the new procedure. You
should not edit either sp_login_procedure or sp_tsql_environment.
MAX_CURSOR_COUNT option
Function A resource governor to limit the maximum number of cursors that a
connection can use at once.
Allowed values Integer
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately. DBA permissions are required to set this option for any
connection.
184
Chapter 5 Database Options
Default 50
Description This resource governor allows a DBA to limit the number of cursors per
connection that a user can use. If an operation would exceed the limit for a
connection, an error is generated, indicating that the governor for the
resource has been exceeded.
If a connection executes a stored procedure, that procedure is executed under
the permissions of the procedure owner. However, the resources used by the
procedure are assigned to the current connection.
You can remove resource limits by setting the option to 0 (zero).
MAX_HASH_SIZE option
Function Specify the default maximum hash size for new indexes.
Allowed values Integer, from 2 to 64 inclusive.
Scope Can be set for the PUBLIC group only. Takes effect immediately. DBA
permissions are required to set this option.
Default 10
See also "CREATE INDEX statement" on page 435
"CREATE TABLE statement" on page 453
Description This option controls the default hash size for indexes. For performance
implications, see "How indexes work" on page 795 of the book ASA User’s
Guide.
MAX_WORK_TABLE_HASH_SIZE option
Function Specify the maximum hash size used during query optimization for internal
temporary tables.
Allowed values Integer, from 2 to 64 inclusive.
Scope Can be set for the PUBLIC group only. Takes effect immediately. DBA
permissions are required to set this option.
Default 20
"Temporary tables used in query processing" on page 802 of the book ASA
See also
User’s Guide.
185
Alphabetical list of options
Description In general, you should not need to use this option, as the query optimizer
allocates hash sizes for the internal temporary tables based on the data
distribution within the table. The option allows you to override the optimizer
behavior to either increase the maximum hash size it can use beyond 20, or
to restrict it further.
MAX_STATEMENT_COUNT option
Function A resource governor to limit the maximum number of prepared statements
that a connection can use at once.
Allowed values Integer
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately. DBA permissions are required to set this option for any
connection.
Default 50
Description This resource governor allows a DBA to limit the number of prepared
statements per connection a user can use. If an operation would exceed the
limit for a connection, an error is generated, indicating that the governor for
the resource has been exceeded.
If a connection executes a stored procedure, that procedure is executed under
the permissions of the procedure owner. However, the resources used by the
procedure are assigned to the current connection.
You can remove resource limits by setting the option to 0 (zero).
MIN_PASSWORD_LENGTH option
Function Sets the minimum length for new passwords in the database.
Allowed values Integer, greater than or equal to zero.
The value is in bytes. For single-byte character sets, this is the same as the
number of characters.
Scope Can be set for the PUBLIC group. Takes effect immediately. DBA
permissions are required to set this option.
Default 0 characters
Description This option allows the database administrator to impose a minimum length
on all new passwords for greater security. Existing passwords are not
affected.
186
Chapter 5 Database Options
NEAREST_CENTURY option
Function Controls the interpretation of two-digit years, in string-to-date conversions.
Allowed values Integer between 0 and 100
Default 50 for databases created with Version 6 or later.
0 for databases created with Version 5.5 or earlier.
Description This option controls the handling of two-digit years, when converting from
strings to dates or timestamps.
The NEAREST_CENTURY setting is a numeric value that acts as a rollover
point. Two digit years less than the value are converted to 20yy, while years
greater than or equal to the value are converted to 19yy.
NON_KEYWORDS option
Function Turns off individual keywords, allowing their use as identifiers.
Allowed values String
Default The empty string.
Description This option turns off individual keywords, or all keywords introduced since a
specific release of the product. This provides a way of ensuring that
applications created with older versions of the product are not broken by new
keywords. If you have an identifier in your database that is now a keyword,
you can either add double quotes around the identifier in all applications or
scripts, or turn off the keyword using the NON_KEYWORDS option.
In addition to specifying individual keywords, you can turn off all keywords
since a specified release, using one of the following special values in the list
of keywords:
keywords_4_0_d, keywords_4_0_c, keywords_4_0_b,
keywords_4_0_a, keywords_4_0, keywords_5_0_01,
keywords_5_0
187
Alphabetical list of options
188
Chapter 5 Database Options
ON_TSQL_ERROR option
Function Controls error-handling in stored procedures.
Allowed values String. See below for allowed values.
Default CONDITIONAL
See also "CREATE PROCEDURE statement" on page 440
"CREATE PROCEDURE statement" on page 447
"Transact-SQL procedure language overview" on page 954 of the book ASA
User’s Guide
Description This option controls error handling in stored procedures.
♦ STOP Stop execution immediately upon finding an error.
♦ CONDITIONAL If the procedure uses ON EXCEPTION RESUME,
and the statement following the error handles the error, continue,
otherwise exit.
♦ CONTINUE Continue execution, regardless of the following statement.
If there are multiple errors, the first error encountered in the stored
procedure is returned. This option most closely mirrors Adaptive Server
Enterprise behavior.
This option deprecates CONTINUE_AFTER_RAISERROR as a way of
simulating Adaptive Server Enterprise behavior for stored procedures.
OPTIMIZATION_GOAL option
Function Determines whether query processing is optimized towards returning the first
row quickly, or minimizing the cost of returning the complete result set.
Allowed values first-row or all-rows
Default first-row
189
Alphabetical list of options
190
Chapter 5 Database Options
♦ DBASEIII The output is a dBASE III format file with the column
definitions at the top of the file. Note that a maximum of 128 columns
can be output. Also, note that columns longer than 255 characters will be
truncated in the file.
♦ DIF The output is a file in the standard Data Interchange Format.
♦ FIXED The output is fixed format, with each column having a fixed
width. The width for each column can be specified using the COLUMN
WIDTH clause. If this clause is omitted, the width for each column is
computed from the data type for the column, and is large enough to hold
any value of that data type. No column headings are output in this
format.
♦ FOXPRO The output is a FoxPro format file (the FoxPro memo field is
different than the dBASE memo field) with the column definitions at the
top of the file. Note that a maximum of 128 columns can be output.
Also, note that columns longer than 255 characters will be truncated in
the file.
♦ LOTUS The output is a Lotus WKS format worksheet. Column names
will be put as the first row in the worksheet. Note that there are certain
restrictions on the maximum size of Lotus WKS format worksheets that
other software (such as Lotus 1-2-3) can load. There is no limit to the
size of file Interactive SQL can produce.
♦ SQL The output is an Interactive SQL INPUT statement required to
recreate the information in the table.
♦ TEXT The output is a TEXT format file, which prints the results in
columns with the column names at the top and vertical lines separating
the columns. This format is similar to that used to display data in the
Interactive SQL data window.
♦ WATFILE The output is a WATFILE format file, with the column
definitions at the top of the file.
191
Alphabetical list of options
PERCENT_AS_COMMENT option
Function Controls the interpretation of the percent character.
Allowed values ON, OFF
Default ON
Description It is recommended that you not use % as a comment marker.
Versions of this product before Version 6 treated the percent character (%) in
SQL statements exclusively as a comment delimiter. Since Version 5,
alternative comment markers such as //, /* */, and -- (double dash) have been
available. The double-dash style is the SQL/92 comment delimiter.
Adaptive Server Enterprise treats % as a modulo operator and does not
support the Adaptive Server Anywhere mod function. Writing a statement
that works in both environments and performs a modulo operation was
previously impossible.
The PERCENT_AS_COMMENT option controls the meaning of %. The
default setting is ON, for backwards compatibility. You can set the option to
OFF for compatibility with Adaptive Server Enterprise.
Procedures, triggers and views that were created with %-style comments are
converted to double-dash comments when they are stored in the catalog.
192
Chapter 5 Database Options
The Sybase Central code editor does not highlight %-style comments. If you
wish to have your comments highlighted in the Sybase Central editor, you
should use one of the other comment delimiters.
PRECISION option
Function Specifies the maximum number of digits in the result of any decimal
arithmetic.
Allowed values Integer, with a maximum of 127
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 30
Description Precision is the total number of digits to the left and right of the decimal
point. The "SCALE option" on page 198 specifies the minimum number of
digits after the decimal point when an arithmetic result is truncated to the
maximum PRECISION.
Multiplication, division, addition, subtraction, and aggregate functions can
all have results that exceed the maximum precision.
For example, when a DECIMAL(8,2) is multiplied with a DECIMAL(9,2),
the result could require a DECIMAL(17,4). If PRECISION is 15, only 15
digits will be kept in the result. If SCALE is 4, the result will be a
DECIMAL(15,4). If SCALE is 2, the result will be a DECIMAL(15,2). In
both cases, there is a possibility of overflow.
PREFETCH option
Function The PREFETCH option acts as a toggle allowing you to turn fetching on and
off.
Allowed values ON, OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default ON
193
Alphabetical list of options
Description This option controls whether rows are fetched to the client side in advance of
being made available to the client application. Fetching a number of rows at
a time, even when the client application requests rows one at a time (for
example, when looping over the rows of a cursor) cuts down on response
time and improves overall throughput by cutting down the number of
requests to the database.
The setting of PREFETCH is ignored by Open Client and JDBC
connections.
QUALIFY_OWNERS option
Function Controls whether SQL statements being replicated by SQL Remote should
use qualified object names.
Allowed values ON, OFF
Default The default in Adaptive Server Anywhere is ON. The default in Adaptive
Server Enterprise is OFF.
Description Qualifying owners in Adaptive Server Enterprise setups is rarely needed
because it is common for objects to be owned by dbo. When qualification is
not needed in Adaptive Server Anywhere setups, messages will be slightly
smaller with the option OFF.
QUERY_PLAN_ON_OPEN option
Function Controls whether a plan is returned when a cursor is opened.
Allowed values ON, OFF
Default OFF
Description In early versions of the software, each time an OPEN was done on a cursor,
the server would return in the SQLCA sqlerrmc field a string representing
the query plan (limited to 70 bytes). A more complete description can be
obtained using the EXPLAIN statement or the PLAN function. For this
reason, computing and returning the query plan on an OPEN is needed only
for compatibility with old applications. The QUERY_PLAN_ON_OPEN
option controls whether the plan is returned on an OPEN. By default, the
setting is OFF.
194
Chapter 5 Database Options
QUOTE_ALL_IDENTIFIERS option
Function Controls whether SQL statements being replicated by SQL Remote should
use quoted identifiers
Allowed values ON, OFF
Default OFF
Description When this option is off, dbremote quotes identifiers that require quotes by
Adaptive Server Anywhere (as it has always done) and ssremote does not
quote any identifiers.
When the option is on, all identifiers are quoted.
QUOTED_IDENTIFIER option
Function Controls the interpretation of strings that are enclosed in double quotes.
Allowed values ON, OFF
Default ON
OFF for Open Client and JDBC connections
Description This option controls whether strings that are enclosed in double quotes are
interpreted as identifiers (ON) or as literal strings (OFF). The
QUOTED_IDENTIFIER option is included for Transact-SQL compatibility.
Sybase Central sets QUOTED_IDENTIFER temporarily to ON if it is set to
OFF. A message is displayed informing you of this change. The change is in
effect only for the Sybase Central connection.
$ For more information, see "Setting options for Transact-SQL
compatibility" on page 943 of the book ASA User’s Guide.
RECOVERY_TIME option
Function Sets the maximum length of time, in minutes, that the database server will
take to recover from system failure.
Allowed values Integer, in minutes
Scope Can be set only for the PUBLIC group. Takes effect when server is restarted.
Default 2
195
Alphabetical list of options
Description This option is used with the "CHECKPOINT_TIME option" on page 165 to
decide when checkpoints should be done.
ROW_COUNTS option
Function Specifies whether the database will always count the number of rows in a
query when it is opened.
Allowed values ON, OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default OFF
Description If this option is set to OFF, the row count is usually only an estimate. If this
option is set to ON, the row count is always accurate. Opening queries may
take significantly longer.
REPLICATE_ALL option
Function Allows an entire database to act as a primary site in a Replication Server
setup.
Allowed values ON, OFF
Default OFF
Description This option is used by the LTM only. When it is set to ON, the entire
database is set to act as a primary site in a Replication Server installation. All
changes to the database are sent to Replication Server by the LTM.
REPLICATION_ERROR option
Function For SQL Remote, allows you to specify a stored procedure to be called by
the Message Agent when a SQL error occurs.
Allowed values Stored procedure name.
196
Chapter 5 Database Options
Default No procedure
Description For SQL Remote, the REPLICATION_ERROR option allows you to specify
a stored procedure to be called by the Message Agent when a SQL error
occurs. By default no procedure is called.
The procedure must have a single argument of type CHAR, VARCHAR, or
LONG VARCHAR. The procedure is called once with the SQL error
message and once with the SQL statement that causes the error.
Although the option allows you to track and monitor SQL errors in
replication, you must still design them out of your setup; this option is not
intended to resolve such errors.
RETURN_JAVA_AS_STRING option
Function To control how a Java object is passed to the client application when queried.
Allowed values ON, OFF
Scope Can be set for as a temporary option only, for the duration of the current
connection.
Default OFF
Description The option indicates how a Java object is returned to applications connecting
over Open Client or jConnect.
By default, a Java object is returned over TDS as a Sun serialization of the
object. The client, or receiver of the object serialization, is responsible for
deserializing the object into an instance.
If Return_java_as_string is set to ON, the object is first converted to an
instance of java.lang.String using the toString() method, and the String
object is returned to the client.
RI_TRIGGER_TIME option
Function Controls the relative timing of referential integrity checks and trigger actions.
Allowed values BEFORE, AFTER
Scope Can be set for the PUBLIC option only. DBA authority is required to set this
option.
Default AFTER
197
Alphabetical list of options
Description The option can be set to either BEFORE or AFTER. When it’s set to AFTER,
referential integrity actions are executed after the UPDATE or DELETE.
Only the PUBLIC setting can be used; any other setting is ignored.
SCALE option
Function Specifies the minimum number of digits after the decimal point when an
arithmetic result is truncated to the maximum PRECISION.
Allowed values Integer, with a maximum of 127.
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default 6
Description Multiplication, division, addition, subtraction, and aggregate functions can
all have results that exceed the maximum precision. See "PRECISION
option" on page 193 for an example.
SQL_FLAGGER_ERROR_LEVEL option
Function Controls the response to any SQL that is not part of a specified set of
SQL/92.
Allowed values E, I, F, or W
Default W
Description This option flags any SQL that is not part of a specified set of SQL/92 as an
error.
198
Chapter 5 Database Options
SQL_FLAGGER_WARNING_LEVEL option
Function Controls the response to any SQL that is not part of a specified set of
SQL/92.
Allowed values E, I, F, or W
Default W
Description This option flags any SQL that is not part of a specified set of SQL/92 as a
warning.
199
Alphabetical list of options
STRING_TRUNCATION option
Function Determines whether an error is raised when an INSERT or UPDATE
truncates a CHAR or VARCHAR string.
Allowed values ON, OFF
Default OFF
Description If the truncated characters consist only of spaces, no exception is raised. The
setting of ON corresponds to ANSI/ISO SQL/92 behavior. When it is set to
OFF, the exception is not raised and the character string is silently truncated.
SUBSCRIBE_BY_REMOTE option
Function Controls interpretation of NULL or empty-string SUBSCRIBE BY values.
Allowed values ON, OFF
Default ON
Description When the option is set to ON, operations from remote databases on rows
with a SUBSCRIBE BY value that is NULL or an empty string assume that
the remote user is subscribed to the row. When it is set to OFF, the remote
user is assumed not to be subscribed to the row.
THREAD_COUNT option
Function Historical
Allowed values Integer
Default Not applicable
Description This option is now ignored by the server. For Version 6 you should use the -
gn server command-line option to set the maximum number of requests that
the server handles simultaneously.
$ For information on the command-line switch, see "The database server"
on page 14.
TIME_FORMAT option
Function Sets the format for times retrieved from the database.
Allowed values A string composed of the symbols listed below.
200
Chapter 5 Database Options
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default HH:NN:SS.SSS
For Open Client and JDBC connections the default is set to HH:NN:SS.SSS.
Description The format is a string using the following symbols:
♦ hh Two digit hours (24 hour clock)
♦ nn Two digit minutes
♦ mm Two digit minutes if following a colon (as in hh:mm)
♦ ss[.s...] Two digit seconds plus optional fraction
Each symbol is substituted with the appropriate data for the time that is being
formatted. Any format symbol that represents character rather than digit
output can be put in uppercase, which causes the substituted characters to
also be in uppercase. For numbers, using mixed case in the format string
suppresses leading zeros.
TIMESTAMP_FORMAT option
Function Sets the format for timestamps that are retrieved from the database.
Allowed values A string composed of the symbols listed below.
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default YYYY-MM-DD HH:NN:ss.SSS
For Open Client and JDBC connections the default is set to YYYY-MM-DD
HH:NN:SS.SSS.
Description The format is a string using the following symbols:
Symbol Description
yy Two digit year
Yyyy Four digit year
Mm Two digit month, or two digit minutes if following a colon (as in
’hh:mm’)
Mmm[m...] Character short form for months—as many characters as there are
m's
dd Two digit day of month
201
Alphabetical list of options
Symbol Description
Ddd[d...] Character short form for day of the week
hh Two digit hours
nn Two digit minutes
ss.ssssss Seconds and fractions of a second, up to six decimal places. Not all
platforms support timestamps to a precision of six places.
aa am or pm (12 hour clock)
pp Pm if needed (12 hour clock)
f Use French days and months (deprecated)
Each symbol is substituted with the appropriate data for the timestamp that is
being formatted. Any format symbol that represents character rather than
digit output can be put in uppercase, which causes the substituted characters
to also be in uppercase. For numbers, using mixed case in the format string
suppresses leading zeros.
TRUNCATE_DATE_VALUES option
Function To change the storage of time values within DATE data type values.
Allowed values ON, OFF
Default ON for databases created with Version 7 or later software, or upgraded to
Version 7 or later.
OFF for older databases
See also "DATE_FORMAT option" on page 169
"DATE data type" on page 269
Description When the option is set to ON, columns or variables declared as DATE data
types have no hours and minutes stored.
When the option is set to OFF, DATE columns or variables have hours and
minutes stored also. These time components are typically not displayed
because of the DATE_FORMAT setting. However, exact comparisons
between DATE values may unexpectedly fail because of non-matching time
components.
TRUNCATE_WITH_AUTO_COMMIT option
Function To speed up TRUNCATE TABLE statements
202
Chapter 5 Database Options
TSQL_HEX_CONSTANT option
Function Controls whether hexadecimal constants are treated as binary typed
constants.
Allowed values ON, OFF
Default ON
203
Alphabetical list of options
Description When this option is set to ON, hexadecimal constants are treated as binary
typed constants. To get the historical behavior, set the option to OFF.
TSQL_VARIABLES option
Function Controls whether the @ sign can be used as a prefix for Embedded SQL host
variable names.
Allowed values ON, OFF
Default OFF
ON for Open Client and JDBC connections
Description When this options set to ON, you can use the @ sign instead of the colon as a
prefix for host variable names in Embedded SQL. This is implemented
primarily for Transact-SQL compatibility.
VERIFY_ALL_COLUMNS option
Function Controls whether messages that contain updates published by the local
database are sent with all column values included.
Allowed values ON, OFF
Default OFF
Description This option is used by SQL Remote only. When it is set to ON, messages
that contain updates published by the local database are sent with all column
values included, and a conflict in any column triggers a RESOLVE
UPDATE trigger at the subscriber database.
VERIFY_THRESHOLD option
Function Controls which columns are verified when updates are replicated.
Allowed values Integer, in bytes
Default 1000
Description This option is used by SQL Remote only. If the data type of a column is
longer than the threshold, old values for the column are not verified when an
UPDATE is replicated. This keeps the size of SQL Remote messages down,
but has the disadvantage that conflicting updates of long values are not
detected.
204
Chapter 5 Database Options
WAIT_FOR_COMMIT option
Function Determines when foreign key integrity is checked, as data is manipulated.
Allowed values ON or OFF
Scope Can be set for an individual connection or for the PUBLIC group. Takes
effect immediately.
Default OFF
Description If this option is set to ON, the database does not check foreign key integrity
until the next COMMIT statement. Otherwise, all foreign keys that are not
created with the CHECK ON COMMIT option are checked as they are
inserted, updated or deleted.
205
Alphabetical list of options
206
C H A P T E R 6
About this chapter This chapter describes the elements and conventions of the SQL language.
Contents
Topic Page
Keywords 208
Identifiers 211
Strings 212
Operators 213
Expressions 218
Search conditions 226
Special values 234
Variables 237
Comments 246
NULL value 247
207
Keywords
Keywords
Each SQL statement contains one or more keywords. SQL is case insensitive
to keywords, but throughout these manuals, keywords are indicated in upper
case.
For example, in the following statement, SELECT and FROM are keywords:
SELECT *
FROM employee
The following statements are equivalent to the one above:
Select *
From employee
select * from employee
sELECT * FRoM employee
Some keywords cannot be used as identifiers without surrounding them in
double quotes. These are called reserved words. Other keywords, such as
DBA, do not require double quotes, and are not reserved words.
Reserved words
Some keywords in SQL are also reserved words. To use a reserved word in
a SQL statement as an identifier, you must enclose it in double quotes.
Many, but not all, of the keywords that appear in SQL statements are
reserved words. For example, you must use the following syntax to retrieve
the contents of a table named SELECT.
SELECT *
FROM "SELECT"
Because SQL is not case sensitive with respect to keywords, each of the
following words may appear in upper case, lower case, or any combination
of the two. All strings that differ only in capitalization from one of the
following words, are reserved words.
If you are using Embedded SQL, you can use the database library function
sql_needs_quotes to determine whether a string requires quotation marks.
A string requires quotes if it is a reserved word or if it contains a character
not ordinarily allowed in an identifier.
The SQL keywords in Adaptive Server Anywhere 7 are as follows:
208
Chapter 6 SQL Language Elements
209
Keywords
210
Chapter 6 SQL Language Elements
Identifiers
Function Identifiers represent names of objects in the database, such as user IDs,
tables, and columns.
Description Identifiers consist of any string of alphabetic characters or digits. The first
character of an identifier must be an alphabetic character, not a digit.
Alternatively, any string of characters can be used as an identifier by
enclosing it in quotation marks ("double quotes") as long as the
QUOTED_IDENTIFIER database option is set to ON.
The underscore character (_), at sign (@), number sign (#), and dollar sign
($) are considered alphabetic characters. The database collation sequence
dictates which characters are considered alphabetic or digit characters.
A quotation mark inside the identifier is represented by two quotation marks
in a row.
Identifiers have a maximum length of 128 bytes.
Reserved words play an important role in the syntax of the SQL language. If
you choose to use a reserved word as an identifier, you must enclose it in
double quotes even if it does not have spaces.
Examples The following are all valid identifiers.
Surname
"Surname"
SomeBigName
"Client Number"
"With a quotation "" mark"
See also $ For a complete list of the reserved words, see "Reserved words" on
page 208.
$ For information on the QUOTED_IDENTIFIER option, see
"QUOTED_IDENTIFIER option" on page 195.
211
Strings
Strings
Strings are of the following types:
♦ literal strings
♦ expressions with CHAR or VARCHAR data types.
An expression with a CHAR data type may be a built-in or user-defined
function, or one of the many other kinds of expressions available.
$ For more information on expressions, see "Expressions" on page 218.
A literal string is any sequence of characters enclosed in apostrophes (’single
quotes’). A SQL variable of character data type can hold a string. The
following is a simple example of a literal strings:
’This is a string.’
Special characters You represent special character in strings by escape sequences, as follows:
in strings
♦ To represent an apostrophe inside a string, use two apostrophes in a row.
For example:
’John’’s database’
♦ To represent a new line character, use a backslash followed by n (\n).
For example:
’First line:\nSecond line:’
♦ To represent a backslash character, use two backslashes in a row (\\). For
example:
’c:\\temp’
♦ Hexadecimal escape sequences can be used for any character, printable
or not. A hexadecimal escape sequence is a backslash followed by an x
followed by two hexadecimal digits (for example, \x6d represents the
letter m). For example:
’\x00\x01\x02\x03’
Compatibility For compatibility with Adaptive Server Enterprise, you can set the
QUOTED_IDENTIFIER database option to OFF. With this setting, you can
also use double quotes to mark the beginning and end of strings. The option
is set to ON by default.
212
Chapter 6 SQL Language Elements
Operators
This section describes arithmetic, string, and bit-wise operators. For
information on comparison operators, see the section "Search conditions" on
page 226.
The normal precedence of operations applies. Expressions in parentheses are
evaluated first, then multiplication and division before addition and
subtraction. String concatenation happens after addition and subtraction.
Comparison operators
The syntax for comparison conditions is as follows:
... expression compare expression
where compare is a comparison operator. The following comparison
operators are available:
operator description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
!= Not equal to
<> Not equal to
!> Not greater than
!< Not less than
Case sensitivity
All string comparisons are case insensitive unless the database was
created as case sensitive.
Compatibility ♦ Trailing blanks Any trailing blanks in character data are ignored for
comparison purposes by Adaptive Server Enterprise. The behavior of
Adaptive Server Anywhere when comparing strings is controlled the –b
command-line switch that is set when creating the database.
213
Operators
Logical operators
Search conditions can be combined using AND, OR and NOT.
Conditions are combined using AND as follows:
... condition1 AND condition2
The combined condition is TRUE if both conditions are TRUE, FALSE if
either condition is FALSE, and UNKNOWN otherwise.
Conditions are combined using OR as follows:
... condition1 OR condition2
The combined condition is TRUE if either condition is TRUE, FALSE if
both conditions are FALSE, and UNKNOWN otherwise.
The syntax for the NOT operator is as follows:
... NOT condition
The NOT condition is TRUE if condition is FALSE, FALSE if condition is
TRUE, and UNKNOWN if condition is UNKNOWN.
The IS operator provides a means to test a logical value. The syntax for the
IS operator is as follows:
...expression IS [ NOT ] truth-value
The condition is TRUE if the expression evaluates to the supplied truth-
value, which must be one of TRUE, FALSE, UNKNOWN, or NULL.
Otherwise, the value is FALSE.
$ For more information, see "Three-valued logic" on page 231.
Compatibility ♦ The logical operators are compatible between Adaptive Server
Anywhere and Adaptive Server Enterprise.
Arithmetic operators
expression + expression Addition. If either expression is the NULL
value, the result is the NULL value.
214
Chapter 6 SQL Language Elements
String operators
expression || expression String concatenation (two vertical bars). If
either string is the NULL value, it is treated as the empty string for
concatenation.
Bitwise operators
The following operators can be used on bit data types, in both Adaptive
Server Anywhere and Adaptive Server Enterprise.
Operator Description
& and
| or
^ exclusive or
~ not
215
Operators
Join operators
The Transact-SQL outer join operators *= and =* are supported in Adaptive
Server Anywhere, in addition to the SQL/92 join syntax that uses a table
expression in the FROM clause.
Compatibility ♦ Modulo The % operator can be used in Adaptive Server Anywhere
only if the PERCENT_AS_COMMENT option is set to OFF. The
default value is ON.
♦ String concatenation When using the + concatenation operator in
Adaptive Server Anywhere, you should explicitly set the operands to
strings rather than relying on implicit data conversion. For example, the
following query returns the integer value 579
SELECT 123 + 456
whereas the following query returns the character string 123456
SELECT ’123’ + ’456’
You can use the CAST or CONVERT function to explicitly convert data
types.
The || concatenation operator is not supported by Adaptive Server
Enterprise.
Operator precedence
The precedence of operators in expressions is as follows. The operators at the
top of the list are evaluated before those at the bottom of the list.
1 unary operators
2 ’.’ (the Java reference operator)
3 ’&’, ’|’, ’^’, ’~’
4 ’*’, ’/’, ’%’
5 ’+’, ’-’
6 ’||’
7 not
8 and
9 or
216
Chapter 6 SQL Language Elements
217
Expressions
Expressions
Syntax expression:
case-expression
| constant
| [correlation-name .] column-name [ java-ref ]
| - expression
| expression operator expression
| ( expression )
| function-name ( expression, ... )
| if-expression
| [ java-package-name.] java-class-name java-ref
| special value
| ( subquery )
| variable-name [ java-ref ]
Parameters case-expression:
{ CASE search-condition
... WHEN expression
... THEN,...
... [ ELSE expression ]
END
| CASE
... WHEN search-condition
... THEN expression,...
... [ ELSE expression ]
END
}
constant:
integer | number | ’string’ | host-variable
special-value:
CURRENT { DATE | TIME | TIMESTAMP }
| NULL
| SQLCODE
| SQLSTATE
| USER
if-expression:
IF condition
... THEN expression
... [ ELSE expression ]
... ENDIF
java-ref:
.field-name [ java-ref ]
| >> field-name [ java-ref ]
| .method-name ( [expression,...] ) [ java-ref ]
| >> method-name ( [expression,...] ) [ java-ref ]
218
Chapter 6 SQL Language Elements
operator:
{ + | - | * | / | || | % }
Usage Anywhere.
Authorization Must be connected to the database.
Side effects None.
See also "Constants in expressions" on page 219
"Special values" on page 234
"Column names in expressions" on page 219
"SQL Functions" on page 291
"Subqueries in expressions" on page 220
"Search conditions" on page 226
"SQL Data Types" on page 251
"SQL Functions" on page 291
"Variables" on page 237
Description Expressions are formed from several different kinds of elements, discussed
in the following sections.
$ For information on functions, see "SQL Functions" on page 291. For
information on variables, see "Variables" on page 237.
Compatibility ♦ The IF condition is not supported in Adaptive Server Enterprise.
♦ Java expressions are not currently supported in Adaptive Server
Enterprise.
♦ For other differences, see the separate descriptions of each class of
expression, in the following sections.
Constants in expressions
Constants are numbers or strings. String constants are enclosed in
apostrophes (’single quotes’). An apostrophe is represented inside the string
by two apostrophes in a row.
219
Expressions
address
"date hired"
"salary"."date paid"
$ For more information on identifiers, see "Identifiers" on page 211.
Subqueries in expressions
A subquery is a SELECT statement enclosed in parentheses. The SELECT
statement must contain one and only one select list item. When used as an
expression, a subquery is generally allowed to return only one value.
A subquery can be used anywhere that a column name can be used. For
example, a subquery can be used in the select list of another SELECT
statement.
$ For other uses of subqueries, see "Subqueries in search conditions" on
page 227.
IF expressions
The syntax of the IF expression is as follows:
IF condition
THEN expression1
[ ELSE expression2 ]
ENDIF
This expression returns the following:
♦ If condition is TRUE, the IF expression returns expression1.
♦ If condition is FALSE, the IF expression returns expression2.
♦ If condition is FALSE, and there is no expression2, the IF expression
returns NULL.
♦ If condition is NULL, the IF expression returns NULL.
$ For more information about TRUE, FALSE and UNKNOWN
conditions, see "NULL value" on page 247, and "Search conditions" on
page 226.
220
Chapter 6 SQL Language Elements
CASE expressions
The CASE expression provides conditional SQL expressions. Case
expressions can be used anywhere an expression can be used.
The syntax of the CASE expression is as follows:
CASE expression
WHEN expression
THEN expression,...
[ ELSE expression ]
END
If the expression following the CASE statement is equal to the expression
following the WHEN statement, then the expression following the THEN
statement is returned. Otherwise the expression following the ELSE
statement is returned, if it exists.
For example, the following code uses a case expression as the second clause
in a SELECT statement.
SELECT id,
( CASE name
WHEN ’Tee Shirt’ then ’Shirt’
WHEN ’Sweatshirt’ then ’Shirt’
WHEN ’Baseball Cap’ then ’Hat’
ELSE ’Unknown’
END ) as Type
FROM "DBA".Product
An alternative syntax is as follows:
CASE
WHEN search-condition
THEN expression,...
[ ELSE expression ]
END
221
Expressions
For example, the following statement uses a case expression as the third
clause of a SELECT statement to associate a string with a search-condition.
SELECT id, name,
( CASE
WHEN name=’Tee Shirt’ then ’Sale’
WHEN quantity >= 50 then ’Big Sale’
ELSE ’Regular price’
END ) as Type
FROM "DBA".Product
NULLIF function The NULLIF function provides a way to write some CASE statements in
for abbreviated short form. The syntax for NULLIF is as follows:
CASE expressions
NULLIF ( expression-1, expression-2 )
NULLIF compares the values of the two expressions. If the first expression
equals the second expression, NULLIF returns NULL. If the first expression
does not equal the second expression, NULLIF returns the first expression.
Java expressions
The following kinds of Java expressions can be used as SQL expressions:
♦ Java fields Any field of an installed Java class can be invoked
wherever an expression is required. The data type of the expression is
converted from the Java field data type according to the table in "Java
to-SQL-data type conversion" on page 282. Both instance fields and
class fields can be used as expressions.
♦ Java methods Any method of an installed Java class can be invoked
wherever an expression is required. The data type of the expression is
converted from the return type of the Java method according to the table
in "Java to-SQL-data type conversion" on page 282. Both instance fields
and class fields can be used as expressions.
♦ Java objects The NEW operator is an extension to the SQL language
that allows it to better assimilate Java syntax.
The NEW SQL operator performs the same operation as the new
keyword in Java code: invoke a constructor method of a Java class. The
data type of the NEW expression is a Java class, specifically the Java
class that is being constructed.
The following expression invokes the constructor method of the String
class, a member of the java.lang package.
NEW java.lang.String( ’This argument is optional’ )
222
Chapter 6 SQL Language Elements
Compatibility of expressions
The following tables describe the compatibility of expressions and constants
between Adaptive Server Enterprise and Adaptive Server Anywhere. These
tables are a guide only, and a marking of Both may not mean that the
expression performs in an identical manner for all purposes under all
circumstances. For detailed descriptions, you should refer to the Adaptive
Server Enterprise documentation and the Adaptive Server Anywhere
documentation on the individual expression.
In the following table, expr represents an expression, and op represents an
operator.
223
Expressions
Expression Supported by
constant Both
column name Both
variable name Both
function (expr) Both
- expr Both
expr op expr Both
( expr ) Both
( subquery ) Both
if-expression Adaptive Server Anywhere only
Constant Supported by
integer Both
number Both
’string’ Both
special-constant Both
host-variable Adaptive Server Anywhere
Default By default, Adaptive Server Enterprise and Adaptive Server Anywhere give
interpretation of different meanings to delimited strings: that is, strings enclosed in
delimited strings apostrophes (single quotes) and in quotation marks (double quotes).
Adaptive Server Anywhere employs the SQL/92 convention, that strings
enclosed in apostrophes are constant expressions, and strings enclosed in
quotation marks (double quotes) are delimited identifiers (names for database
objects). Adaptive Server Enterprise employs the convention that strings
enclosed in quotation marks are constants, while delimited identifiers are not
allowed by default and are treated as strings.
224
Chapter 6 SQL Language Elements
Compatible You can choose to use either the SQL/92 or the default Transact-SQL
interpretation of convention in both Adaptive Server Enterprise and Adaptive Server
delimited strings Anywhere as long as the quoted_identifier option is set to the same value in
each DBMS.
Examples If you choose to operate with the quoted_identifier option on (the default
Adaptive Server Anywhere setting), then the following statements involving
the SQL keyword user are valid for both DBMS’s.
CREATE TABLE "user" (
col1 char(5)
) ;
INSERT "user" ( col1 )
VALUES ( ’abcde’ ) ;
If you choose to operate with the quoted_identifier option off (the default
Adaptive Server Enterprise setting), then the following statements are valid
for both DBMSs.
SELECT *
FROM employee
WHERE emp_lname = "Chin"
225
Search conditions
Search conditions
Function To specify a search condition for a WHERE clause, a HAVING clause, a
CHECK clause, a JOIN clause, or an IF expression.
Syntax search condition:
expression compare expression
| expression compare { [ ANY | SOME ] | ALL }( subquery )
| expression IS [ NOT ] NULL
| expression [ NOT ] BETWEEN expression AND expression
| expression [ NOT ] LIKE expression [ ESCAPE expression ]
| expression [ NOT ] IN ( { expression | subquery | value-expr1 ,
value-expr2 [, value-expr3 ] ...} )
| EXISTS ( subquery )
| NOT condition
| condition AND condition
| condition OR condition
| ( condition )
| ( condition , estimate )
| condition IS [ NOT ] { TRUE | FALSE | UNKNOWN }
Parameters compare:
= | > | < | >= | <= | <> | != | !< | !>
Usage Anywhere.
Authorization Must be connected to the database.
Side effects None.
See also "Expressions" on page 218
Description Conditions are used to choose a subset of the rows from a table, or in a
control statement such as an IF statement to determine control of flow.
SQL conditions do not follow boolean logic, where conditions are either true
or false. In SQL, every condition evaluates as one of TRUE, FALSE, or
UNKNOWN. This is called three-valued logic. The result of a comparison is
UNKNOWN if either value being compared is the NULL value. For tables
showing how logical operators combine in three-valued logic, see the section
"Three-valued logic" on page 231.
Rows satisfy a search condition if and only if the result of the condition is
TRUE. Rows for which the condition is UNKNOWN do not satisfy the
search condition. For more information about NULL, see "NULL value" on
page 247.
Subqueries form an important class of expression that is used in many search
conditions. For information about using subqueries in search conditions, see
"Subqueries in search conditions" on page 227.
226
Chapter 6 SQL Language Elements
BETWEEN conditions
The syntax for BETWEEN conditions is as follows:
227
Search conditions
LIKE conditions
The syntax for LIKE conditions is as follows:
... expression [NOT] LIKE pattern [ESCAPE escape-expr]
The LIKE condition can evaluate as TRUE, FALSE, or UNKNOWN.
Without the NOT keyword, the condition evaluates as TRUE if expression
matches the pattern. If either expression or pattern is the NULL value, this
condition is UNKNOWN. The NOT keyword reverses the meaning of the
condition, but leaves UNKNOWN unchanged.
The pattern may contain any number of wild cards. The wild cards are:
228
Chapter 6 SQL Language Elements
Searching for one A range of characters to look for is specified by giving the ends of the range
of a range of inside square brackets, separated by a hyphen. For example, the following
characters condition finds the strings bough and rough, but not tough:
... LIKE ’[a-r]ough’
The range of characters [a-z] is interpreted as "greater than or equal to a, and
less than or equal to z", where the greater than and less than operations are
carried out within the collation of the database. For information on ordering
of characters within a collation, see "International Languages and Character
Sets" on page 279 of the book ASA User’s Guide.
The lower end of the range must precede the higher end of the range. For
example, a LIKE condition containing the expression [z-a] returns no rows,
because no character matches the [z-a] range.
Unless the database is created as case-sensitive, the range of characters is
case insensitive. For example, the following condition finds the strings
Bough, rough, and TOUGH:
... LIKE ’[a-z]ough’
If the database is created as a case-sensitive database, the search condition is
case sensitive also.
Combining You can combine ranges and sets within a square bracket. For example, the
searches for following condition finds the strings bough, rough, and tough:
ranges and sets ... LIKE ’[a-rt]ough’
The bracket [a-mpqs-z] is interpreted as "exactly one character that is either
in the range a to m inclusive, or is p, or is q, or is in the range s to z
inclusive".
229
Search conditions
Searching for one The caret character (^) is used to specify a range of characters that is
character not in a excluded from a search. For example, the following condition finds the string
range tough, but not the strings rough, or bough:
... LIKE ’[^a-r]ough’
The caret negates the entire rest of the contents of the brackets. For example,
the bracket [^a-mpqs-z] is interpreted as "exactly one character that is not in
the range a to m inclusive, is not p, is not q, and is not in the range s to z
inclusive".
Special cases of Any single character in square brackets means that character. For example,
ranges and sets [a] matches just the character a. [^] matches just the caret character, [%]
matches just the percent character (the percent character does not act as a
wild card in this context), and [_] matches just the underscore character.
Also, [[] matches just the character [.
Other special cases are as follows:
♦ The expression [a-] matches either of the characters a or -.
♦ The expression [] is never matched and always returns no rows.
♦ The expressions [ or [abp-q are ill-formed expressions, and give syntax
errors.
♦ You cannot use wild cards inside square brackets. The expression [a%b]
finds one of a, %, or b.
♦ You cannot use the caret character to negate ranges except as the first
character in the bracket. The expression [a^b] finds one of a, ^, or b.
Compatibility ♦ The ESCAPE clause is supported by Adaptive Server Anywhere only.
IN conditions
The syntax for IN conditions is as follows:
...expression [ NOT ] IN ( subquery )
| expression [ NOT ] IN ( expression )
| expression [ NOT ] IN (value-expr1 , value-expr2 [, value-
expr3 ] ... )
Without the NOT keyword, the IN conditions is TRUE if expression equals
any of the listed values, UNKNOWN if expression is the NULL value, and
FALSE otherwise. The NOT keyword reverses the meaning of the condition,
but leaves UNKNOWN unchanged.
Compatibility ♦ IN conditions are compatible between Adaptive Server Enterprise and
Adaptive Server Anywhere.
230
Chapter 6 SQL Language Elements
EXISTS conditions
The syntax for EXISTS conditions is as follows:
... EXISTS( subquery )
The EXISTS condition is TRUE if the subquery result contains at least one
row, and FALSE if the subquery result does not contain any rows. The
EXISTS condition cannot be UNKNOWN.
Compatibility ♦ The EXISTS condition is compatible between Adaptive Server
Enterprise and Adaptive Server Anywhere.
IS NULL conditions
The syntax for IS NULL conditions is as follows:
expression IS [ NOT ] NULL
Without the NOT keyword, the IS NULL condition is TRUE if the
expression is the NULL value, and FALSE otherwise. The NOT keyword
reverses the meaning of the condition.
Compatibility ♦ The IS NULL condition is compatible between Adaptive Server
Enterprise and Adaptive Server Anywhere.
Three-valued logic
The following tables show how the AND, OR, NOT, and IS logical operators
of SQL work in three-valued logic.
231
Search conditions
232
Chapter 6 SQL Language Elements
Fractional values enable more accurate user estimates for joins, particularly
for large tables.
Compatibility ♦ Adaptive Server Enterprise does not support explicit estimates.
233
Special values
Special values
Special values can be used in expressions, and as column defaults when
creating tables.
234
Chapter 6 SQL Language Elements
235
Special values
236
Chapter 6 SQL Language Elements
Variables
Adaptive Server Anywhere supports three levels of variables:
♦ Local variables These are defined inside a compound statement in a
procedure or batch using the DECLARE statement. They exist only
inside the compound statement.
♦ Connection-level variables These are defined with a CREATE
VARIABLE statement. They belong to the current connection, and
disappear when you disconnect from the database or when you use the
DROP VARIABLE statement.
♦ Global variables These are system-supplied variables that have
system-supplied values.
Local and connection-level variables are declared by the user, and can be
used in procedures or in batches of SQL statements to hold information.
Global variables are system-supplied variables that provide system-supplied
values. All global variables have names beginning with two @ signs. For
example, the global variable @@version has a value that is the current
version number of the database server. Users cannot define global variables.
Local variables
Local variables are declared using the DECLARE statement, which can be
used only within a compound statement (that is, bracketed by the BEGIN and
END keywords). The variable is initially set as NULL. The value of the
variable can be set using the SET statement, or can be assigned using a
SELECT statement with an INTO clause.
The syntax of the DECLARE statement is as follows:
DECLARE variable-name data-type
Local variables can be passed as arguments to procedures, as long as the
procedure is called from within the compound statement.
Examples ♦ The following batch illustrates the use of local variables.
BEGIN
DECLARE local_var INT ;
SET local_var = 10 ;
MESSAGE ’local_var = ’, local_var TO CLIENT;
END
Running this batch from Interactive SQL gives the message local_var =
10 in the Interactive SQL Messages window.
237
Variables
♦ The variable local_var does not exist outside the compound statement in
which it is declared. The following batch is invalid, and gives a column
not found error.
-- This batch is invalid.
BEGIN
DECLARE local_var INT ;
SET local_var = 10 ;
MESSAGE ’local_var = ’, local_var TO CLIENT;
END;
MESSAGE ’local_var = ’, local_var TO CLIENT;
♦ The following example illustrates the use of SELECT with an INTO
clause to set the value of a local variable:
BEGIN
DECLARE local_var INT ;
SELECT 10 INTO local_var ;
MESSAGE ’local_var = ’, local_var TO CLIENT;
END
Running this batch from Interactive SQL gives the message local_var =
10 on the server window.
Connection-level variables
Connection-level variables are declared with the CREATE VARIABLE
statement. Connection-level variables can be passed as parameters to
procedures.
238
Chapter 6 SQL Language Elements
Example ♦ The following batch of SQL statements illustrates the use of connection-
level variables.
CREATE VARIABLE con_var INT;
SET con_var = 10;
MESSAGE ’con_var = ’, con_var TO CLIENT;
Running this batch from Interactive SQL gives the message local_var =
10 on the server window.
Global variables
Global variables have values set by the database server. For example, the
global variable @@version has a value that is the current version number of
the database server.
Global variables are distinguished from local and connection-level variables
by having two @ signs preceding their names. For example, @@error and
@@rowcount are global variables. Users cannot create global variables, and
cannot update the value of global variables directly.
Some global variables, such as @@identity, hold connection-specific
information, and so have connection-specific values. Other variables, such as
@@connections, have values that are common to all connections.
Global variable and The special constants (for example, CURRENT DATE, CURRENT TIME,
special constants USER, and SQLSTATE) are similar to global variables.
The following statement retrieves a value of the version global variable.
SELECT @@version
In procedures and triggers, global variables can be selected into a variable
list. The following procedure returns the server version number in the ver
parameter.
239
Variables
240
Chapter 6 SQL Language Elements
Compatibility The following list includes all Adaptive Server Enterprise global variables
supported in Adaptive Server Anywhere. Adaptive Server Enterprise global
variables not supported by Adaptive Server Anywhere are not included in the
list. In contrast to the above table, this list includes all global variables that
return a value, including those for which the value is fixed at NULL, 1, -1, or
0, and may not be meaningful.
241
Variables
242
Chapter 6 SQL Language Elements
243
Variables
244
Chapter 6 SQL Language Elements
@@identity and When an insert causes referential integrity actions or fires a trigger,
triggers @@identity behaves like a stack. For example, if an insert into a table T1
(with an identity or autoincrement column) fires a trigger that inserts a row
into table T2 (also with an identity or autoincrement column), then the value
returned to the application or procedure which carried out the insert is the
value inserted into T1. Within the trigger, @@identity has the T1 value
before the insert into T2 and the T2 value after. The trigger can copy the
values to local variables if it needs to access both.
245
Comments
Comments
Comments are used to attach explanatory text to SQL statements or
statement blocks. The database server does not execute comments.
Several comment indicators are available in Adaptive Server Anywhere.
♦ -- (Double hyphen) The database server ignores any remaining
characters on the line. This is the SQL/92 comment indicator.
♦ // (Double slash) The double slash has the same meaning as the
double hyphen.
♦ /* ... */ (Slash-asterisk) Any characters between the two comment
markers are ignored. The two comment markers may be on the same or
different lines. Comments indicated in this style can be nested. This
style of commenting is also called C-style comments.
♦ % (Percent sign) The percent sign has the same meaning as the
double hyphen, if the PERCENT_AS_COMMENT option is set to ON.
It is recommended that % not be used as a comment indicator.
Transact-SQL compatibility
The double-hyphen and the slash-asterisk comment styles are compatible
with Adaptive Server Enterprise.
246
Chapter 6 SQL Language Elements
NULL value
Function To specify a value that is unknown or not applicable.
Syntax NULL
Usage Anywhere.
Permissions Must be connected to the database.
Side effects None.
See also "Expressions" on page 218
"Search conditions" on page 226
Description The NULL value is a special value which is different from any valid value
for any data type. However, the NULL value is a legal value in any data
type. The NULL value is used to represent missing or inapplicable
information. Note that these are two separate and distinct cases where NULL
is used:
Situation Description
missing The field does have a value, but that value is unknown.
inapplicable The field does not apply for this particular row.
SQL allows columns to be created with the NOT NULL restriction. This
means that those particular columns cannot contain the NULL value.
The NULL value introduces the concept of three valued logic to SQL. The
NULL value compared using any comparison operator with any value
(including the NULL value) is "UNKNOWN." The only search condition
that returns TRUE is the IS NULL predicate. In SQL, rows are selected only
if the search condition in the WHERE clause evaluates to TRUE; rows that
evaluate to UNKNOWN or FALSE are not selected.
The IS [ NOT ] truth-value clause, where truth-value is one of TRUE,
FALSE or UNKNOWN can be used to select rows where the NULL value is
involved. See "Search conditions" on page 226 for a description of this
clause.
In the following examples, the column Salary contains NULL.
247
NULL value
The same rules apply when comparing columns from two different tables.
Therefore, joining two tables together will not select rows where any of the
columns compared contain the NULL value.
NULL also has an interesting property when used in numeric expressions.
The result of any numeric expression involving the NULL value is NULL.
This means that if NULL is added to a number, the result is NULL—not a
number. If you want NULL to be treated as 0, you must use the ISNULL(
expression, 0 ) function (see "SQL Functions" on page 291).
Many common errors in formulating SQL queries are caused by the behavior
of NULL. You will have to be careful to avoid these problem areas. See
"Search conditions" on page 226 for a description of the effect of three-
valued logic when combining search conditions.
Standards and ♦ SQL/92 Entry-level feature.
compatibility
♦ Sybase In some contexts, Adaptive Server Enterprise treats NULL as
a value, whereas Adaptive Server Anywhere does not. For example,
rows of a column c1 that are NULL are not included in the results of a
query with the following WHERE clause in Adaptive Server Anywhere,
as the condition has a value of UNKNOWN:
WHERE NOT( C1 = NULL )
In Adaptive Server Enterprise, the condition is evaluated as TRUE, and
these rows are returned. You should use IS NULL rather than a
comparison operator for compatibility.
Unique indexes in Adaptive Server Anywhere can hold rows that hold
NULL and are otherwise identical. Adaptive Server Enterprise does not
permit such entries in unique indexes.
Example ♦ The following INSERT statement inserts a NULL into the date_returned
column of the Borrowed_book table.
248
Chapter 6 SQL Language Elements
INSERT
INTO Borrowed_book
( date_borrowed, date_returned, book )
VALUES ( CURRENT DATE, NULL, ’1234’ )
249
NULL value
250
C H A P T E R 7
About this chapter This chapter describes the data types supported by Adaptive Server
Anywhere.
Contents
Topic Page
Character data types 252
Numeric data types 256
Money data types 263
Bit data type 264
Date and time data types 265
Binary data types 272
Domains 274
Java class data types 276
Data type conversions 281
Java / SQL data type conversion 282
Year 2000 compliance 285
251
Character data types
252
Chapter 7 SQL Data Types
Notes Data type lengths of less than one are not allowed.
Compatibility ♦ The CHARACTER (n) alternative for CHAR is not supported in
Adaptive Server Enterprise.
♦ Adaptive Server Anywhere does not support the NCHAR and
NVARCHAR data types provided by Adaptive Server Enterprise.
253
Character data types
For strings up to 254 bytes in length, the storage requirements are the
number of bytes in the string plus one additional byte. For longer strings,
there is more overhead.
Strings of multi-byte characters can be held as the CHAR data type, but it is
important to note that max-length is in bytes, not characters.
Parameters max-length The maximum length of the string, in bytes. The maximum
size allowed is 32,767.
Standards and ♦ SQL/92 Compatible with SQL/92.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise. The maximum
max-length for Adaptive Server Enterprise is 255.
"CHAR data type" on page 253
See also
"LONG VARCHAR data type" on page 254
254
Chapter 7 SQL Data Types
255
Numeric data types
256
Chapter 7 SQL Data Types
Usage The BIGINT data type is an exact numeric data type: its accuracy is
preserved after arithmetic operations.
A BIGINT value requires 8 bytes of storage.
The range for signed BIGINT values is from ( -2e63) to ( +2e63 -1
).
The range for unsigned BIGINT values is from 0 to ( 2e64 - 1 ).
By default, the data type is signed.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported in Adaptive Server Enterprise.
See also "INT or INTEGER data type" on page 259
"TINYINT data type" on page 261
"SMALLINT data type" on page 261
scale An integer expression that specifies the number of digits after the
decimal point. The default setting is 6.
The defaults can be changed by setting database options. For information,
see "PRECISION option" on page 193 and "SCALE option" on page 198.
Standards and ♦ SQL/92 Compatible with SQL/92.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
257
Numeric data types
258
Chapter 7 SQL Data Types
259
Numeric data types
scale An integer expression that specifies the number of digits after the
decimal point. The default value is 6.
The defaults can be changed by setting database options. For information,
see "PRECISION option" on page 193 and "SCALE option" on page 198.
Standards and ♦ SQL/92 Compatible with SQL/92, if the SCALE option is set to zero.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
See also "FLOAT data type" on page 258
"REAL data type" on page 260
"DOUBLE data type" on page 258
260
Chapter 7 SQL Data Types
261
Numeric data types
262
Chapter 7 SQL Data Types
263
Bit data type
264
Chapter 7 SQL Data Types
265
Date and time data types
266
Chapter 7 SQL Data Types
267
Date and time data types
For combinations of dates and times, any unambiguous date and any
unambiguous time yield an unambiguous date-time value. Also, the form
YYYY-MM-DD HH.MM.SS.SSS
is an unambiguous date-time value. Periods can be used in the time only in
combination with a date.
In other contexts, a more flexible date format can be used. Adaptive Server
Anywhere can interpret a wide range of strings as dates. The interpretation
depends on the setting of the database option DATE_ORDER. The
DATE_ORDER database option can have the value MDY, YMD, or DMY
(see "SET OPTION statement" on page 596). For example, the following
statement sets the DATE_ORDER option to DMY:
SET OPTION DATE_ORDER = ’DMY’ ;
The default DATE_ORDER setting is ’YMD’. The ODBC driver sets the
DATE_ORDER option to ’YMD’ whenever a connection is made. The value
can still be changed using the SET TEMPORARY OPTION statement.
The database option DATE_ORDER determines whether the string 10/11/12
is interpreted by the database as Oct 11 1912, Nov 12 1910, or Nov 10 1912.
The year, month, and day of a date string should be separated by some
character (for example /, -, or space) and appear in the order specified by the
DATE_ORDER option. The year can be supplied as either 2 or 4 digits, with
2 digit years defaulting to the 20th century. The month can be the name or
number of the month. The hours and minutes are separated by a colon, but
can appear anywhere in the string.
Notes ♦ We recommend that you always specify the year using the four-digit
format.
$ For more information about Y2K compliance issues, see "Year
2000 compliance" on page 285.
♦ With an appropriate setting of DATE_ORDER, the following strings are
all valid dates:
92-05-23 21:35
92/5/23
1992/05/23
May 23 1992
23-May-1992
Tuesday May 23, 1992 10:00pm
♦ If a string contains only a partial date specification, default values are
used to fill out the date. The following defaults are used:
♦ year This year
268
Chapter 7 SQL Data Types
♦ month No default
♦ day 1 (useful for month fields; for example, May 1992 will be the
date 1992-05-01 00:00)
♦ hour, minute, second, fraction 0
For historical reasons, a DATE column can also contain an hour and minute
if the TRUNCATE_DATE_VALUES option is set to OFF. The
TIMESTAMP data type is recommended for anything with hours and
minutes.
The format in which DATE values are retrieved by applications is controlled
by the DATE_FORMAT setting. For example, a date value representing the
19th of July, 2003 may be returned to an application as 2003/07/19, as
Jul 19, 2003, or as one of a number of other possibilities.
The way in which a string is interpreted by the database server as a date is
controlled by the DATE_ORDER option. For example, depending on the
DATE_ORDER setting, a value of 02/05/2002 supplied by an application
for a DATE value may be interpreted in the database as the 2nd of May or
the 5th of February.
269
Date and time data types
Syntax DATETIME
Usage DATETIME is provided primarily for compatibility with Adaptive Server
Enterprise.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise. For an
exception, see "Transact-SQL compatibility of string-to-date/time
conversions" on page 265.
See also "DATE data type" on page 269
"SMALLDATETIME data type" on page 270
"TIMESTAMP data type" on page 271
270
Chapter 7 SQL Data Types
271
Binary data types
The maximum size allowed is 32,767. The BINARY data type is identical to
the CHAR data type except when used in comparisons. BINARY values are
compared exactly while CHAR values are compared using the collation
sequence of the database.
Parameters max-length An integer expression that specifies the maximum length of
the expression.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Adaptive Server Enterprise supports max-length up to 255.
See also "LONG BINARY data type" on page 272
"VARBINARY data type" on page 273
272
Chapter 7 SQL Data Types
273
Domains
Domains
Function Domains are aliases for built-in data types, including precision and scale
values where applicable, and optionally including DEFAULT values and
CHECK conditions. Some domains, such as the monetary data types, are pre-
defined in Adaptive Server Anywhere, but you can add more of your own.
Domains, sometimes called user-defined data types, allow columns
throughout a database to be automatically defined on the same data type,
with the same NULL or NOT NULL condition, with the same DEFAULT
setting, and with the same CHECK condition. Domains encourage
consistency throughout the database and can eliminate some types of errors.
Simple domains Domains are created using the CREATE DOMAIN statement For full
description of the syntax, see "CREATE DOMAIN statement" on page 421.
The following statement creates a data type named street_address, which is
a 35-character string.
CREATE DOMAIN street_address CHAR( 35 )
CREATE DATATYPE can be used as an alternative to CREATE DOMAIN,
but is not recommended because CREATE DOMAIN is the syntax used in
the draft SQL/3 standard.
Resource authority is required to create data types. Once a data type is
created, the user ID that executed the CREATE DOMAIN statement is the
owner of that data type. Any user can use the data type. Unlike with other
database objects, the owner name is never used to prefix the data type name.
The street_address data type may be used in exactly the same way as any
other data type when defining columns. For example, the following table
with two columns has the second column as a street_address column:
CREATE TABLE twocol (
id INT,
street street_address
)
Domains can be dropped by their owner or by the DBA, using the DROP
DOMAIN statement:
DROP DOMAIN street_address
This statement can be carried out only if the data type is not used in any table
in the database. If you attempt to drop a domain that is in use, the message
"Primary key for row in table ’SYSUSERTYPE’ is referenced in another
table" appears.
274
Chapter 7 SQL Data Types
Constraints and Many of the attributes associated with columns, such as allowing NULL
defaults with values, having a DEFAULT value, and so on, can be built into a domain.
domains Any column that is defined on the data type automatically inherits the NULL
setting, CHECK condition, and DEFAULT values. This allows uniformity to
be built into columns with a similar meaning throughout a database.
For example, many primary key columns in the sample database are integer
columns holding ID numbers. The following statement creates a data type
that may be useful for such columns:
CREATE DOMAIN id INT
NOT NULL
DEFAULT AUTOINCREMENT
CHECK( @col > 0 )
Any column created using the data type id is not allowed to hold NULLs,
defaults to an auto-incremented value, and must hold a positive number. Any
identifier could be used instead of col in the @col variable.
The attributes of the data type can be overridden if needed by explicitly
providing attributes for the column. A column created on data type id with
NULL values explicitly allowed does allow NULLs, regardless of the setting
in the id data type.
Compatibility ♦ Named constraints and defaults In Adaptive Server Anywhere,
domains are created with a base data type, and optionally a NULL or
NOT NULL condition, a default value, and a CHECK condition. Named
constraints and named defaults are not supported.
♦ Creating data types In Adaptive Server Anywhere, you can use the
sp_addtype system procedure to add a domain, or you can use the
CREATE DOMAIN statement. In Adaptive Server Enterprise, you must
use sp_addtype.
275
Java class data types
Not all standard Adaptive Server Anywhere supports JDK 1.1.6, but not all standard Java
Java classes are classes from JDK 1.1.6 are supported. This is intentional. Some classes are
supported not supported for security reasons. Other classes are not supported because
they are applicable to user interface programming. Lastly, only classes in
packages that begin with the word java are considered to be 100% pure
Java, so any packages that start with other words (like sun) are unsupported.
Definition of When a Java class is listed as supported, it means all its methods have been
supported implemented within the Sybase VM. If a class is listed as partially
supported then some of its methods have not been implemented.
Even if a class is supported, not all of the methods of a supported Java class
are guaranteed to work. Methods of supported classes can fail if they depend
on classes that are not supported.
Error condition When a method fails because of an unsupported class, the usual error
when not condition is an unhandled exception:
supported java.lang.UnsatisfiedLinkError for the method which has not
been implemented.
276
Chapter 7 SQL Data Types
♦ java.io. The classes that govern file access are supported only on
Windows NT, and only if the JAVA_INPUT_OUTPUT option is set to
ON. See "JAVA_INPUT_OUTPUT option" on page 182.
♦ java.lang
♦ java.lang.reflect
♦ java.lang.Thread
♦ java.math
♦ java.net
♦ java.rmi
♦ java.rmi.dgc
♦ java.rmi.registry
♦ java.rmi.server
♦ java.security
♦ java.security.acl
♦ java.security.interfaces
♦ java.sql. For details on support for JDBC 2.0 features, see "Server-side
JDBC features" on page 579 of the book ASA User’s Guide.
♦ java.text
♦ java.util
♦ java.util.zip
277
Java class data types
278
Chapter 7 SQL Data Types
Installing a class Once you have a compiled Java class file, you can install it into the database.
You can do this conveniently using either Sybase Central or Interactive SQL.
279
Java class data types
280
Chapter 7 SQL Data Types
281
Java / SQL data type conversion
282
Chapter 7 SQL Data Types
283
Java / SQL data type conversion
284
Chapter 7 SQL Data Types
285
Year 2000 compliance
$ For more information on Adaptive Server Anywhere date and time data
types see "Date and time data types" on page 265.
286
Chapter 7 SQL Data Types
Leap years
The year 2000 is also a leap year, with an additional day in the month of
February. Adaptive Server Anywhere uses a globally accepted algorithm for
determining which years are leap years. Using this algorithm, a year is
considered a leap year if it is divisible by four, unless the year is a century
date (such as the year 1900), in which case it is a leap year only if it is
divisible by 400.
Adaptive Server Anywhere handles all leap years correctly. For example:
The following SQL statement results in a return value of "Tuesday":
SELECT DAYNAME(’2000-02-29’);
Adaptive Server Anywhere accepts Feb 29, 2000 — a leap year — as a date,
and using this date determines the day of the week.
However, the following statement is rejected by Adaptive Server Anywhere:
SELECT DAYNAME(’2001-02-29’);
This statement results in an error (cannot convert '2001-02-29' to a date)
because Feb 29 does not exist in the year 2001.
If this option is not set, the default setting of 50 is assumed, thus adding 1900
to two digit year strings and placing them in the 20th century.
This NEAREST_CENTURY option was introduced in SQL Anywhere
Version 5.5. In version 5.5, the default setting was 0.
Ambiguous date The following statement creates a table that can be used to illustrate the
conversion conversion of ambiguous date information in Adaptive Server Anywhere.
example CREATE TABLE T1 (C1 DATE);
The table T1 contains one column, C1, of the type DATE.
The following statement inserts a date value into the column C1. Adaptive
Server Anywhere automatically converts a string that contains an ambiguous
year value, one with two digits representing the year but nothing to indicate
the century.
INSERT INTO T1 VALUES(’00-01-01’);
By default, the NEAREST_CENTURY option is set to 50, thus Adaptive
Server Anywhere converts the string into the date 2000-01-01. The following
statement verifies the result of this insert.
SELECT * FROM T1;
Changing the NEAREST_CENTURY option using the following statement
alters the conversion process.
SET OPTION NEAREST_CENTURY = 0;
When NEAREST_CENTURY option is set to 0, executing the previous
insert using the same statement will create a different date value:
INSERT INTO T1 VALUES(’00-01-01’);
The above statement now results in the insertion of the date 1900-01-01. Use
the following statement to verify the results.
SELECT * FROM T1;
288
Chapter 7 SQL Data Types
SELECT DATEFORMAT (
DATEFORMAT(’2000-01-01’, ’Mmm dd/yy’ ),
’yyyy-Mmm-dd’ )
AS Wrong_year;
Although the unambiguous date string 2000-01-01 is automatically and
correctly converted by Adaptive Server Anywhere into a date value, the
’Mmm dd/yy’ formatting of the inner, or nested, DATEFORMAT function
drops the century portion of the date when it is converted back to a string and
passed to the outer DATEFORMAT function.
Because the database option NEAREST_CENTURY in this case is set to 0,
the outer DATEFORMAT function converts the string representing a date
with a two-digit year value into a year in the 20th century.
$ For more information on date and time functions, see "Date and time
functions" on page 292.
289
Year 2000 compliance
290
C H A P T E R 8
SQL Functions
About this chapter Functions are used to return information from the database. They are allowed
anywhere an expression is allowed.
NULL parameters
Unless otherwise stated, any function that receives NULL as a parameter
returns NULL.
291
Function types
Function types
This section groups the available function by type.
Aggregate functions
Aggregate functions summarize data over a group of rows from the database.
The groups are formed using the GROUP BY clause of the SELECT
statement. Aggregate functions are allowed only in the select list and in the
HAVING and ORDER BY clauses of a SELECT statement.
List of functions The following aggregate functions are available:
♦ "AVG function " on page 304
♦ "COUNT function " on page 312
♦ "LIST function" on page 332
♦ "MAX function" on page 335
♦ "MIN function" on page 335
♦ "SUM function" on page 358
List of functions The following data type conversion functions are available:
♦ "CAST function" on page 306
♦ "CONVERT function" on page 310
♦ "HEXTOINT function" on page 327
♦ "INTTOHEX function" on page 330
292
Chapter 8 SQL Functions
In this chapter, the term datetime is used to mean date or time or timestamp.
The specific data type DATETIME is indicated as DATETIME.
$ For more information on datetime data types, see "Date and time data
types" on page 265.
List of functions The following date and time functions are available:
♦ "DATE function" on page 313
♦ "DATEADD function" on page 314
♦ "DATEDIFF function" on page 314
♦ "DATEFORMAT function" on page 316
♦ "DATENAME function" on page 316
♦ "DATEPART function" on page 317
♦ "DATETIME function" on page 317
♦ "DAY function" on page 318
♦ "DAYNAME function" on page 318
♦ "DAYS function" on page 318
♦ "DOW function" on page 321
♦ "GETDATE function" on page 326
♦ "HOUR function " on page 327
♦ "HOURS function " on page 327
♦ "MINUTE function" on page 336
♦ "MINUTES function" on page 336
♦ "MONTH function" on page 338
♦ "MONTHNAME function" on page 338
♦ "MONTHS function" on page 338
♦ "NOW function" on page 341
♦ "QUARTER function" on page 346
♦ "SECOND function" on page 351
♦ "SECONDS function" on page 351
♦ "TODAY function" on page 359
♦ "WEEKS function" on page 362
♦ "YEARS function" on page 363
293
Function types
Date parts
Many of the date functions use dates built from date parts. The following
table displays allowed values of date-parts.
User-defined You can implement your own functions in SQL using the "CREATE
functions in SQL FUNCTION statement" on page 432. The RETURN statement inside the
CREATE FUNCTION statement determines the data type of the function.
Once a SQL user-defined function is created, it can be used anywhere a
built-in function of the same data type is used.
$ For more information on creating SQL functions, see "Using
Procedures, Triggers, and Batches" on page 423 of the book ASA User’s
Guide.
User-defined Although SQL functions are useful, Java classes provide a more powerful
functions in Java and flexible way of implementing user-defined functions, with the additional
advantage that they can be moved from the database server to a client
application if desired.
Any class method of an installed Java class can be used as a user-defined
function anywhere a built-in function of the same data type is used.
Instance methods are tied to particular instances of a class, and so have
different behavior from standard user-defined functions.
$ For more information on creating Java classes, and on class methods,
see "A Java seminar" on page 509 of the book ASA User’s Guide.
Miscellaneous functions
Miscellaneous functions perform operations on arithmetic, string or date/time
expressions, including the return values of other functions.
List of functions The following miscellaneous functions are available:
♦ "ARGN function" on page 302
♦ "COALESCE function" on page 308
♦ "ESTIMATE function" on page 322
♦ "EXPERIENCE_ESTIMATE function" on page 326
♦ "ESTIMATE_SOURCE function" on page 322
♦ "IFNULL function" on page 328
♦ "INDEX_ESTIMATE function" on page 329
♦ "ISNULL function" on page 330
♦ "NULLIF function" on page 341
♦ "NUMBER function" on page 342
295
Function types
Numeric functions
Numeric functions perform mathematical operations on numerical data types
or return numeric information.
List of functions The following numeric functions are available:
♦ "ABS function" on page 301
♦ "ACOS function" on page 301
♦ "ASIN function" on page 302
♦ "ATAN function" on page 303
♦ "ATN2 function" on page 303
♦ "CEILING function" on page 306
♦ "COS function" on page 311
♦ "COT function" on page 312
♦ "DEGREES function" on page 321
♦ "EXP function" on page 325
♦ "FLOOR function" on page 326
♦ "LOG function" on page 333
♦ "LOG10 function" on page 334
♦ "MOD function" on page 337
♦ "PI function" on page 343
♦ "POWER function" on page 344
♦ "RADIANS function" on page 347
♦ "RAND function" on page 347
♦ "REMAINDER function" on page 348
♦ "ROUND function" on page 350
♦ "SIGN function" on page 352
♦ "SIN function" on page 353
♦ "SQRT function" on page 355
296
Chapter 8 SQL Functions
String functions
String functions perform conversion, extraction or manipulation operations
on strings, or return information about strings.
When working in a multi-byte character set, check carefully whether the
function being used returns information concerning characters or bytes.
List of functions The following string functions are available:
♦ "ASCII function " on page 302
♦ "BYTE_LENGTH function" on page 304
♦ "BYTE_SUBSTR function" on page 305
♦ "CHAR function" on page 307
♦ "CHARINDEX function" on page 307
♦ "CHAR_LENGTH function" on page 308
♦ "DIFFERENCE function" on page 321
♦ "INSERTSTR function" on page 329
♦ "LCASE function" on page 330
♦ "LEFT function" on page 331
♦ "LENGTH function" on page 331
♦ "LOCATE function" on page 333
♦ "LTRIM function" on page 334
♦ "PATINDEX function" on page 342
♦ "REPEAT function" on page 348
♦ "REPLACE function" on page 348
♦ "REPLICATE function" on page 349
♦ "RIGHT function" on page 350
♦ "RTRIM function" on page 351
♦ "SIMILAR function" on page 353
♦ "SOUNDEX function" on page 354
297
Function types
System functions
System functions return system information.
List of functions The following system functions are available:
♦ "CONNECTION_PROPERTY function " on page 309
♦ "DATALENGTH function" on page 313
♦ "DB_ID function" on page 319
♦ "DB_NAME function " on page 320
♦ "DB_PROPERTY function" on page 320
♦ "EVENT_CONDITION function" on page 323
♦ "EVENT_PARAMETER function" on page 324
♦ "NEXT_CONNECTION function" on page 339
♦ "NEXT_DATABASE function" on page 340
♦ "PROPERTY function" on page 345
♦ "PROPERTY_DESCRIPTION function" on page 344
♦ "PROPERTY_NAME function" on page 345
♦ "PROPERTY_NUMBER function" on page 346
Compatibility The following table shows the Adaptive Server Enterprise system functions
and their status in Adaptive Server Anywhere:
298
Chapter 8 SQL Functions
Function Status
Col_length Implemented
Col_name Implemented
Db_id Implemented
Db_name Implemented
Index_col Implemented
Object_id Implemented
Object_name Implemented
Proc_role Always returns 0
Show_role Always returns NULL
Tsequal Implemented
User_id Implemented
User_name Implemented
Suser_id Implemented
Suser_name Implemented
Datalength Implemented
Curunreservedpgs Not implemented
Data_pgs Not implemented
Host_id Not implemented
Host_name Not implemented
Lct_admin Not implemented
Reserved_pgs Not implemented
Rowcnt Not implemented
Used_pgs Not implemented
Valid_name Not implemented
Valid_user Not implemented
299
Function types
300
Chapter 8 SQL Functions
301
Alphabetical list of functions
expression An expression of any data type passed into the function. All
supplied expressions must be of the same data type.
Examples The following statement returns the value 6.
SELECT ARGN( 6, 1,2,3,4,5,6 )
Usage Using the value of the integer-expression as n, returns the n’th argument
(starting at 1) from the remaining list of arguments. While the expressions
can be of any data type, they must all be of the same data type. The integer
expression must be from one to the number of expressions in the list or
NULL is returned. Multiple expressions are separated by a comma.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
302
Chapter 8 SQL Functions
303
Alphabetical list of functions
304
Chapter 8 SQL Functions
Usage Trailing white space characters are included in the length returned.
The return value of a NULL string is NULL.
If the string is in a multi-byte character set, the BYTE_LENGTH value
differs from the number of characters returned by CHAR_LENGTH.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
See also "CHAR_LENGTH function" on page 308
"DATALENGTH function" on page 313
"LENGTH function" on page 331
305
Alphabetical list of functions
306
Chapter 8 SQL Functions
307
Alphabetical list of functions
emp_lname Emp_fname
Klobucher James
Kuo Felicia
Kelly Moira
Usage The position of the first character in the string being searched is 1.
If the string being searched contains more than one instance of the other
string, then CHARINDEX returns the position of the first instance.
If the string being searched does not contain the other string, then
CHARINDEX returns 0.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
See also "SUBSTRING function" on page 357
308
Chapter 8 SQL Functions
309
Alphabetical list of functions
format-style For converting strings to date or time data types and vice
versa, the format-style is a style code number that describes the date format
string to be used. The values of the format-style argument have the following
meanings:
310
Chapter 8 SQL Functions
order_date
16.03.1993
20.03.1993
23.03.1993
25.03.1993
...
order_date
mar 16, 93
mar 20, 93
mar 23, 93
mar 25, 93
...
311
Alphabetical list of functions
312
Chapter 8 SQL Functions
Examples The following statement returns the value 27, the longest string in the
company_name column.
SELECT following MAX( DATALENGTH( company_name ) )
FROM customer
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
313
Alphabetical list of functions
314
Chapter 8 SQL Functions
315
Alphabetical list of functions
316
Chapter 8 SQL Functions
date-expression The date for which the part is to be returned. The date
must contain the date-part field.
Example The following statement returns the value 5.
SELECT datepart( month , ’1987/05/02’ )
Standards and ♦ SQL/92 Transact-SQL extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
317
Alphabetical list of functions
318
Chapter 8 SQL Functions
The following statement returns the value 0 if executed against the only
running database.
SELECT DB_ID()
319
Alphabetical list of functions
320
Chapter 8 SQL Functions
321
Alphabetical list of functions
322
Chapter 8 SQL Functions
323
Alphabetical list of functions
324
Chapter 8 SQL Functions
325
Alphabetical list of functions
326
Chapter 8 SQL Functions
Examples The following statement returns the system date and time.
SELECT GETDATE( )
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
327
Alphabetical list of functions
328
Chapter 8 SQL Functions
329
Alphabetical list of functions
330
Chapter 8 SQL Functions
331
Alphabetical list of functions
DISTINCT column-name The name of a column that you are using in the
query. For each unique value of that column, the value is added to the
comma-separated result.
332
Chapter 8 SQL Functions
333
Alphabetical list of functions
334
Chapter 8 SQL Functions
Examples The following statement returns the value Test Message with all leading
blanks removed.
SELECT LTRIM( ’ Test Message’ )
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Compatible with Adaptive Server Enterprise.
See also "RTRIM function" on page 351
"TRIM function" on page 360
335
Alphabetical list of functions
336
Chapter 8 SQL Functions
337
Alphabetical list of functions
338
Chapter 8 SQL Functions
339
Alphabetical list of functions
The following call returns the the connection after connection-id (regardless
of database).
NEXT_CONNECTION( connection-id, NULL )
The following call returns the connection after connection-id on the specified
database.
NEXT_CONNECTION( connection-id, database-id )
The following call returns the first connection (regardless of database).
NEXT_CONNECTION(NULL, NULL)
The following call returns the first connection on the specified database.
NEXT_CONNECTION( NULL, database-id )
Usage NEXT_CONNECTION can be used to enumerate the connections to a
database. To get the first connection pass NULL; to get each subsequent
connection, pass the previous return value. The function returns NULL when
there are no more connections.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
340
Chapter 8 SQL Functions
341
Alphabetical list of functions
Deprecated feature
The NUMBER function is deprecated. It will not be supported in future
versions of Adaptive Server Anywhere.
Syntax NUMBER ( * )
Examples The following statement returns a numbered list.
SELECT NUMBER( * )
FROM department
WHERE dept_id > 5
Usage The NUMBER(*) function can be used to generate primary keys when using
the INSERT from SELECT statement (see "INSERT statement" on
page 540), although using AUTOINCREMENT is a preferred mechanism for
generating sequential primary keys.
$ For information on AUTOINCREMENT, see "CREATE TABLE
statement" on page 453.
You should not use NUMBER( * ) anywhere but in a select-list. If you do
use NUMBER( * ) rather than the preferred AUTOINCREMENT, you
should check your results carefully, as the behavior is not reliable in several
circumstances. For example, including the function in a WHERE clause or a
HAVING clause produces unpredictable results, and you should not include
NUMBER( * ) in a UNION operation.
In Embedded SQL, care should be exercised when using a cursor that
references a query containing a NUMBER(*) function. In particular, this
function returns negative numbers when a database cursor is positioned using
relative to the end of the cursor (an absolute position with a negative offset).
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
342
Chapter 8 SQL Functions
Parameters pattern The pattern to be searched for. If the leading percent wild card is
omitted, PATINDEX returns one (1) if the pattern occurs at the beginning of
the string, and zero if not.
The pattern uses the same wild cards as the LIKE comparison. These are as
follows:
PI function [Numeric]
Function Returns the numeric value PI.
Syntax PI ( * )
Examples The following statement returns the value 3.141592653....
SELECT PI( * )
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase The PI() function is supported in Adaptive Server Enterprise,
but PI(*) is not.
343
Alphabetical list of functions
345
Alphabetical list of functions
Examples The following statement returns the property associated with property
number 126. The actual property to which this refers changes from release to
release.
SELECT PROPERTY_NAME( 126 )
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
See also "Database properties" on page 1060
346
Chapter 8 SQL Functions
347
Alphabetical list of functions
348
Chapter 8 SQL Functions
349
Alphabetical list of functions
351
Alphabetical list of functions
352
Chapter 8 SQL Functions
353
Alphabetical list of functions
354
Chapter 8 SQL Functions
355
Alphabetical list of functions
start The character position at which to begin deleting characters. The first
character in the string is position 1.
356
Chapter 8 SQL Functions
357
Alphabetical list of functions
358
Chapter 8 SQL Functions
359
Alphabetical list of functions
Examples To use the traceback function, enter the following after an error occurs while
executing a procedure:
SELECT TRACEBACK ( * )
Usage This is useful for debugging procedures and triggers
Standards and ♦ SQL/92 Transact-SQL extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
360
Chapter 8 SQL Functions
361
Alphabetical list of functions
362
Chapter 8 SQL Functions
integer expression The number of the month. If the month is outside the
range 1-12, the year is adjusted accordingly.
364
C H A P T E R 9
SQL Statements
About this chapter This chapter presents detailed descriptions of the SQL statements that are
available to users of Adaptive Server Anywhere.
This chapter contains an alphabetical listing of SQL statements, including
some that can only be used from embedded SQL or Interactive SQL.
Contents The chapter includes an alphabetical list of SQL statements.
365
Using the SQL statement reference
366
Chapter 9 SQL Statements
Syntax conventions
The following conventions are used in the SQL syntax descriptions:
♦ Keywords All SQL keywords are shown like the words ALTER
TABLE in the following example:
ALTER TABLE [ owner.]table-name
♦ Placeholders Items that must be replaced with appropriate identifiers
or expressions are shown like the words owner and table-name in the
following example.
ALTER TABLE [ owner.]table-name
♦ Continuation Lines beginning with an ellipsis (…) are a continuation
from the previous line. For example,
ALTER TABLE [ owner.]table-name
… ADD column-definition [ column-constraint … ]
♦ Repeating items Lists of repeating items are shown with an element
of the list followed by an ellipsis (three dots), like column-constraint in
the following example:
ADD column-definition [ column-constraint … ]
One or more list elements are allowed. If more than one is specified,
they must be separated by commas.
367
Using the SQL statement reference
368
Chapter 9 SQL Statements
369
ALLOCATE DESCRIPTOR statement [ESQL]
370
Chapter 9 SQL Statements
371
ALTER DATABASE statement
JCONNECT clause If you wish to use the Sybase jConnect JDBC driver
to access system catalog information, you need to specify JCONNECT ON.
If you wish to exclude the jConnect system objects, specify JCONNECT
OFF. You can still use JDBC, as long as you do not access system catalog
information. The default is to include jConnect support (JCONNECT ON).
Setting JCONNECT OFF does not remove jConnect support from a
database.
Standards and ♦ SQL/92 Vendor extension
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Example ♦ Upgrade a Version 5 database to enable Java operations:
ALTER DATABASE UPGRADE
JAVA ON
372
Chapter 9 SQL Statements
RENAME clause If you rename or move a database file other than the
main file to a different directory or device, you can use ALTER DBSPACE
with the RENAME clause to ensure that Adaptive Server Anywhere finds the
new file when the database is started.
373
ALTER DBSPACE statement
374
Chapter 9 SQL Statements
Description This statement allows you to alter an event definition created with CREATE
EVENT. Possible uses include the following:
♦ You can use ALTER EVENT to change an event handler during
development.
♦ You may want to define and test an event handler without a trigger
condition or schedule during a development phase, and then add the
conditions for execution using ALTER EVENT once the event handler
is completed.
♦ You may want to disable an event handler temporarily by disabling the
event.
Parameters DELETE TYPE clause Removes an association of the event with an event
type.
376
Chapter 9 SQL Statements
377
ALTER SERVER statement
378
Chapter 9 SQL Statements
379
ALTER TABLE statement
380
Chapter 9 SQL Statements
table-constraint:
{ UNIQUE ( column-name, … )
| PRIMARY KEY ( column-name, … )
} [ WITH [ MAX | MAXIMUM ] HASH SIZE hash-size ]
| CHECK ( condition )
| foreign-key-constraint
foreign-key-constraint:
[ NOT NULL ] FOREIGN KEY [ role-name ] [ (column-name, … ) ]
… REFERENCES table-name [ (column-name, … ) ]
… [ actions ] [ CHECK ON COMMIT ]
… [ WITH [ MAX | MAXIMUM ] HASH SIZE hash-size ]
actions:
[ ON UPDATE action ] [ ON DELETE action ]
action:
CASCADE
| SET NULL
| SET DEFAULT
| RESTRICT
Syntax 2 ALTER TABLE [ owner.]table-name
… REPLICATE { ON | OFF }
Permissions Must be one of the following:
♦ The owner of the table
♦ A user with DBA authority.
♦ A user granted ALTER permission on the table.
ALTER TABLE requires exclusive access to the table.
Global temporary tables cannot be altered unless all users that have
referenced the temporary table have disconnected.
Side effects Automatic commit.
The MODIFY and DELETE (DROP) options close all cursors for the current
connection.
A checkpoint is carried out at the beginning of the ALTER TABLE
operation.
Once you alter a column or table, any stored procedures, views or other items
that refer to the altered column no longer work.
See also "CREATE TABLE statement" on page 453
"DROP statement" on page 491
"SQL Data Types" on page 251
"Using computed columns with Java classes" on page 572 of the book ASA
User’s Guide
"Altering tables" on page 124 of the book ASA User’s Guide
381
ALTER TABLE statement
Description Syntax 1 The ALTER TABLE statement changes table attributes (column
definitions, constraints) in a table that was previously created. Note that the
syntax allows a list of alter clauses; however, only one table-constraint or
column-constraint can be added, modified or deleted in one ALTER TABLE
statement.
You cannot use ALTER TABLE on a local temporary table.
ALTER TABLE is prevented whenever the statement affects a table that is
currently being used by another connection. ALTER TABLE can be time-
consuming, and the server will not process requests referencing the table
while the statement is being processed.
Before version 5.0, all table and column constraints were held in a single
table constraint. Consequently, for these databases individual constraints on
columns cannot be deleted using the MODIFY column-name CHECK NULL
clause or replaced using the MODIFY column-name CHECK (condition )
clause. To use these statements, the entire table constraint should be deleted
and the constraints added back using the MODIFY column-name CHECK
(condition ) clause. At this point you can use MODIFY CHECK.
Syntax 2 When a table has REPLICATE ON, all changes to the table are
sent to Replication Server for replication. The replication definitions in
Replication Server are used to decide which table changes are sent to other
sites. The remainder of this section describes syntax 1.
Parameters ADD column-definition Add a new column to the table. The table must
be empty or the column must have a default if you specify NOT NULL.
If the column has a default value, all rows of the new column are populated
with that default value.
NULL values
Adaptive Server Anywhere optimizes the creation of columns that are
allowed to contain NULL. The first column allowed to contain NULL
allocates room for eight such columns, and initializes all eight to be
NULL. (This requires no extra storage.) Thus, the next seven columns
added require no changes to the rows of the table.
Adding a ninth column then allocates room for another eight such
columns and modifies each row of the table to allocate the extra space.
Consequently, seven out of eight column additions run quickly.
382
Chapter 9 SQL Statements
If PRIMARY KEY is specified, the table must not already have a primary
key that was created by the CREATE TABLE statement or another
ALTER TABLE statement.
383
ALTER TABLE statement
DELETE column-name Delete the column from the table. If the column
is contained in any index, uniqueness constraint, foreign key, or primary key
then the index, constraint, or key must be deleted before the column can be
deleted. This does not delete CHECK constraints that refer to the column.
DELETE CHECK Delete all check constraints for the table. This includes
both table check constraints and column check constraints.
DELETE PRIMARY KEY Delete the primary key constraint for this table.
All foreign keys referencing the primary key for this table will also be
deleted.
DELETE FOREIGN KEY role-name Delete the foreign key constraint for
this table with the given role name.
384
Chapter 9 SQL Statements
385
ALTER TRIGGER statement
386
Chapter 9 SQL Statements
387
ALTER WRITEFILE statement
388
Chapter 9 SQL Statements
BACKUP statement
Function Use this statement to back up a database and transaction log.
Syntax 1 (image BACKUP DATABASE
backup) DIRECTORY backup-directory
[ WAIT BEFORE START ]
[ DBFILE ONLY ]
[ TRANSACTION LOG ONLY ]
[ TRANSACTION LOG RENAME [ MATCH ] ]
[ TRANSACTION LOG TRUNCATE ]
backup-directory: string
Syntax 2 (archive BACKUP DATABASE TO archive-root
backup) [ ATTENDED { ON | OFF } ]
[ WITH COMMENT comment string ]
archive-root: string
comment-string: string
Permissions Must have DBA authority.
Side effects Causes a checkpoint.
See also "RESTORE statement" on page 577
"Backup and Data Recovery" on page 627 of the book ASA User’s Guide
Description Syntax 1 An image backup creates copies of each of the database files, in
the same way as the Backup utility (dbbackup). In the case of the BACKUP
statement, however, the backup is made on the server, while the Backup
utility makes the backup from a client machine.
Optionally, only the database file(s) or transaction log can be saved. The log
may also be renamed or truncated after the backup has completed.
To restore from an image backup, copy the saved files back to their original
locations and reapply transaction logs as described in the chapter "Backup
and Data Recovery" on page 627 of the book ASA User’s Guide.
Syntax 2 An archive backup creates a single file holding all the required
backup information. The destination can be either a file name or a tape drive
device name.
There can be only one backup on a given tape. The file backup.syb records
the BACKUP and RESTORE operations that have been performed on a
given server.
The tape is ejected at the end of the backup.
389
BACKUP statement
WAIT BEFORE START clause This clause ensures that the backup copy
of the database does not contain any information required for recovery. In
particular, it ensures that the rollback log for each connection is empty.
If a backup is carried out using this clause, you can start the backup copy of
the database in read-only mode and validate it. By enabling validation of the
backup database, the customer can avoid making an additional copy of the
database.
MATCH keyword If you supply the MATCH keyword, the backup copy
of the transaction log is given a name of the form YYMMDDnn.log. This
enables the same statement to be executed several times without writing over
old data.
archive-root The file name or tape drive device name for the archive file.
To back up to tape, you must specify the device name of the tape drive. For
example, on Windows NT or NetWare, the first tape drive is \\.\tape0.
The ’\’ is an escape character in SQL strings, so each backslash must be
doubled. For more information on escape characters and strings, see
"Strings" on page 212.
WITH COMMENT Record a comment in the archive file and in the backup
history file.
391
BEGIN statement
BEGIN statement
Function Use this statement to group SQL statements together.
Syntax [ statement-label : ]
… BEGIN [ [ NOT ] ATOMIC ]
… [ local-declaration; … ]
… statement-list
… [ EXCEPTION [ exception-case … ] ]
… END [ statement-label ]
local-declaration:
variable-declaration
| cursor-declaration
| exception-declaration
| temporary-table-declaration
variable-declaration:
DECLARE variable-name data-type
exception-declaration:
DECLARE exception-name EXCEPTION
FOR SQLSTATE [ VALUE ] string
exception-case:
WHEN exception-name [, … ] THEN statement-list
| WHEN OTHERS THEN statement-list
Permissions None.
Side effects None.
See also "DECLARE CURSOR statement" on page 475
"DECLARE LOCAL TEMPORARY TABLE statement" on page 481
"LEAVE statement" on page 544
"SIGNAL statement" on page 603
"RESIGNAL statement" on page 576
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The body of a procedure or trigger is a compound statement. Compound
statements can also be used in control statements within a procedure or
trigger.
A compound statement allows one or more SQL statements to be grouped
together and treated as a unit. A compound statement starts with the keyword
BEGIN and ends with the keyword END.
392
Chapter 9 SQL Statements
393
BEGIN statement
CustomerLoop:
LOOP
FETCH NEXT curThisCust
INTO ThisCompany, ThisValue;
IF SQLSTATE = err_notfound THEN
LEAVE CustomerLoop;
END IF;
IF ThisValue > TopValue THEN
SET TopValue = ThisValue;
SET TopCompany = ThisCompany;
END IF;
END LOOP CustomerLoop;
CLOSE curThisCust;
END
394
Chapter 9 SQL Statements
395
BEGIN TRANSACTION statement
Caution
When calling a stored procedure, you should ensure that it operates
correctly under the required transaction mode.
396
Chapter 9 SQL Statements
397
CALL statement
CALL statement
Function Use this statement to invoke a procedure.
Syntax 1 [variable = ] CALL procedure-name ( [ expression, … ] )
Syntax 2 [variable = ] CALL procedure-name ( [ parameter-name = expression, … ] )
Permissions Must be the owner of the procedure, have EXECUTE permission for the
procedure, or have DBA authority.
Side effects None.
See also "CREATE PROCEDURE statement" on page 440
"GRANT statement" on page 526
"EXECUTE statement" on page 502
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The CALL statement invokes a procedure that has been previously created
with a CREATE PROCEDURE statement. When the procedure completes,
any INOUT or OUT parameter values will be copied back.
The argument list can be specified by position or by using keyword format.
By position, the arguments will match up with the corresponding parameter
in the parameter list for the procedure. By keyword, the arguments are
matched up with the named parameters.
Procedure arguments can be assigned default values in the CREATE
PROCEDURE statement, and missing parameters are assigned the default
value or. If no default is set, and an argument is not provided, an error is
given.
Inside a procedure, a CALL statement can be used in a DECLARE statement
when the procedure returns result sets (see "Returning results from
procedures" on page 453 of the book ASA User’s Guide).
Procedures can return an integer value (as a status indicator, say) using the
RETURN statement. You can save this return value in a variable using the
equality sign as an assignment operator:
CREATE VARIABLE returnval INT;
returnval = CALL proc_integer ( arg1 = val1, ... )
$ For information on returning non-integer values, see "CREATE
FUNCTION statement" on page 432.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise. For an
alternative that is supported, see "EXECUTE statement" on page 502.
398
Chapter 9 SQL Statements
399
CASE statement
CASE statement
Function Use this statement to select an execution path based on multiple cases.
Syntax CASE value-expression
… WHEN [ constant | NULL ] THEN statement-list …
… [ WHEN [ constant | NULL ] THEN statement-list ] …
… ELSE statement-list
… END CASE
Permissions None.
Side effects None.
See also "BEGIN statement" on page 392
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The CASE statement is a control statement that allows you to choose a list of
SQL statements to execute based on the value of an expression. If a WHEN
clause exists for the value of value-expression, the statement-list in the
WHEN clause is executed. If no appropriate WHEN clause exists, and an
ELSE clause exists, the statement-list in the ELSE clause is executed.
Execution resumes at the first statement after the END CASE.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Example The following procedure using a case statement classifies the products listed
in the product table of the sample database into one of shirt, hat, shorts, or
unknown.
The following procedure uses a case statement to classify the results of a
query.
CREATE PROCEDURE ProductType (IN product_id INT, OUT
type CHAR(10))
BEGIN
DECLARE prod_name CHAR(20);
SELECT name INTO prod_name FROM "DBA"."product"
WHERE id = product_id;
CASE prod_name
WHEN ’Tee Shirt’ THEN
SET type = ’Shirt’
WHEN ’Sweatshirt’ THEN
SET type = ’Shirt’
WHEN ’Baseball Cap’ THEN
SET type = ’Hat’
WHEN ’Visor’ THEN
SET type = ’Hat’
400
Chapter 9 SQL Statements
401
CHECKPOINT statement
CHECKPOINT statement
Function Use this statement to checkpoint the database.
Syntax CHECKPOINT
Permissions DBA authority is required to checkpoint the network database server.
No permissions are required to checkpoint the personal database server.
Side effects None.
See also "CHECKPOINT_TIME option" on page 165
"RECOVERY_TIME option" on page 195
Description The CHECKPOINT statement forces the database server to execute a
checkpoint. Checkpoints are also performed automatically by the database
server according to an internal algorithm. It is not normally required for
applications issue the CHECKPOINT statement.
$ For a full description of checkpoints, see "Backup and Data Recovery"
on page 627 of the book ASA User’s Guide.
Standards and ♦ SQL/92 Vendor extension
compatibility
♦ Sybase Supported by Adaptive Server Enterprise.
402
Chapter 9 SQL Statements
403
CLOSE statement [ESQL] [SP]
404
Chapter 9 SQL Statements
CustomerLoop:
LOOP
FETCH NEXT curThisCust
INTO ThisCompany, ThisValue;
IF SQLSTATE = err_notfound THEN
LEAVE CustomerLoop;
END IF;
IF ThisValue > TopValue THEN
SET TopValue = ThisValue;
SET TopCompany = ThisCompany;
END IF;
END LOOP CustomerLoop;
CLOSE curThisCust;
END
405
COMMENT statement
COMMENT statement
Function Use this statement to store a comment in the system tables for a database
object.
Syntax COMMENT ON
{
COLUMN [ owner.]table-name.column-name
| EVENT event-name
| FOREIGN KEY [ owner.]table-name.role-name
| INDEX [ owner.]index-name
| JAVA CLASS java-class-name
| JAVA JAR java-jar-name
| LOGIN integrated_login_id
| PROCEDURE [ owner.]procedure-name
| TABLE [ owner.]table-name
| TRIGGER [ owner.]trigger-name
| USER userid
| VIEW [ owner.]view-name
}
IS comment
comment:
{ string | NULL }
Permissions Must either be the owner of the database object being commented, or have
DBA authority.
Side effects Automatic commit.
Description Several system tables have a column named Remarks that allows you to
associate a comment with a database item (SYSUSERPERM, SYSTABLE,
SYSCOLUMN, SYSINDEX, SYSLOGIN, SYSFOREIGNKEY,
SYSPROCEDURE, SYSTRIGGER). The COMMENT ON statement allows
you to set the Remarks column in these system tables. A comment can be
removed by setting it to NULL.
For a comment on an index or trigger, the owner of the comment is the
owner of the table on which the index or trigger is defined.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Examples The following examples show how to add and remove a comment.
♦ Add a comment to the employee table.
COMMENT
ON TABLE employee
IS ’Employee information’
406
Chapter 9 SQL Statements
407
COMMIT statement
COMMIT statement
Function Use this statement to make changes to the database permanent, or to
terminate a user-defined transaction.
Syntax 1 COMMIT [ WORK ]
Syntax 2 COMMIT TRAN[SACTION] [ transaction-name ]
Permissions None.
Side effects Closes all cursors except those opened WITH HOLD.
Deletes all rows of declared temporary tables on this connection, unless they
were declared using ON COMMIT PRESERVE ROWS..
See also "BEGIN TRANSACTION statement" on page 395
"PREPARE TO COMMIT statement" on page 566
"ROLLBACK statement" on page 583
Description Syntax 1 The COMMIT statement ends a transaction and makes all
changes made during this transaction permanent in the database.
Data definition statements all carry out a commit automatically. For
information, see the Side effects listing for each SQL statement.
The COMMIT statement fails if the database server detects any invalid
foreign keys. This makes it impossible to end a transaction with any invalid
foreign keys. Usually, foreign key integrity is checked on each data
manipulation operation. However, if the database option
WAIT_FOR_COMMIT is set ON or a particular foreign key was defined
with a CHECK ON COMMIT clause, the database server delays integrity
checking until the COMMIT statement is executed.
Syntax 2 You can use BEGIN TRANSACTION and COMMIT
TRANSACTION statements in pairs to construct nested transactions.
Nested transactions are similar to savepoints. When executed as the
outermost of a set of nested transactions, the statement makes changes to the
database permanent. When executed inside a transaction, the COMMIT
TRANSACTION statement decreases the nesting level of transactions by
one. When transactions are nested, only the outermost COMMIT makes the
changes to the database permanent.
Parameters transaction-name An optional name assigned to this transaction. It must
be a valid identifier. You should use transaction names only on the outermost
pair of nested BEGIN/COMMIT or BEGIN/ROLLBACK statements.
408
Chapter 9 SQL Statements
409
CONFIGURE statement [Interactive SQL]
410
Chapter 9 SQL Statements
411
CONNECT statement [ESQL] [Interactive SQL]
Standards and ♦ SQL/92 Syntax 1 is a full SQL feature; syntax 2 is a vendor extension.
compatibility
♦ Sybase Open Client Embedded SQL supports a different syntax for
the CONNECT statement.
Examples ♦ The following are examples of CONNECT usage within Embedded
SQL.
EXEC SQL CONNECT AS :conn_name
USER :userid IDENTIFIED BY :password;
EXEC SQL CONNECT USER "dba" IDENTIFIED BY "sql";
♦ Connect to a database from Interactive SQL. Interactive SQL prompts
for a user ID and a password.
CONNECT
♦ Connect to the default database as DBA, from Interactive SQL.
Interactive SQL promptS for a password.
CONNECT USER "DBA"
♦ Connect to the sample database as the DBA, from Interactive SQL.
CONNECT
TO asademo
USER DBA
IDENTIFIED BY sql
♦ Connect to the sample database using a connect string, from
Interactive SQL.
CONNECT
USING ’UID=DBA;PWD=sql;DBN=asademo’
413
CREATE COMPRESSED DATABASE statement
Permissions ♦ The permissions required to execute this statement are set on the server
command line, using the -gu command-line option. The default setting
is to require DBA authority.
♦ The operating system account under which the server is running must
have write permissions on the directories where files are created.
♦ The old database file must not be currently running.
♦ Not supported on Windows CE.
Side effects An operating system file is created.
See also "The Compression utility" on page 81
"The Uncompression utility" on page 124
Description Creates a compressed database file from an uncompressed database file, or
an uncompressed database file from a compressed one.
Any relative path is resolved relative to the current working directory of the
server.
You cannot use this statement on files other than the main database file.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Example ♦ The following statement creates a compressed database file named
compress.db in the C:\ directory from a database file named full.db in the
current working directory of the server.
CREATE COMPRESSED DATABASE ’C:\\compress.db’
FROM ’full.db’
♦ The following statement creates an uncompressed database file named
full.db in the C:\ directory from a compressed database file named
compress.db in the current working directory of the server.
CREATE EXPANDED DATABASE ’C:\\full.db’
FROM ’compress.db’
414
Chapter 9 SQL Statements
Permissions The permissions required to execute this statement are set on the server
command line, using the -gu command-line option. The default setting is to
require DBA authority.
The account under which the server is running must have write permissions
on the directories where files are created.
Not supported on Windows CE.
Side effects An operating system file is created.
See also "ALTER DATABASE statement" on page 371
"DROP DATABASE statement" on page 493
"The Initialization utility" on page 92
Description Creates a database file with the supplied name and attributes.
Parameters File name The file names ( db-file-name-string, log-file-name-string,
mirror-file-name-string) are strings containing operating system file names.
As literal strings, they must be enclosed in single quotes.
415
CREATE DATABASE statement
CASE clause For databases created with CASE RESPECT, all values are
case sensitive in comparisons and string operations.
This option is provided for compatibility with the ISO/ANSI SQL standard.
The default value for the option is CASE IGNORE; that is, all comparisons
are case insensitive. If you create a case-sensitive database, all passwords are
case sensitive. User IDs and other identifiers in the database are case
insensitive, even in case sensitive databases.
PAGE SIZE clause The page size for a database can be 1024, 2048, 4096,
8192, 16384, or 32768 bytes. The default page size is 2048 bytes. Large
databases generally obtain performance benefits from a larger page size, but
there can be additional overhead associated with large page sizes.
$ For more information, see "Information utility options" on page 90.
For example:
CREATE DATABASE ’c:\\sybase\\my_db.db’
PAGE SIZE 4096
416
Chapter 9 SQL Statements
JCONNECT clause If you wish to use the Sybase jConnect JDBC driver
to access system catalog information, you need to install jConnect support.
Specify JCONNECT OFF if you wish to exclude the jConnect system
objects. You can still use JDBC, as long as you do not access system
information.
JAVA clause If you wish to use Java in your database, you must install
entries for the Sybase runtime Java classes into the system tables. By default,
these entries are installed. You can specify JAVA OFF if you are sure you
will not be using Java, to avoid installing these entries.
Standards and ♦ SQL/92 Vendor extension.
compatibility
417
CREATE DATABASE statement
418
Chapter 9 SQL Statements
419
CREATE DBSPACE statement
420
Chapter 9 SQL Statements
421
CREATE DOMAIN statement
422
Chapter 9 SQL Statements
423
CREATE EVENT statement
424
Chapter 9 SQL Statements
425
CREATE EVENT statement
426
Chapter 9 SQL Statements
1 If the EVERY clause is used, find whether the next scheduled time falls
on the current day, and is before the end of the BETWEEN … AND
range. If so, that is the next scheduled time.
2 If the next scheduled time does not fall on the current day, find the next
date on which the event is to be executed.
3 Find the START TIME for that date, or the beginning of the BETWEEN
… AND range.
427
CREATE EXISTING TABLE statement
428
Chapter 9 SQL Statements
429
CREATE EXTERNLOGIN statement
REMOTE LOGIN clause The REMOTE LOGIN clause specifies the user
account on remote-server for the local user login-name.
431
CREATE FUNCTION statement
432
Chapter 9 SQL Statements
fullname(’joe’, ’smith’)
joe smith
433
CREATE FUNCTION statement
434
Chapter 9 SQL Statements
435
CREATE INDEX statement
WITH HASH SIZE clause By default, at most ten bytes of each index
entry is actually hashed (stored in the index). If a query needs access to more
than the hashed data, it needs to fetch it from the underlying row, and this
may affect index performance. You can explicitly configure the amount of
data that is stored in the index by specifying WITH HASH SIZE. Increasing
the hash size can reduce the number of times the underlying row needs to be
accessed. However, this is at the expense of a decreased index fanout. For
optimal performance, you should not increase hash size for all indexes, only
for indexes for which the first ten bytes of data does not provide high
selectivity.
If the data in the index does not require the whole space set aside by the
WITH HASH clause, it is not used. For example, a single column index
holding an integer (four bytes) takes only five bytes for each index entry,
even if the WITH HASH clause specifies a larger value.
The maximum hash size is 64 bytes.
The MAX and SIZE keywords are optional.
436
Chapter 9 SQL Statements
The MAX_HASH_SIZE database option changes the default hash size for
indexes.
$ For more information, see "How indexes work" on page 795 of the
book ASA User’s Guide.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Adaptive Server Enterprise has a more complex CREATE
INDEX statement than Adaptive Server Anywhere. While the Adaptive
Server Enterprise syntax is permitted in Adaptive Server Anywhere,
some clauses and keywords are ignored.
The full syntax for Adaptive Server Enterprise 11.5 is as follows:
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ]
… INDEX index-name
… ON [ [ database.]owner.]table_name
(column_name [, column_name], …)
… [ WITH {
… { FILLFACTOR | MAX_ROWS_PER_PAGE } = x,
CONSUMERS = x,
… IGNORE_DUP_KEY,
… SORTED_DATA,
[ IGNORE_DUP_ROW | ALLOW_DUP_ROW ]
}]
… [ ON segment_name ]
Adaptive Server Enterprise indexes can be either clustered or
nonclustered. A clustered index almost always retrieves data faster than
a nonclustered index. Only one clustered index is permitted per table.
Adaptive Server Anywhere does not support clustered indexes. The
CLUSTERED and NONCLUSTERED keywords are allowed by
Adaptive Server Anywhere, but no action is taken.
Adaptive Server Anywhere also allows, by ignoring, the following
keywords:
♦ FILLFACTOR
♦ IGNORE_DUP_KEY
♦ SORTED_DATA
♦ IGNORE_DUP_ROW
437
CREATE INDEX statement
♦ ALLOW_DUP_ROW
Physical placement of an index is carried out differently in Adaptive
Server Enterprise and Adaptive Server Anywhere. The ON segment-
name clause is supported in Adaptive Server Anywhere, but segment-
name refers to a dbspace.
Unique indexes in Adaptive Server Anywhere permit entries that contain
NULL, and are otherwise identical. Unique indexes in Adaptive Server
Enterprise do not permit entries that contain NULL and are otherwise
identical.
Index names must be unique on a given table for both Adaptive Server
Anywhere and Enterprise.
Examples ♦ Create a two-column index on the employee table.
CREATE INDEX employee_name_index
ON employee
( emp_lname, emp_fname )
♦ Create an index on the sales_order_items table for the prod_id column.
CREATE INDEX item_prod
ON sales_order_items
( prod_id )
438
Chapter 9 SQL Statements
439
CREATE PROCEDURE statement
440
Chapter 9 SQL Statements
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The CREATE PROCEDURE statement creates a procedure in the database.
Users with DBA authority can create procedures for other users by
specifying an owner. A procedure is invoked with a CALL statement.
Parameters CREATE PROCEDURE clause Parameter names must conform to the
rules for other database identifiers such as column names. They must be a
valid SQL data type (see "SQL Data Types" on page 251), and must be
prefixed by one of the keywords IN, OUT or INOUT. The keywords have
the following meanings:
♦ IN The parameter is an expression that provides a value to the
procedure.
♦ OUT The parameter is a variable that could be given a value by the
procedure.
♦ INOUT The parameter is a variable that provides a value to the
procedure, and could be given a new value by the procedure.
When procedures are executed using the CALL statement, not all parameters
need to be specified. If a default value is provided in the CREATE
PROCEDURE statement, missing parameters are assigned the default values.
If an argument is not provided in the CALL statement, and no default is set,
an error is given.
SQLSTATE and SQLCODE are special parameters that output the
SQLSTATE or SQLCODE value when the procedure ends (they are OUT
parameters). Whether or not a SQLSTATE and SQLCODE parameter is
specified, the SQLSTATE and SQLCODE special values can always be
checked immediately after a procedure call to test the return status of the
procedure.
The SQLSTATE and SQLCODE special values are modified by the next
SQL statement. Providing SQLSTATE or SQLCODE as procedure
arguments allows the return code to be stored in a variable.
RESULT clause The RESULT clause declares the number and type of
columns in the result set. The parenthesized list following the RESULT
keyword defines the result column names and types. This information is
returned by the Embedded SQL DESCRIBE or by ODBC SQLDescribeCol
when a CALL statement is being described. Allowable data types are listed
in "SQL Data Types" on page 251.
$ For more information on returning result sets from procedures, see
"Returning results from procedures" on page 453 of the book ASA User’s
Guide.
441
CREATE PROCEDURE statement
Some procedures can more than one result set, with different numbers of
columns, depending on how they are executed. For example, the following
procedure returns two columns under some circumstances, and one in others.
CREATE PROCEDURE names( IN formal char(1))
BEGIN
IF formal = ’n’ THEN
SELECT emp_fname
FROM employee
ELSE
SELECT emp_lname,emp_fname
FROM employee
END IF
END
Procedures with variable result sets must be written without a RESULT
clause, or in Transact-SQL. Their use is subject to the following limitations:
♦ Embedded SQL You must DESCRIBE the procedure call after the
cursor for the result set is opened, but before any rows are returned, in
order to get the proper shape of result set. The CURSOR cursor-name
clause on the DESCRIBE statement is required.
♦ ODBC Variable result-set procedures can be used by ODBC
applications. The proper description of the result sets is carried out by
the ODBC driver.
♦ Open Client applications Variable result-set procedures can be used
by Open Client applications.
If your procedure returns only one result set, you should use a RESULT
clause. The presence of this clause prevents ODBC and Open Client
applications from re-describing the result set after a cursor is open.
In order to handle multiple result sets, ODBC must describe the currently
executing cursor, not the procedure’s defined result set. Therefore, ODBC
does not always describe column names as defined in the RESULT clause of
the procedure definition. To avoid this problem, use column aliases in the
SELECT statement that generates the result set.
442
Chapter 9 SQL Statements
♦ SELECT @variable =
♦ CASE
♦ LOOP
♦ LEAVE
♦ CONTINUE
♦ CALL
♦ EXECUTE
♦ SIGNAL
♦ RESIGNAL
♦ DECLARE
♦ SET VARIABLE
You should not use explicit error handling code with an ON EXCEPTION
RESUME clause.
$ For more information, see "ON_TSQL_ERROR option" on page 189.
EXTERNAL NAME clause A procedure using the EXTERNAL NAME
clause is a wrapper around a call to an external library. A stored procedure
using EXTERNAL NAME can have no other clauses following the
parameter list.
$ For information about external library calls, see "Calling external
libraries from procedures" on page 475 of the book ASA User’s Guide.
443
CREATE PROCEDURE statement
DYNAMIC RESULT SETS clause This clause is for use with procedures
that are wrappers around Java methods. If the DYNAMIC RESULT SETS
clause is not provided, it is assumed that the method returns no result set.
For example,
double some_method(
boolean a,
int b,
java.math.BigDecimal c,
byte [][] d,
java.sql.ResultSet[] d ) {
}
444
Chapter 9 SQL Statements
445
CREATE PROCEDURE statement
446
Chapter 9 SQL Statements
448
Chapter 9 SQL Statements
449
CREATE SCHEMA statement
450
Chapter 9 SQL Statements
451
CREATE SERVER statement
READ ONLY The READ ONLY clause specifies that the remote server is
a read-only data source. Any update request is rejected by Adaptive Server
Anywhere.
Standards and ♦ SQL/92 Entry-level feature.
compatibility
♦ Sybase Supported by Open Client/Open Server.
Examples ♦ Create an Adaptive Server Anywhere remote server named testasa,
located on the machine apple and listening on port number 2638, use:
CREATE SERVER testasa
CLASS ’asajdbc’
USING ’apple:2638’
♦ Create a remote server for the JDBC-based Adaptive Server named
ase_prod. Its machine name is banana and port number is 3025.
CREATE SERVER ase_prod
CLASS ’asejdbc’
USING ’banana:3025’
♦ Create a remote server for the Oracle server named oracle723. Its ODBC
Data Source Name is oracle723.
CREATE SERVER oracle723
CLASS ’oraodbc’
USING ’oracle723’
452
Chapter 9 SQL Statements
453
CREATE TABLE statement
454
Chapter 9 SQL Statements
For example, the following statement maps the table a1 to the MS Access
file mydbfile.mdb:
CREATE TABLE a1
AT ’access;d:\mydbfile.mdb;;a1’
$ For information on remote servers, see "CREATE SERVER statement"
on page 451. For information on proxy tables, see "CREATE EXISTING
TABLE statement" on page 428.
Foreign key definitions are ignored on remote tables. Foreign key definitions
on local tables that refer to remote tables are also ignored. Primary key
definitions are sent to the remote server if the server supports primary keys.
The COMPUTE clause is ignored for remote tables.
455
CREATE TABLE statement
456
Chapter 9 SQL Statements
457
CREATE TABLE statement
Constraints Column and table constraints help ensure the integrity of data
in the database. If a statement would cause a violation of a constraint,
execution of the statement does not complete, any changes made by the
statement before error detection are undone, and an error is reported. Column
constraints are abbreviations for the corresponding table constraints.
For example, the following statements are equivalent:
CREATE TABLE Product (
product_num integer UNIQUE
)
CREATE TABLE Product (
product_num integer,
UNIQUE ( product_num )
)
Column constraints are normally used unless the constraint references more
than one column in the table. In these cases, a table constraint must be used.
Constraints include the following:
♦ CHECK This allows arbitrary conditions to be verified. For example, a
check constraint could be used to ensure that a column called Sex only
contains the values M or F.
458
Chapter 9 SQL Statements
459
CREATE TABLE statement
The order of the columns in a primary key is the order in which the
columns were created in the table, not the order in which they are listed
when the primary key is created.
$ For information on the WITH HASH clause that can be used with
this constraint, see "CREATE INDEX statement" on page 435.
♦ Foreign key A foreign key constraint can be implemented using a
REFERENCES column constraint (single column only) or a FOREIGN
KEY table constraint. It restricts the values for a set of columns to match
the values in a primary key or, less commonly, a unique constraint of
another table (the primary table). For example, a foreign key constraint
could be used to ensure that a customer number in an invoice table
corresponds to a customer number in the customer table.
If you specify column name in a REFERENCES column constraint, it
must be a column in the primary table, must be subject to a unique
constraint or primary key constraint, and that constraint must consist of
only that one column. If you do not specify column-name, the foreign
key references the primary key of the primary table.
If you do not explicitly define a foreign key column, it is created with
the same data type as the corresponding column in the primary table.
These automatically-created columns cannot be part of the primary key
of the foreign table. Thus, a column used in both a primary key and
foreign key of the same table must be explicitly created.
If foreign key column names are specified, then primary key column
names must also be specified, and the column names are paired
according to position in the lists. If the primary table column names are
not specified in a FOREIGN KEY table constraint, then the primary key
columns are used. If foreign key column names are not specified then
the foreign key columns are give the same names as the columns in the
primary table.
If at least one value in a multi-column foreign key is NULL, there is no
restriction on the values that can be held in other columns of the key.
A temporary table cannot have a foreign key that references a base table
and a base table cannot have a foreign key that references a temporary
table.
♦ NOT NULL Disallow NULL in the foreign key columns. A NULL
in a foreign key means that no row in the primary table corresponds
to this row in the foreign table.
♦ role-name The role name is the name of the foreign key. The
main function of the role name is to distinguish two foreign keys to
the same table. If no role name is specified, the role name is
assigned as follows:
460
Chapter 9 SQL Statements
1 If there is no foreign key with a role name the same as the table
name, the table name is assigned as the role name.
2 If the table name is already taken, the role name is the table
name concatenated with a zero-padded three-digit number
unique to the table.
♦ action The referential integrity action defines the action to be
taken to maintain foreign key relationships in the database.
Whenever a primary key value is changed or deleted from a
database table, there may be corresponding foreign key values in
other tables that should be modified in some way. You can specify
either an ON UPDATE clause, an ON DELETE clause, or both,
followed by one of the following actions:
♦ CASCADE When used with ON UPDATE, updates the
corresponding foreign keys to match the new primary key
value. When used with ON DELETE, deletes the rows from the
foreign table that match the deleted primary key.
♦ SET NULL Sets to NULL all the foreign key values that
correspond to the updated or deleted primary key.
♦ SET DEFAULT Sets foreign key values that match the
updated or deleted primary key value to values specified on the
DEFAULT clause of each foreign key column.
♦ RESTRICT Generates an error if an attempt is made to update
or delete a primary key value while there are corresponding
foreign keys elsewhere in the database. RESTRICT is the
default action.
♦ CHECK ON COMMIT The CHECK ON COMMIT clause
overrides the WAIT_FOR_COMMIT database option, and causes
the database server to wait for a COMMIT before checking
RESTRICT actions on a foreign key. The CHECK ON COMMIT
clause does not delay CASCADE, SET NULL, or SET DEFAULT
actions.
If you use CHECK ON COMMIT with out specifying any actions,
then RESTRICT is implied as an action for UPDATE and
DELETE.
$ For information on the WITH HASH clause that can be used with
this constraint, see "CREATE INDEX statement" on page 435.
Standards and ♦ SQL/92 Entry level feature.
compatibility
The following are vendor extensions:
♦ The { IN | ON } dbspace-name clause.
461
CREATE TABLE statement
♦ Create tables for a sales database to hold order and order item
information.
CREATE TABLE Orders (
order_num INTEGER NOT NULL PRIMARY KEY,
date_ordered DATE,
name CHAR(80)
);
CREATE TABLE Order_item (
order_num INTEGER NOT NULL,
item_num SMALLINT NOT NULL,
PRIMARY KEY (order_num, item_num),
-- When an order is deleted, delete all of its
-- items.
FOREIGN KEY (order_num)
REFERENCES Orders (order_num)
ON DELETE CASCADE
)
463
CREATE TRIGGER statement
ORDER clause Triggers of the same type (insert, update, or delete) that
fire at the same time (before, after, or resolve) can use the ORDER clause to
determine the order that the triggers are fired.
WHEN clause The trigger fires only for rows where the search-condition
evaluates to true. The WHEN clause can be used only with row level
triggers.
465
CREATE TRIGGER statement
Standards and ♦ SQL/92 Persistent stored module feature. Some clauses are vendor
compatibility extensions.
♦ Sybase This syntax is different to that supported by Adaptive Server
Enterprise.
Example ♦ When a new department head is appointed, update the manager_id
column for employees in that department.
CREATE TRIGGER tr_manager
BEFORE UPDATE OF dept_head_id
ON department
REFERENCING OLD AS old_dept NEW AS new_dept
FOR EACH ROW
BEGIN
UPDATE employee
SET employee.manager_id=new_dept.dept_head_id
WHERE employee.dept_id=old_dept.dept_id
END
466
Chapter 9 SQL Statements
467
CREATE VARIABLE statement
468
Chapter 9 SQL Statements
column-name The columns in the view are given the names specified in
the column-name list. If the column name list is not specified, the view
columns are given names from the select list items. In order to use the names
from the select list items, each item must be a simple column name or have
an alias-name specified (see "SELECT statement" on page 587).
AS clause The SELECT statement on which the view is based must not
have an ORDER BY clause on it. It may have a GROUP BY clause and may
be a UNION. The SELECT statement must not refer to local temporary
tables.
469
CREATE VIEW statement
470
Chapter 9 SQL Statements
471
DEALLOCATE DESCRIPTOR statement [ESQL]
472
Chapter 9 SQL Statements
473
DECLARE statement
DECLARE statement
Function Use this statement to declare a SQL variable within a compound statement
(BEGIN … END).
Syntax DECLARE variable_name data-type
Description Variables used in the body of a procedure, trigger, or batch can be declared
using the DECLARE statement. The variable persists for the duration of the
compound statement in which it is declared.
The body of a Watcom-SQL procedure or trigger is a compound statement,
and variables must be declared immediately following BEGIN. In a
Transact-SQL procedure or trigger, there is no such restriction.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Supported by Adaptive Server Enterprise.
♦ To be compatible with Adaptive Server Enterprise, the variable
name must be preceded by an @.
♦ In Adaptive Server Enterprise, a variable that is declared in a
procedure or trigger exists for the duration of the procedure or
trigger. In Adaptive Server Anywhere, if a variable is declared
inside a compound statement, it exists only for the duration of that
compound statement (whether it is declared in a Watcom-SQL or
Transact-SQL compound statement).
Examples ♦ The following batch illustrates the use of the DECLARE statement and
prints a message on the server window:
BEGIN
DECLARE varname CHAR(61);
SET varname = ’Test name’;
MESSAGE name;
END
474
Chapter 9 SQL Statements
475
DECLARE CURSOR statement [ESQL] [SP]
SCROLL cursors A cursor declared SCROLL can use all formats of the
FETCH statement.
SCROLL cursors behave differently from DYNAMIC SCROLL cursors
when a row in the cursor is modified or deleted after the first time the row is
read. SCROLL cursors have more predictable behavior when changes
happen.
476
Chapter 9 SQL Statements
An update to any column causes the warning/error, even if the column is not
referenced by the cursor. For example, a cursor on Surname and Initials
would report the update even if only the Birthdate column were modified.
These update warning and error conditions will not occur in bulk operations
mode (-b database server statement line switch) when row locking is
disabled. See "Performance tips" on page 695 of the book ASA User’s Guide.
FOR UPDATE | READ ONLY A cursor declared FOR READ ONLY may
not be used in an UPDATE (positioned) or a DELETE (positioned)
operation. FOR UPDATE is the default.
477
DECLARE CURSOR statement [ESQL] [SP]
set rowcnt = 0;
open crsr;
lp: loop
fetch crsr;
if SQLCODE <> 0 then leave lp end if;
set rowcnt = rowcnt + 1;
end loop;
return rowcnt;
end
♦ Nested inside another BEGIN..END after the variable has been assigned
a value. For example:
create procedure get_table_name(
in id_value int, out tabname char(128)
)
begin
declare qry long varchar;
open crsr;
fetch crsr into tabname;
close crsr;
end
end
Standards and ♦ SQL/92 Entry level feature.
compatibility
♦ Sybase Supported by Open Client/Open Server.
Examples ♦ The following example illustrates how to declare a scroll cursor in
Embedded SQL:
EXEC SQL DECLARE cur_employee SCROLL CURSOR
FOR SELECT * FROM employee;
♦ The following example illustrates how to declare a cursor for a prepared
statement in Embedded SQL:
EXEC SQL PREPARE employee_statement
FROM ’SELECT emp_lname FROM employee’;
EXEC SQL DECLARE cur_employee CURSOR
FOR employee_statement;
478
Chapter 9 SQL Statements
479
DECLARE CURSOR statement [T-SQL]
480
Chapter 9 SQL Statements
481
DELETE statement
DELETE statement
Function Use this statement to delete rows from the database.
Syntax DELETE [ FIRST | TOP n ]
… [FROM] [ owner.]table-name
… [FROM table-list]
… [WHERE search-condition]
Permissions Must have DELETE permission on the table.
Side effects None.
See also "TRUNCATE TABLE statement" on page 615
"INSERT statement" on page 540
"INPUT statement" on page 536
"FROM clause" on page 518
Description The DELETE statement deletes all the rows from the named table that satisfy
the search condition. If no WHERE clause is specified, all rows from the
named table are deleted.
The DELETE statement can be used on views, provided the SELECT
statement defining the view has only one table in the FROM clause and does
not contain a GROUP BY clause, an aggregate function, or involve a
UNION operation.
The optional second FROM clause in the DELETE statement allows rows to
be deleted based on joins. If the second FROM clause is present, the
WHERE clause qualifies the rows of this second FROM clause. Rows are
deleted from the table name given in the first FROM clause.
$ The second FROM clause can contain arbitrary complex table
expressions, such as KEY and NATURAL joins. For a full description of the
FROM clause and joins, see "FROM clause" on page 518.
The following statement illustrates a potential ambiguity in table names in
DELETE statements with two FROM clauses that use correlation names:
DELETE
FROM table_1
FROM table_1 AS alias_1, table_2 AS alias_2
WHERE ...
The table table_1 is identified without a correlation name in the first FROM
clause, but with a correlation name in the second FROM clause. In this case,
table_1 in the first clause is identified with alias_1 in the second clause—
there is only one instance of table_1 in this statement.
482
Chapter 9 SQL Statements
This is an exception to the general rule that where a table is identified with a
correlation name and without a correlation name in the same statement, two
instances of the table are considered.
Consider the following example:
DELETE
FROM table_1
FROM table_1 AS alias_1, table_1 AS alias_2
WHERE ...
In this case, there are two instances of table_1in the second FROM clause.
The statement will fail with a syntax error as it is ambiguous which instance
of the table_1 from the second FROM clause matches the first instance of
table_1 in the first FROM clause.
Standards and ♦ SQL/92 Entry level compliant. The use of more than one table in the
compatibility FROM clause is a vendor extension.
♦ Sybase Supported by Adaptive Server Enterprise, including the
vendor extension.
Examples ♦ Remove employee 105 from the database.
DELETE
FROM employee
WHERE emp_id = 105
♦ Remove all data prior to 1993 from the fin_data table.
DELETE
FROM fin_data
WHERE year < 1993
♦ Remove all orders from sales_order_items table if their ship date is
older than 1994-01-01 and their region is Central.
DELETE
FROM sales_order_items
FROM sales_order
WHERE sales_order_items.id = sales.order.id and
ship_date < ’1994-01-01’ and region =’Central’
483
DELETE (positioned) statement [ESQL] [SP]
484
Chapter 9 SQL Statements
485
DESCRIBE statement [ESQL]
486
Chapter 9 SQL Statements
If you specify a cursor name, the cursor must have been previously declared
and opened. The default action is to describe the OUTPUT. Only SELECT
statements and CALL statements have OUTPUT. A DESCRIBE OUTPUT
on any other statement, or on a cursor that is not a dynamic cursor, indicates
no output by setting the sqld field of the SQLDA to zero.
Parameters USER TYPES A DESCRIBE statement with the USER TYPES clause
returns information about domains of a column. Typically, such a
DESCRIBE will be done when a previous DESCRIBE returns an indicator of
DT_HAS_USERTYPE_INFO.
The information returned is the same as for a DESCRIBE without the USER
TYPES keywords, except that the sqlname field holds the name of the
domain, instead of the name of the column.
If the DESCRIBE uses the LONG NAMES clause, the sqldata field holds
this information.
ALL DESCRIBE ALL allows you to describe INPUT and OUTPUT with
one request to the database server. This has a performance benefit. The
INPUT information will be filled in the SQLDA first, followed by the
OUTPUT information. The sqld field contains the total number of INPUT
and OUTPUT variables. The DT_DESCRIBE_INPUT bit in the indicator
variable is set for INPUT variables and clear for OUTPUT variables.
487
DESCRIBE statement [ESQL]
OUTPUT The DESCRIBE OUTPUT statement fills in the data type and
length for each select list item in the SQLDA. The name field is also filled in
with a name for the select list item. If an alias is specified for a select list
item, the name will be that alias. Otherwise, the name will be derived from
the select list item: if the item is a simple column name, it will be used;
otherwise, a substring of the expression will be used. DESCRIBE will also
put the number of select list items in the sqld field of the SQLDA.
If the statement being described is a UNION of two or more SELECT
statements, the column names returned for DESCRIBE OUTPUT are the
same column names which would be returned for the first SELECT
statement.
488
Chapter 9 SQL Statements
$ For more information on the use of the SQLDA structure, see "The SQL
descriptor area (SQLDA)" on page 44 of the book ASA Programming
Interfaces Guide.
Standards and ♦ SQL/92 Part of the SQL/92 standard. Some clauses are vendor
compatibility extensions.
♦ Sybase Some clauses supported by Open Client/Open Server.
Example ♦ The following example shows how to use the DESCRIBE statement:
sqlda = alloc_sqlda( 3 );
EXEC SQL DESCRIBE OUTPUT
FOR employee_statement
INTO sqlda;
if( sqlda->sqld > sqlda->sqln ) {
actual_size = sqlda->sqld;
free_sqlda( sqlda );
sqlda = alloc_sqlda( actual_size );
EXEC SQL DESCRIBE OUTPUT
FOR employee_statement
INTO sqlda;
}
489
DISCONNECT statement [ESQL][Interactive SQL]
DISCONNECT statement
[ESQL][Interactive SQL]
Function Use this statement to drop a connection with the database.
Syntax DISCONNECT
connection-name
| [ CURRENT ]
| ALL
connection-name: identifier, string, or host-variable.
Permissions None.
Side effects None.
See also "CONNECT statement" on page 411
"SET CONNECTION statement" on page 594
Description The DISCONNECT statement drops a connection with the database server
and releases all resources used by it. If the connection to be dropped was
named on the CONNECT statement, the name can be specified. Specifying
ALL will drop all of the application’s connections to all database
environments. CURRENT is the default, and will drop the current
connection.
An implicit ROLLBACK is executed on connections that are dropped.
Standards and ♦ SQL/92 Intermediate level feature.
compatibility
♦ Sybase Supported by Open Client/Open Server.
Examples ♦ The following statement shows how to use DISCONNECT in
Embedded SQL:
EXEC SQL DISCONNECT :conn_name
♦ The following statement shows how to use DISCONNECT from
Interactive SQL to disconnect all connections:
DISCONNECT ALL
490
Chapter 9 SQL Statements
DROP statement
Function Use this statement to remove objects from the database.
Syntax DROP
{ DATATYPE | DOMAIN } datatype-name
| DBSPACE dbspace-name
| EVENT event-name
| FUNCTION [ owner.]function-name
| INDEX [ [owner].table-name.]index-name
| PROCEDURE [ owner.]procedure-name
| TABLE [ owner.]table-name
| TRIGGER [ [ owner.]table-name.]trigger-name
| VIEW [ owner.]view-name
Permissions Any user who owns the object, or has DBA authority, can execute the DROP
statement.
For DROP DBSPACE, you must be the only connection to the database.
A user with ALTER permissions on the table can execute DROP TRIGGER.
A user with REFERENCES permissions on the table can execute DROP
INDEX.
Global temporary tables cannot be dropped unless all users that have
referenced the temporary table have disconnected.
Side effects Automatic commit. Clears the Data window in Interactive SQL. DROP
TABLE and DROP INDEX close all cursors for the current connection.
Local temporary tables is an exception; no commit is performed when one is
dropped.
When a view is dropped, all procedures and triggers are unloaded from
memory, so that any procedure or trigger that references the view reflects the
fact that the view does not exist. The unloading and loading of procedures
and triggers can have a performance impact if you are regularly dropping and
creating views.
See also "CREATE DATABASE statement" on page 415
"CREATE DOMAIN statement" on page 421
"CREATE INDEX statement" on page 435
"CREATE FUNCTION statement" on page 432
"CREATE PROCEDURE statement" on page 440
"CREATE TABLE statement" on page 453
"CREATE TRIGGER statement" on page 464
"CREATE VIEW statement" on page 469
491
DROP statement
Description The DROP statement removes the definition of the indicated database
structure. If the structure is a dbspace, all tables in that dbspace must be
dropped prior to dropping the dbspace. If the structure is a table, all data in
the table is automatically deleted as part of the dropping process. Also, all
indexes and keys for the table are dropped by the DROP TABLE statement.
DROP TABLE, DROP INDEX, and DROP DBSPACE are prevented
whenever the statement affects a table that is currently being used by another
connection.
DROP PROCEDURE and DROP FUNCTION are prevented when the
procedure or function is in use by another connection.
DROP DATATYPE is prevented if the data type is used in a table. You must
change data types on all columns defined on the domain in order to drop the
data type. It is recommended that you use DROP DOMAIN rather than
DROP DATATYPE, as DROP DOMAIN is the syntax used in the
ANSI/ISO SQL3 draft.
Standards and ♦ SQL/92 Entry level feature.
compatibility
♦ Sybase Supported by Adaptive Server Enterprise for those objects
that exist in Adaptive Server Enterprise.
Examples ♦ Drop the department table from the database.
DROP TABLE department
♦ Drop the emp_dept view from the database.
DROP VIEW emp_dept
492
Chapter 9 SQL Statements
493
DROP CONNECTION statement
494
Chapter 9 SQL Statements
TO clause Specifies the name of the remote server. The local user’s
alternate login name and password for that server is the external login that is
deleted.
Standards and ♦ SQL/92 Entry-level feature.
compatibility
♦ Sybase Supported by Open Client/Open Server.
Example DROP EXTERNLOGIN dba TO sybase1
495
DROP OPTIMIZER STATISTICS statement
496
Chapter 9 SQL Statements
497
DROP STATEMENT statement [ESQL]
498
Chapter 9 SQL Statements
499
EXECUTE statement [ESQL]
500
Chapter 9 SQL Statements
ARRAY clause The optional ARRAY clause can be used with prepared
INSERT statements to allow wide inserts, which insert more than one row at
a time and which may improve performance. The integer value is the number
of rows to be inserted. The SQLDA must contain a variable for each entry
(number of rows * number of columns). The first row is placed in SQLDA
variables 0 to (columns per row)-1, and so on.
Standards and ♦ SQL/92 Intermediate level feature.
compatibility
♦ Sybase Supported in Open Client/Open Server.
Examples ♦ Execute a DELETE.
EXEC SQL EXECUTE IMMEDIATE
’DELETE FROM employee WHERE emp_id = 105’;
♦ Execute a prepared DELETE statement.
EXEC SQL PREPARE del_stmt FROM
’DELETE FROM employee WHERE emp_id = :a’;
EXEC SQL EXECUTE del_stmt USING :employee_number;
♦ Execute a prepared query.
EXEC SQL PREPARE sel1 FROM
’SELECT emp_lname FROM employee WHERE emp_id = :a’;
EXEC SQL EXECUTE sel1 USING :employee_number INTO
:emp_lname;
501
EXECUTE statement [T-SQL]
502
Chapter 9 SQL Statements
The following statement executes the procedure, and stores the return
value in a variable for checking return status.
EXECUTE @status = p1 23
503
EXECUTE IMMEDIATE statement [SP]
504
Chapter 9 SQL Statements
505
EXIT statement [Interactive SQL]
506
Chapter 9 SQL Statements
507
EXPLAIN statement [ESQL]
508
Chapter 9 SQL Statements
509
FETCH statement [ESQL] [SP]
Single row fetch One row from the result of the SELECT statement is put
into the variables in the variable list. The correspondence is one-to-one from
the select list to the host variable list.
Multi-row fetch One or more rows from the result of the SELECT
statement are put into either the variables in variable-list or the program data
areas described by sqlda-name. In either case, the correspondence is one-to-
one from the select-list to either the host-variable-list or the sqlda-name
descriptor array.
Parameters INTO The INTO clause is optional. If it is not specified, the FETCH
statement positions the cursor only. The host-variable-list is for Embedded
SQL use only.
The OPEN statement initially positions the cursor before the first row.
♦ NEXT Next is the default positioning, and causes the cursor to be
advanced one row before the row is fetched.
♦ PRIOR Causes the cursor to be backed up one row before fetching.
510
Chapter 9 SQL Statements
BLOCK clause Rows may be fetched by the client application more than
one at a time. This is referred to as block fetching, prefetching, or multi-
row fetching. The first fetch causes several rows to be sent back from the
server. The client buffers these rows, and subsequent fetches are retrieved
from these buffers without a new request to the server.
The BLOCK clause is for use in Embedded SQL only. It gives the client and
server a hint as to how many rows may be fetched by the application. The
special value of 0 means the request will be sent to the server and a single
row will be returned (no row blocking).
If no BLOCK clause is specified, the value specified on OPEN is used. For
more information, see "OPEN statement" on page 556.
511
FETCH statement [ESQL] [SP]
FOR UPDATE clause The FOR UPDATE clause indicates that the
fetched row will subsequently be updated with an UPDATE WHERE
CURRENT OF CURSOR statement. This clause causes the database server
to put a write lock on the row. The lock will be held until the end of the
current transaction. See "How locking works" on page 401 of the book ASA
User’s Guide.
ARRAY clause The ARRAY clause is for use in Embedded SQL only. It
allows so-called wide fetches, which retrieve more than one row at a time,
and which may improve performance.
To use wide fetches in embedded SQL, include the fetch statement in your
code as follows:
EXEC SQL FETCH . . . ARRAY nnn
where ARRAY nnn is the last item of the FETCH statement. The fetch count
nnn can be a host variable. The SQLDA must contain nnn * (columns per
row) variables. The first row is placed in SQLDA variables 0 to (columns
per row)-1, and so on.
$ For a detailed example of using wide fetches, see the section "Fetching
more than one row at a time" on page 36 of the book ASA Programming
Interfaces Guide.
Standards and ♦ SQL/92 Entry level feature. Use in procedures is a Persistent Stored
compatibility Module feature.
♦ Sybase Supported in Adaptive Server Enterprise.
Example ♦ The following is an Embedded SQL example.
EXEC SQL DECLARE cur_employee CURSOR FOR
SELECT emp_id, emp_lname FROM employee;
EXEC SQL OPEN cur_employee;
EXEC SQL FETCH cur_employee
INTO :emp_number, :emp_name:indicator;
♦ The following is a procedure example:
BEGIN
DECLARE cur_employee CURSOR FOR
SELECT emp_lname
FROM employee;
DECLARE name CHAR(40);
OPEN cur_employee;
LOOP
512
Chapter 9 SQL Statements
513
FOR statement
FOR statement
Function Use this statement to repeat the execution of a statement list once for each
row in a cursor.
Syntax [ statement-label : ]
. . .FOR for-loop-name AS cursor-name
. . . CURSOR FOR statement
. . .[ FOR UPDATE | FOR READ ONLY ]
. . . DO statement-list
. . . END FOR [ statement-label ]
Permissions None.
Side effects None.
See also "DECLARE CURSOR statement" on page 475
"FETCH statement" on page 509
"LEAVE statement" on page 544
"LOOP statement" on page 553
Description The FOR statement is a control statement that allows you to execute a list of
SQL statements once for each row in a cursor. The FOR statement is
equivalent to a compound statement with a DECLARE for the cursor and a
DECLARE of a variable for each column in the result set of the cursor
followed by a loop that fetches one row from the cursor into the local
variables and executes statement-list once for each row in the cursor.
The name and data type of each local variable is derived from the statement
used in the cursor. With a SELECT statement, the data types will be the data
types of the expressions in the select list. The names will be the select list
item aliases, if they exist; otherwise, they will be the names of the columns.
Any select list item that is not a simple column reference must have an alias.
With a CALL statement, the names and data types will be taken from the
RESULT clause in the procedure definition.
The LEAVE statement can be used to resume execution at the first statement
after the END FOR. If the ending statement-label is specified, it must match
the beginning statement-label.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Example ♦ The following fragment illustrates the use of the FOR loop.
FOR names AS curs CURSOR FOR
SELECT emp_lname
FROM employee
DO
CALL search_for_name( emp_lname );
514
Chapter 9 SQL Statements
END FOR;
515
FORWARD TO statement
FORWARD TO statement
Function Use this statement to send native syntax SQL statements to a remote server.
Syntax 1 FORWARD TO server-name { sql-statement }
Syntax 2 FORWARD TO [ server-name ]
Permissions None
Side effects The remote connection is set to AUTOCOMMIT (unchained) mode for the
duration of the FORWARD TO session. Any work that was pending prior to
the FORWARD TO statement is automatically committed.
Description The FORWARD TO statement enables users to specify the server to which a
passthrough connection is required. The statement can be used in two ways:
♦ Syntax 1 Send a single statement to a remote server.
♦ Syntax 2 Place Adaptive Server Anywhere into passthrough mode for
sending a series of statements to a remote server. All subsequent
statements are passed directly to the remote server. To turn passthrough
mode off, issue FORWARD TO without a server-name specification.
If you encounter an error from the remote server while in passthrough
mode, you must still issue a FORWARD TO statement to turn
passthrough off.
When establishing a connection to server-name on behalf of the user, the
server uses:
♦ A remote login alias set using CREATE EXTERNLOGIN, or
♦ If a remote login alias is not set up, the name and password used to
communicate with Adaptive Server Anywhere
If the connection cannot be made to the server specified, the reason is
contained in a message returned to the user.
After statements are passed to the requested server, any results are converted
into a form that can be recognized by the client program.
server-name The name of the remote server.
516
Chapter 9 SQL Statements
FORWARD TO aseprod
SELECT * from titles
SELECT * from authors
FORWARD TO
517
FROM clause
FROM clause
Function Use this statement to specify the database tables or views involved in a
SELECT or UPDATE statement.
Syntax … FROM table-expression, …
table-expression:
table-spec
| table-expression join-type table-spec [ ON condition ]
| ( table-expression, … )
table-spec:
[userid.]table-name [ [AS] correlation-name ]
| select-statement [ AS ] correlation-name [ ( column-name, … ) ]
join-type:
CROSS JOIN
| [ NATURAL | KEY ] JOIN
| [ NATURAL | KEY ] INNER JOIN
| [ NATURAL | KEY ] LEFT OUTER JOIN
| [ NATURAL | KEY ] RIGHT OUTER JOIN
Permissions None.
Side effects None.
See also "DELETE statement" on page 482
"SELECT statement" on page 587
"UPDATE statement" on page 621
"Joins: Retrieving Data from Several Tables" on page 189 of the book ASA
User’s Guide
Description The SELECT, UPDATE, and DELETE statements require a table list, to
specify which tables will be used by the statement.
The FROM table list creates a result set consisting of all the columns from
all the tables specified. Initially, all combinations of rows in the component
tables are in the result set, and the number of combinations is usually
reduced by join conditions and/or WHERE conditions.
Tables owned by a different user can be qualified by specifying the user ID.
Tables owned by groups to which the current user belongs will be found by
default without specifying the user ID (see "Referring to tables owned by
groups" on page 736 of the book ASA User’s Guide).
518
Chapter 9 SQL Statements
The correlation name is used to give a temporary name to the table for this
SQL statement only. This is useful when referencing columns from a table
with a long name. The correlation name is also necessary to distinguish
between table instances if you reference the same table more than once in the
same query. If no correlation name is specified, the table name is used as the
correlation name for the current statement.
If the same correlation name is used twice for the same table in a table
expression, that table is treated as if it were listed only once. For example, in:
SELECT *
FROM sales_order
KEY JOIN sales_order_items,
sales_order
KEY JOIN employee
the two instances of the sales_order table are treated as one instance, this is
equivalent to:
SELECT *
FROM sales_order
KEY JOIN sales_order_items
KEY JOIN employee
Whereas:
SELECT *
FROM Person HUSBAND, Person WIFE
would be treated as two instances of the Person table, with different
correlation names HUSBAND and WIFE.
You can supply SELECT statements instead of table or view names in the
FROM clause. This allows you to use groups on groups, or joins with
groups, without creating a view. The tables that you create in this way are
derived tables.
Standards and ♦ SQL/92 Entry level feature.
compatibility
♦ Sybase The JOIN clause is not supported in Adaptive Server
Enterprise. Instead, you must use the WHERE clause to build joins.
Examples ♦ The following are valid FROM clauses:
...
FROM employee
...
...
FROM employee NATURAL JOIN department
...
...
FROM customer
519
FROM clause
520
Chapter 9 SQL Statements
521
GET DATA statement [ESQL]
WITH TEXTPTR can be used only with long data types (LONG BINARY,
LONG VARCHAR, TEXT, IMAGE). If you attempt to use it with another
data type, the error INVALID_TEXTPTR_VALUE is returned.
The total length of the data is returned in the SQLCOUNT field of the
SQLCA structure.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Open Client/Open Server. An alternative is
the Transact-SQL READTEXT statement.
Example ♦ The following example uses GET DATA to fetch a binary large object
(often called a blob).
EXEC SQL BEGIN DECLARE SECTION;
DECL_BINARY(1000) piece;
short ind;
long offset;
EXEC SQL END DECLARE SECTION;
int size;
/* Open a cursor on a long varchar field */
EXEC SQL DECLARE big_cursor CURSOR FOR
SELECT long_data FROM some_table
WHERE key_id = 2;
EXEC SQL OPEN big_cursor;
EXEC SQL FETCH big_cursor INTO :piece;
for( offset = 0; ; offset += piece.len ) {
EXEC SQL GET DATA big_cursor COLUMN 1
OFFSET :offset INTO :piece:ind;
/* Done if the NULL value */
if( ind < 0 ) break;
write_out_piece( piece );
/* Done when the piece was not truncated */
if( ind == 0 ) break;
}
EXEC SQL CLOSE big_cursor;
522
Chapter 9 SQL Statements
523
GET OPTION statement [ESQL]
524
Chapter 9 SQL Statements
525
GRANT statement
GRANT statement
Function Use this statement to create new user IDs, to grant or deny permissions to
specific users, and to create or change passwords.
Syntax 1 GRANT CONNECT TO userid, …
[ AT starting-id }
IDENTIFIED BY password, …
Syntax 2 GRANT {
DBA,
GROUP,
MEMBERSHIP IN GROUP userid, …,
[ RESOURCE | ALL ]
}
… TO userid, …
Syntax 3 GRANT {
ALL [ PRIVILEGES ],
ALTER,
DELETE,
INSERT,
REFERENCES [ ( column-name, … ) ],
SELECT [ ( column-name, … ) ],
UPDATE [ ( column-name, … ) ],
}
… ON [ owner.]table-name
… TO userid, …
[ WITH GRANT OPTION ]
Syntax 4 GRANT EXECUTE ON [ owner.]procedure-name TO userid, …
Syntax 5 GRANT INTEGRATED LOGIN TO user_profile_name, … AS USER userid
Permissions Syntax 1 or 2 One of the following conditions must be met.
♦ You are changing your own password using GRANT CONNECT
♦ You have DBA authority
If you are changing another user’s password (with DBA authority), the other
user must not be connected to the database.
526
Chapter 9 SQL Statements
AT starting-id This clause is not for general purpose use. The clause
specifies the internal numeric value to be used for the first user ID in the list.
The clause is implemented primarily for use by the Unload utility.
527
GRANT statement
RESOURCE Allows the user to create tables and views. In syntax 2, ALL
is a synonym for RESOURCE that is compatible with Sybase Adaptive
Server Enterprise.
ALTER The users will be allowed to alter the named table with the
ALTER TABLE statement. This permission is not allowed for views.
DELETE The users will be allowed to delete rows from the named table or
view.
INSERT The users will be allowed to insert rows into the named table or
view.
528
Chapter 9 SQL Statements
529
HELP statement [Interactive SQL]
530
Chapter 9 SQL Statements
IF statement
Function Use this statement to control conditional execution of SQL statements.
Syntax IF search-condition THEN statement-list
… [ ELSEIF search-condition THEN statement-list ] …
… [ ELSE statement-list ]
… END IF
Permissions None.
Side effects None.
See also "BEGIN statement" on page 392
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The IF statement is a control statement that allows you to conditionally
execute the first list of SQL statements whose search-condition evaluates to
TRUE. If no search-condition evaluates to TRUE, and an ELSE clause
exists, the statement-list in the ELSE clause is executed.
Execution resumes at the first statement after the END IF.
531
IF statement
532
Chapter 9 SQL Statements
IF statement [T-SQL]
Function Use this statement to control conditional execution of a SQL statement, as an
alternative to the Watcom-SQL IF statement.
Syntax IF expression
… statement
… [ ELSE
… [ IF expression ]
… statement ]
Authorization None.
Side effects None.
Description The Transact-SQL IF conditional and the ELSE conditional each control the
execution of only a single SQL statement or compound statement (between
the keywords BEGIN and END).
In comparison to the Watcom-SQL IF statement, there is no THEN in the
Transact-SQL IF statement. The Transact-SQL version also has no ELSEIF
or END IF keywords.
Standards and ♦ SQL/92 Transact-SQL extension.
compatibility
♦ Sybase Adaptive Server Enterprise supports the Transact-SQL IF
statement.
Example ♦ The following example illustrates the use of the Transact-SQL IF
statement:
IF (SELECT max(id) FROM sysobjects) < 100
RETURN
ELSE
BEGIN
PRINT "These are the user-created objects"
SELECT name, type, id
FROM sysobjects
WHERE id < 100
END
♦ The following two statement blocks illustrate Transact-SQL and
Watcom-SQL compatibility:
/* Transact-SQL IF statement */
IF @v1 = 0
PRINT ’0’
ELSE IF @v1 = 1
PRINT ’1’
ELSE
PRINT ’other’
/* Watcom-SQL IF statement */
533
IF statement [T-SQL]
IF v1 = 0 THEN
PRINT ’0’
ELSEIF v1 = 1 THEN
PRINT ’1’
ELSE
PRINT ’other’
END IF
534
Chapter 9 SQL Statements
535
INPUT statement [Interactive SQL]
536
Chapter 9 SQL Statements
BY clause The BY clause allows the user to specify whether the columns
from the input file should be matched up with the table columns based on
their ordinal position in the lists (ORDER, the default) or by their names
(NAME). Not all input formats have column name information in the file.
NAME is allowed only for those formats that do. They are the same formats
that allow automatic table creation listed below: DBASEII, DBASEIII, DIF,
FOXPRO, LOTUS, and WATFILE.
NOSTRIP clause Normally, for ASCII input format, trailing blanks will
be stripped from unquoted strings before the value is inserted. NOSTRIP can
be used to suppress trailing blank stripping. Trailing blanks are not stripped
from quoted strings, regardless of whether the option is used. Leading blanks
are stripped from unquoted strings, regardless of the NOSTRIP option
setting.
If the ASCII file has entries such that a column appears to be null, it is
treated as NULL. If the column in that position cannot be NULL, a zero is
inserted in numeric columns and an empty string in character columns.
FORMAT clause Each set of values must occupy one input line and must
be in the format specified by the FORMAT clause, or the format set by the
SET INPUT_FORMAT statement if the FORMAT clause is not specified.
When input is entered by the user, an empty screen is provided for the user to
enter one row per line in the input format.
537
INPUT statement [Interactive SQL]
Certain file formats contain information about column names and types.
Using this information, the INPUT statement will create the database table if
it does not already exist. This is a very easy way to load data into the
database. The formats that have enough information to create the table are:
DBASEII, DBASEIII, FOXPRO, and LOTUS.
Input from a command file is terminated by a line containing END. Input
from a file is terminated at the end of the file.
Allowable input formats are:
♦ ASCII Input lines are assumed to be ASCII characters, one row per
line, with values separated by commas. Alphabetic strings may be
enclosed in apostrophes (single quotes) or quotation marks (double
quotes). Strings containing commas must be enclosed in either single or
double quotes. If the string itself contains single or double quotes,
double the quote character to use it within the string. Optionally, you can
use the DELIMITED BY clause to specify a different delimiter string
than the default, which is a comma.
Three other special sequences are also recognized. The two characters \n
represent a newline character, \\ represents a single (\), and the sequence
\xDD represents the character with hexadecimal code DD.
♦ DBASE The file is in dBASE II or dBASE III format. Interactive SQL
will attempt to determine which format, based on information in the file.
If the table doesn’t exist, it will be created.
♦ DBASEII The file is in dBASE II format. If the table doesn’t exist, it
will be created.
♦ DBASEIII The file is in dBASE III format. If the table doesn’t exist, it
will be created.
♦ EXCEL Input file is in the format of Microsoft Excel 2.1. If the table
doesn’t exist, it will be created.
♦ FIXED Input lines are in fixed format. The width of the columns can be
specified using the COLUMN WIDTHS clause. If they are not specified,
column widths in the file must be the same as the maximum number of
characters required by any value of the corresponding database column’s
type.
The FIXED format cannot be used with binary columns that contain
embedded newline and End of File character sequences.
♦ FOXPRO The file is in FoxPro format (the FoxPro memo field is
different than the dBASE memo field). If the table doesn’t exist, it will
be created.
538
Chapter 9 SQL Statements
539
INSERT statement
INSERT statement
Function Use this statement to insert a single row (syntax 1) or a selection of rows
from elsewhere in the database (syntax 2) into a table.
Syntax 1 INSERT [ INTO ] [ owner.]table-name [( column-name, … )]
… VALUES ( expression | DEFAULT, … )
Syntax 2 INSERT [ INTO ] [ owner.]table-name [( column-name, … )]
… select-statement
Permissions Must have INSERT permission on the table.
Side effects None.
See also "INPUT statement" on page 536
"UPDATE statement" on page 621
"DELETE statement" on page 482
"PUT statement" on page 568
Description The INSERT statement is used to add new rows to a database table.
Syntax 1 Insert a single row, with the specified expression values. The
keyword DEFAULT can be used to cause the default value for the column to
be inserted. If the optional list of column names is given, the values are
inserted one for one into the specified columns. If the list of column names is
not specified, the values are inserted into the table columns in the order they
were created (the same order as retrieved with SELECT *). The row is
inserted into the table at an arbitrary position. (In relational databases, tables
are not ordered.)
Syntax 2 Carry out mass insertion into a table with the results of a fully
general SELECT statement. Insertions are done in an arbitrary order unless
the SELECT statement contains an ORDER BY clause. The columns from
the select list are matched ordinally with the columns specified in the column
list, or sequentially in the order in which the columns were created.
Inserts can be done into views, if the query specification defining the view is
updatable and has only one table in the FROM clause.
An inherently non-updatable view consists of a query expression or query
specification containing any of the following:
♦ DISTINCT clause
♦ GROUP BY clause
♦ Aggregate function
♦ A select-list item that is not a base table.
540
Chapter 9 SQL Statements
Character strings inserted into tables are always stored in the same case as
they are entered, regardless of whether the database is case sensitive or not.
Thus a string Value inserted into a table is always held in the database with
an upper-case V and the remainder of the letters lower case. SELECT
statements return the string as Value. If the database is not case-sensitive,
however, all comparisons make Value the same as value, VALUE, and so
on. Further, if a single-column primary key already contains an entry Value,
an INSERT of value is rejected, as it would make the primary key not
unique.
Performance tip
To insert many rows into a table, it is more efficient to declare a cursor
and insert the rows through the cursor, where possible, than to carry out
many separate INSERT statements.
541
INSTALL statement
INSTALL statement
Function Use this statement to make Java classes available for use within a database.
Syntax INSTALL JAVA
[ NEW | UPDATE ]
[ JAR jar-name ]
FROM { FILE filename | expression }
Permissions DBA permissions are required to execute the INSTALL statement.
All installed classes can be referenced in any way by any user.
Not supported on Windows CE.
See also "REMOVE statement" on page 575
Description The class definition for each class is loaded by each connection’s VM the
first time that class is used. When you INSTALL a class, the VM on your
connection is implicitly restarted. Therefore, you have immediate access to
the new class, whether the INSTALL has an install-mode of NEW or
UPDATE. Because the VM is restarted, any values stored in java static
variables are lost, and any SQL variables with java class types are dropped.
For other connections, the new class is loaded the next time a VM accesses
the class for the first time. If the class is already loaded by a VM, that
connection does not see the new class until the VM is restarted for that
connection (for example, with a STOP JAVA and START JAVA).
Parameters NEW | UPDATE keyword If you specify an install mode of NEW, the
referenced Java classes must be new classes, rather than updates of currently
installed classes. An error occurs if a class with the same name exists in the
database and the NEW install mode is used.
If you specify UPDATE, the referenced Java classes may include
replacements for Java classes that are already installed in the given database.
If install-mode is omitted, the default is NEW.
JAR clause If this is specified, then the filename must designate a jar file.
Jar files typically have extensions of .jar or .zip.
Installed jar and zip files can be compressed or uncompressed.
If the JAR option is specified, the jar is retained as a jar after the classes that
it contains have been installed. That jar is the associated jar of each of those
classes. The jars installed in a database with the JAR option are called the
retained jars of the database.
The jar-name is a character string value, of up to 255 bytes long. The jar-
name is used to identify the retained jar in subsequent INSTALL UPDATE
and REMOVE statements.
542
Chapter 9 SQL Statements
543
LEAVE statement
LEAVE statement
Function Use this statement to leave a compound statement or loop.
Syntax LEAVE statement-label
Permissions None.
Side effects None.
See also "LOOP statement" on page 553
"FOR statement" on page 514
"BEGIN statement" on page 392
"Using Procedures, Triggers, and Batches" on page 423 of the book ASA
User’s Guide
Description The LEAVE statement is a control statement that allows you to leave a
labeled compound statement or a labeled loop. Execution resumes at the first
statement after the compound statement or loop.
The compound statement that is the body of a procedure or trigger has an
implicit label that is the same as the name of the procedure or trigger.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Not supported in Adaptive Server Enterprise. The BREAK
statement provides a similar feature for Transact-SQL compatible
procedures.
Examples ♦ The following fragment shows how the LEAVE statement is used to
leave a loop.
SET i = 1;
lbl:
LOOP
INSERT
INTO Counters ( number )
VALUES ( i );
IF i >= 10 THEN
LEAVE lbl;
END IF;
SET i = i + 1
END LOOP lbl
♦ The following example fragment uses LEAVE in a nested loop.
outer_loop:
LOOP
SET i = 1;
inner_loop:
LOOP
...
544
Chapter 9 SQL Statements
SET i = i + 1;
IF i >= 10 THEN
LEAVE outer_loop
END IF
END LOOP inner_loop
END LOOP outer_loop
545
LOAD TABLE statement
546
Chapter 9 SQL Statements
LOAD TABLE places an exclusive lock on the whole table; it does not fire
any triggers associated with the table.
You can use LOAD TABLE on a global temporary table, but the temporary
table must have been created with the ON COMMIT PRESERVE ROWS
clause, because LOAD TABLE does a COMMIT after the load. LOAD
TABLE cannot be used on declared temporary tables.
If the ASCII file has entries such that a column appears to be NULL, LOAD
TABLE treats it as null. If the column in that position cannot be NULL, it
inserts a zero in numeric columns and an empty string in character columns.
LOAD TABLE skips empty lines in the input file.
Any columns not present in the column list become NULL if the
DEFAULTS option is off. If DEFAULTS is on and the column has a default
value, that value will be used. If DEFAULTS is off, and a non-nullable
column is omitted from the column list, the engine attempts to convert the
empty string to the column’s type.
Caution
LOAD TABLE is intended solely for fast loading of large amounts of data.
It is not intended for routine use in applications.
Parameters FROM option The filename-string is passed to the server as a string. The
string is therefore subject to the same formatting requirements as other SQL
strings. In particular:
♦ To indicate directory paths, the backslash character \ must be
represented by two backslashes. The statement to load data from the file
c:\temp\input.dat into the employee table is:
LOAD TABLE employee
FROM ’c:\\temp\\input.dat’ ...
♦ The pathname is relative to the database server, not to the client
application. If you are running the statement on a database server on
another computer, the directory names refers to directories on the server
machine, not on the client machine.
♦ You can use UNC path names to load data from files on computers other
than the server. For example, on a Windows for Workgroups,
Windows 95, or Windows NT network, you may use the following
statement to load data from a file on the client machine:
LOAD TABLE employee
FROM ’\\\\client\\temp\\input.dat’
547
LOAD TABLE statement
548
Chapter 9 SQL Statements
STRIP option With STRIP turned on (the default), trailing blanks are
stripped from values before they are inserted. To turn the STRIP option off,
the clause is as follows:
...STRIP OFF ...
Trailing blanks are stripped only for non-quoted strings. Quoted strings
retain their trailing blanks. Leading blanks are trimmed, regardless of the
STRIP setting, unless they are enclosed in quotes.
549
LOAD TABLE statement
Caution
If you set the database option CONVERSION_ERROR to OFF, you may
load bad data into your table without any error being reported. If you do
not specify WITH CHECKPOINT ON, and the database needs to be
recovered, the recovery may fail as CONVERSION_ERROR is ON (the
default value) during recovery. It is recommended that you do not load
tables with CONVERSION_ERROR set to OFF and WITH
CHECKPOINT ON not specified.
550
Chapter 9 SQL Statements
WITH HOLD clause If this clause is specified, the lock is held until the
end of the connection. If the clause is not specified, the lock is release when
the current transaction is committed or rolled back.
SHARE mode Prevent other transactions from modifying the table, but
allow them read access. In this mode you can change data in the table as long
as no other transaction has locked the row being modified, either indirectly
or explicitly using LOCK TABLE.
551
LOCK TABLE statement
552
Chapter 9 SQL Statements
LOOP statement
Function Use this statement to repeat the execution of a statement list.
Syntax [ statement-label : ]
…[ WHILE search-condition ] LOOP
… statement-list
…END LOOP [ statement-label ]
Permissions None.
Side effects None.
See also "FOR statement" on page 514
"LEAVE statement" on page 544
Description The WHILE and LOOP statements are control statements that allow you to
execute a list of SQL statements repeatedly while a search-condition
evaluates to TRUE. The LEAVE statement can be used to resume execution
at the first statement after the END LOOP.
If the ending statement-label is specified, it must match the beginning
statement-label.
Standards and ♦ SQL/92 Persistent Stored Module feature.
compatibility
♦ Sybase Not supported in Adaptive Server Enterprise. The WHILE
statement provides looping in Transact-SQL stored procedures.
Examples ♦ A While loop in a procedure.
...
SET i = 1;
WHILE i <= 10 LOOP
INSERT INTO Counters( number ) VALUES ( i );
SET i = i + 1;
END LOOP;
...
♦ A labeled loop in a procedure.
SET i = 1;
lbl:
LOOP
INSERT
INTO Counters( number )
VALUES ( i );
IF i >= 10 THEN
LEAVE lbl;
END IF;
SET i = i + 1;
END LOOP lbl
553
MESSAGE statement
MESSAGE statement
Function Use this statement to display a message.
Syntax MESSAGE expression, …
[ TYPE { INFO | ACTION | WARNING | STATUS } ]
[ TO { CONSOLE | CLIENT | LOG }]
Permissions None.
Side effects None.
See also "CREATE PROCEDURE statement" on page 440
Description The MESSAGE statement displays a message, which can be any expression.
Clauses can specify where the message appears.
Valid expressions can include a quoted string or other constant, variable, or
function. However, queries are not permitted in the output of a Message
statement even though the definition of an expression includes queries.
Parameters TYPE clause The TYPE clause only has an effect if the message is sent to
the client. The client application must decide how to handle the message.
Interactive SQL displays messages in the following locations:
♦ INFO The Message window. INFO is the default type.
♦ ACTION A Message box with an OK button.
♦ WARNING A Message box with an OK button.
♦ STATUS The Message window.
555
OPEN statement [ESQL] [SP]
556
Chapter 9 SQL Statements
WITH HOLD clause By default, all cursors are automatically closed at the
end of the current transaction (COMMIT or ROLLBACK). The optional
WITH HOLD clause keeps the cursor open for subsequent transactions. It
will remain open until the end of the current connection or until an explicit
CLOSE statement is executed. Cursors are automatically closed when a
connection is terminated.
BLOCK clause This clause is for Embedded SQL use only. Rows are
fetched by the client application in blocks (more than one at a time). By
default, the number of rows in a block is determined dynamically based on
the size of the rows and how long it takes the database server to fetch each
row. The application can specify a maximum number of rows that should be
contained in a block by specifying the BLOCK clause. For example, if you
are fetching and displaying 5 rows at a time, use BLOCK 5. Specifying
BLOCK 0 will cause one row at a time to be fetched, and also cause a
FETCH RELATIVE 0 to always fetch the row again.
$ For more information, see "FETCH statement" on page 509.
Standards and ♦ SQL/92 Embedded SQL use is an entry-level feature. Procedures use
compatibility is a Persistent Stored Modules feature.
557
OPEN statement [ESQL] [SP]
558
Chapter 9 SQL Statements
559
OUTPUT statement [Interactive SQL]
QUOTE clause The QUOTE clause is for the ASCII output format only.
The quote string is placed around string values. The default is a single quote
character. If ALL is specified in the QUOTE clause, the quote string is
placed around all values, not just around strings.
560
Chapter 9 SQL Statements
♦ ASCII The output is an ASCII format file with one row per line in the
file. All values are separated by commas, and strings are enclosed in
apostrophes (single quotes). The delimiter and quote strings can be
changed using the DELIMITED BY and QUOTE clauses. If ALL is
specified in the QUOTE clause, all values (not just strings) will be
quoted.
Three other special sequences are also used. The two characters \n
represent a newline character, \\ represents a single \, and the sequence
\xDD represents the character with hexadecimal code DD. This is the
default output format.
If you are exporting Java methods that have string return values, you
must use the HEXADECIMAL OFF clause.
♦ DBASEII The output is a dBASE II format file with the column
definitions at the top of the file. Note that a maximum of 32 columns can
be output. Also, note that columns longer than 255 characters will be
truncated in the file.
♦ DBASEIII The output is a dBASE III format file with the column
definitions at the top of the file. Note that a maximum of 128 columns
can be output. Also, note that columns longer than 255 characters will be
truncated in the file.
♦ FIXED The output is fixed format with each column having a fixed
width. The width for each column can be specified using the COLUMN
WIDTH clause. No column headings are output in this format.
If the COLUMN WIDTH clause is omitted, the width for each column is
computed from the data type for the column, and is large enough to hold
any value of that data type. The exception is that LONG VARCHAR
and LONG BINARY data defaults to 32 kb.
♦ FOXPRO The output is a FoxPro format file (the FoxPro memo field is
different than the dBASE memo field) with the column definitions at the
top of the file. Note that a maximum of 128 columns can be output.
Also, note that columns longer than 255 characters will be truncated in
the file.
♦ HTML The output is in the Hyper Text Markup Language format.
♦ LOTUS The output is a Lotus WKS format worksheet. Column names
will be put as the first row in the worksheet. Note that there are certain
restrictions on the maximum size of Lotus WKS format worksheets that
other software (such as Lotus 1-2-3) can load. There is no limit to the
size of file Interactive SQL can produce.
♦ SQL The output is a Interactive SQL INPUT statement required to
recreate the information in the table.
561
OUTPUT statement [Interactive SQL]
♦ TEXT The output is a TEXT format file which prints the results in
columns with the column names at the top and vertical lines separating
the columns. This format is similar to that used to display data in the
Interactive SQL data window.
562
Chapter 9 SQL Statements
563
PREPARE statement [ESQL]
564
Chapter 9 SQL Statements
565
PREPARE TO COMMIT statement
DELETE
FROM department
WHERE dept_id = 100;
PREPARE TO COMMIT;
566
Chapter 9 SQL Statements
567
PUT statement [ESQL]
568
Chapter 9 SQL Statements
569
RAISERROR statement [T-SQL]
570
Chapter 9 SQL Statements
571
READ statement [Interactive SQL]
572
Chapter 9 SQL Statements
573
RELEASE SAVEPOINT statement
574
Chapter 9 SQL Statements
REMOVE statement
Function Use this statement to remove a class or a jar file from a database. When a
class is removed it is no longer available for use as a column or variable
type.
The class or jar must already be installed.
Syntax REMOVE JAVA classes_to_remove
classes_to_remove:
CLASS java_class_name [, java_class_name, …]
| JAR jar_name [, jar_name, …]
Permissions Must have DBA authority.
Not supported on Windows CE.
Description Removes a class or jar file from the database.
Parameters CLASS The java_class_name parameter is the name of one or more Java
class to be removed. These classes must be installed classes in the current
database.
JAR The jar_name is a character string value of maximum length 255.
Each jar_name must be equal to the jar_name of a retained jar in the current
database. Equality of jar_name is determined by the character string
comparison rules of the SQL system.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise. A similar
feature is available in an Adaptive Server Enterprise-compatible manner
using nested transactions.
Examples ♦ The following statement removes a Java class named Demo from the
current database.
REMOVE JAVA CLASS Demo
575
RESIGNAL statement
RESIGNAL statement
Function Use this statement to resignal an exception condition.
Syntax RESIGNAL [ exception-name ]
Permissions None.
Side effects None.
See also "SIGNAL statement" on page 603
"BEGIN statement" on page 392
"Using exception handlers in procedures and triggers" on page 466 of the
book ASA User’s Guide
"RAISERROR statement" on page 570
Description Within an exception handler, RESIGNAL allows you to quit the compound
statement with the exception still active, or to quit reporting another named
exception. The exception will be handled by another exception handler or
returned to the application. Any actions by the exception handler before the
RESIGNAL are undone.
Standards and ♦ SQL/92 Persistent stored module feature.
compatibility
♦ Sybase Not supported in Adaptive Server Enterprise. Signaling of
errors in Transact-SQL procedures is carried out using the RAISERROR
statement.
Example ♦ The following fragment returns all exceptions except Column Not
Found to the application.
...
DECLARE COLUMN_NOT_FOUND EXCEPTION
FOR SQLSTATE ’52003’;
...
EXCEPTION
WHEN COLUMN_NOT_FOUND THEN
SET message=’Column not found’;
WHEN OTHERS THEN
RESIGNAL;
576
Chapter 9 SQL Statements
RESTORE statement
Function Use this statement to restore a backed up database from an archive.
Syntax RESTORE DATABASE database_location
FROM archive_root
CATALOG ONLY
[ [ RENAME dbspace_name TO new_dbspace_path ] …]
Permissions Must be connected to the utility database.
Side effects None.
See also "BACKUP statement" on page 389
"Backup and Data Recovery" on page 627 of the book ASA User’s Guide
Description Each RESTORE operation updates a history file called backup.syb, which is
a text file held in the same directory as your database server executable file.
The RENAME clause provides a way to change the restore location for each
dbspace. The dbspace name in a RENAME clause cannot be SYSTEM or
TRANSLOG.
RESTORE DATABASE replaces the database that is being restored. If you
need incremental backups, use the image format of the BACKUP command
and save only the transaction log; however, image backups to tape are not
supported.
Archive backups are only supported on Windows NT and Unix platforms.
Parameters database_location Specifies the location for the main database file.
577
RESUME statement
RESUME statement
Function Use this statement to resume execution of a cursor that returns result sets.
Syntax 1 RESUME cursor-name
cursor-name: identifier
cursor-name: identifier or host-variable
Permissions The cursor must have been previously opened.
Side effects None.
See also "DECLARE CURSOR statement" on page 475
"Returning results from procedures" on page 453 of the book ASA User’s
Guide
Description This statement resumes execution of a procedure that returns result sets. The
procedure executes until the next result set (SELECT statement with no
INTO clause) is encountered. If the procedure completes and no result set is
found, the SQLSTATE_PROCEDURE_COMPLETE warning is set. This
warning is also set when you RESUME a cursor for a SELECT statement.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase Not supported by Adaptive Server Enterprise.
Examples ♦ Embedded SQL example
1. EXEC SQL RESUME cur_employee;
2. EXEC SQL RESUME :cursor_var;
♦ Interactive SQL examples
CALL sample_proc();
RESUME ALL;
578
Chapter 9 SQL Statements
RETURN statement
Function Use this statement to exit from a function or procedure unconditionally,
optionally providing a return value.
Syntax RETURN [ expression ]
Permissions None.
Side effects None.
See also "CREATE FUNCTION statement" on page 432
"CREATE PROCEDURE statement" on page 440
"BEGIN statement" on page 392
Description A RETURN statement causes an immediate exit from a function or
procedure. If expression is supplied, the value of expression is returned as
the value of the function or procedure.
Statements following a RETURN statement are not executed.
Within a function, the expression should be of the same data type as the
function’s RETURNS data type.
Within a procedure, RETURN is used for Transact-SQL-compatibility, and
is used to return an integer error code.
Standards and ♦ SQL/92 Persistent stored module feature.
compatibility
♦ Sybase Transact-SQL procedures use the RETURN statement to
return an integer error code.
Example ♦ The following function returns the product of three numbers:
CREATE FUNCTION product (
a numeric,
b numeric,
c numeric )
RETURNS numeric
BEGIN
RETURN ( a * b * c );
END
♦ Calculate the product of three numbers:
SELECT product (2, 3, 4)
product(2, 3, 4)
24
579
RETURN statement
580
Chapter 9 SQL Statements
REVOKE statement
Function Use this statement to remove permissions for the specified users.
Syntax 1 REVOKE {
CONNECT,
DBA,
INTEGRATED LOGIN,
GROUP,
MEMBERSHIP IN GROUP userid, …
RESOURCE,
}
..FROM userid, …
Syntax 2 REVOKE {
ALL [PRIVILEGES]
ALTER,
DELETE,
INSERT,
REFERENCES [ ( column-name, …) ],
SELECT [ ( column-name, …) ],
UPDATE [ ( column-name, …) ],
}
… ON [ owner.]table-name FROM userid, …
Syntax 3 REVOKE EXECUTE ON [ owner.]procedure-name FROM userid, …
Permissions Must be the grantor of the permissions that are being revoked or have DBA
authority.
If you are revoking CONNECT permissions or table permissions from
another user, the other user must not be connected to the database.
Side effects Automatic commit.
See also "GRANT statement" on page 526
Description The REVOKE statement removes permissions given using the GRANT
statement. Form 1 revokes special user permissions. Form 2 revokes table
permissions. Form 3 revokes permission to execute a procedure.
REVOKE CONNECT removes a user ID from a database, and also destroys
any objects (tables, views, procedures, etc.) owned by that user and any
permissions granted by that user. REVOKE GROUP automatically
REVOKES MEMBERSHIP from all members of the group.
If you give a user GRANT option permission, then later revoke that
permission, you also revoke any permissions that user granted to others
while they had the GRANT option.
581
REVOKE statement
582
Chapter 9 SQL Statements
ROLLBACK statement
Function Use this statement to end a transaction and undo any changes made since the
last COMMIT or ROLLBACK.
Syntax ROLLBACK [ WORK ]
Permissions None.
Side effects Closes all cursors not opened WITH HOLD.
See also "COMMIT statement" on page 408
"ROLLBACK TO SAVEPOINT statement" on page 584
Description A transaction is the logical unit of work done on one database connection to
a database between COMMIT or ROLLBACK statements. The ROLLBACK
statement ends the current transaction and undoes all changes made to the
database since the previous COMMIT or ROLLBACK.
Standards and ♦ SQL/92 Entry level feature.
compatibility
♦ Sybase Supported by Adaptive Server Enterprise.
583
ROLLBACK TO SAVEPOINT statement
584
Chapter 9 SQL Statements
585
SAVEPOINT statement
SAVEPOINT statement
Function Use this statement to establish a savepoint within the current transaction.
Syntax SAVEPOINT [ savepoint-name ]
Permissions None.
Side effects None.
See also "RELEASE SAVEPOINT statement" on page 574
"ROLLBACK TO SAVEPOINT statement" on page 584
Description Establish a savepoint within the current transaction. The savepoint-name is
an identifier that can be used in a RELEASE SAVEPOINT or ROLLBACK
TO SAVEPOINT statement. All savepoints are automatically released when
a transaction ends. See "Savepoints within transactions" on page 373 of the
book ASA User’s Guide.
Savepoints that are established while a trigger or atomic compound statement
is executing are automatically released when the atomic operation ends.
Standards and ♦ SQL/92 Vendor extension. Included in the SQL/3 draft specification.
compatibility
♦ Sybase Not supported in Adaptive Server Enterprise. To implement
similar features in an Adaptive Server Enterprise-compatible manner,
you can use the SAVE TRANSACTION statement.
586
Chapter 9 SQL Statements
SELECT statement
Function Use this statement to retrieve information from the database.
Syntax SELECT [ ALL | DISTINCT ] [ FIRST | TOP n ] select-list
…[ INTO { host-variable-list | variable-list } ]
…[ FROM table-expression ]
…[ WHERE search-condition ]
…[ GROUP BY group-by-list ]
…[ HAVING search-condition ]
…[ ORDER BY { expression | integer } [ ASC | DESC ], … ]
select-list:
{ column-name | expression } [ [ AS ] alias-name ], …| *
group-by-list:
{ column-name | alias-name | function | expression }, …
Permissions Must have SELECT permission on the named tables and views.
Side effects None.
"Expressions" on page 218
See also
"FROM clause" on page 518
"Search conditions" on page 226
"UNION operation" on page 617
"Joins: Retrieving Data from Several Tables" on page 189 of the book ASA
User’s Guide
Description The SELECT statement is used for retrieving results from the database.
A SELECT statement can be used in Interactive SQL to browse data in the
database, or to export data from the database to an external file.
A SELECT statement can also be used in procedures and triggers or in
embedded SQL. The SELECT statement with an INTO clause is used for
retrieving results from the database when the SELECT statement only
returns one row. For multiple row queries, you must use cursors.
A SELECT statement can also be used to return a result set from a
procedure.
Parameters ALL or DISTINCT All (the default) returns all rows that satisfy the clauses
of the SELECT statement. If DISTINCT is specified, duplicate output rows
are eliminated. Many statements take significantly longer to execute when
DISTINCT is specified, so you should reserve DISTINCT for cases where it
is necessary.
FIRST or TOP These keywords are principally for use with ORDER BY
queries. You can explicitly retrieve only the first row of a query or the first n
rows of a query.
587
SELECT statement
The FIRST and TOP keywords cannot be used in a derived table query. You
should not use the keywords in view definitions.
Aggregate functions are allowed in the select list (see "SQL Functions" on
page 291). Subqueries are also allowed in the select list (see "Expressions"
on page 218). Each subquery must be within parentheses.
Alias-names can be used throughout the query to represent the aliased
expression.
Alias names are also displayed by Interactive SQL at the top of each column
of output from the SELECT statement. If the optional alias name is not
specified after an expression, Interactive SQL will display the expression
itself.
FROM clause Rows are retrieved from the tables and views specified in
the table expression. Joins can be specified using join operators. A SELECT
statement with no FROM clause can be used to display the values of
expressions not derived from tables. For example:
SELECT @@version
displays the value of the global variable @@version. This is equivalent to:
SELECT @@version
FROM DUMMY
$ For more information, see "FROM clause" on page 518.
588
Chapter 9 SQL Statements
WHERE clause This clause specifies which rows will be selected from
the tables named in the FROM clause. It is also used to do joins between
multiple tables. This is accomplished by putting a condition in the WHERE
clause that relates a column or group of columns from one table with a
column or group of columns from another table. Both tables must be listed in
the FROM clause.
$ For more information, see "Search conditions" on page 226.
GROUP BY clause You can group by columns, alias names, or functions.
The result of the query contains one row for each distinct set of values in the
named columns, aliases, or functions. All NULL-containing rows are treated
as a single set. The resulting rows are often referred to as groups since there
is one row in the result for each group of rows from the table list. Aggregate
functions can then be applied to these groups to get meaningful results.
When GROUP BY is used, the select-list, HAVING clause, and ORDER BY
clause must not reference any identifier that is not named in the GROUP BY
clause. The exception is that the select-list and HAVING clause may contain
aggregate functions.
HAVING clause This clause selects rows based on the group values and
not on the individual row values. The HAVING clause can only be used if
either the statement has a GROUP BY clause or the select list consists solely
of aggregate functions. Any column names referenced in the HAVING
clause must either be in the GROUP BY clause or be used as a parameter to
an aggregate function in the HAVING clause.
ORDER BY clause This clause sorts the results of a query. Each item in
the ORDER BY list can be labeled as ASC for ascending order (the default)
or DESC for descending order. If the expression is an integer n, then the
query results will be sorted by the n’th item in the select list.
In embedded SQL, the SELECT statement is used for retrieving results from
the database and placing the values into host variables via the INTO clause.
The SELECT statement must return only one row. For multiple row queries,
you must use cursors.
Standards and ♦ SQL/92 Entry level feature. The complexity of the SELECT statement
compatibility means that you should check individual clauses against the standard.
♦ Sybase Supported by Adaptive Server Enterprise, with some
differences in syntax.
Examples ♦ How many employees are there?
SELECT count(*)
FROM Employee;
♦ List all customers and the total value of their orders.
589
SELECT statement
SELECT company_name,
CAST( sum(sales_order_items.quantity *
product.unit_price) AS INTEGER) VALUE
FROM customer
JOIN sales_order
JOIN sales_order_items
JOIN product
GROUP BY company_name
ORDER BY VALUE DESC
♦ The following statement shows an Embedded SQL SELECT statement:
SELECT count(*) INTO :size
FROM employee
590
Chapter 9 SQL Statements
SET statement
Function Use this statement to assign a value to a SQL variable.
Syntax SET identifier = expression
Permissions None.
Side effects None.
See also "CREATE VARIABLE statement" on page 468
"DECLARE statement" on page 474
"DROP VARIABLE statement" on page 499
"Expressions" on page 218
Description The SET statement assigns a new value to a variable. The variable must have
been previously created using a CREATE VARIABLE statement or
DECLARE statement, or it must be an OUPUT parameter for a procedure.
A variable can be used in a SQL statement anywhere a column name is
allowed. If a column name exists with the same name as the variable, the
variable value is used.
Variables are local to the current connection, and disappear when you
disconnect from the database or use the DROP VARIABLE statement. They
are not affected by COMMIT or ROLLBACK statements.
Variables are necessary for creating large text or binary objects for INSERT
or UPDATE statements from embedded SQL programs, because
embedded SQL host variables are limited to 32,767 bytes.
Standards and ♦ SQL/92 Persistent stored module feature.
compatibility
♦ Sybase Not supported. In Adaptive Server Enterprise, variables are
assigned using the SELECT statement with no table, a Transact-SQL
syntax that is also supported by Adaptive Server Anywhere. The SET
statement is used to set database options in Adaptive Server Enterprise.
Example ♦ The following code fragment could be used to insert a large text value
into the database.
591
SET statement
592
Chapter 9 SQL Statements
Database options in Adaptive Server Anywhere are set using the SET
OPTION statement. However, Adaptive Server Anywhere also provides
support for the Adaptive Server Enterprise SET statement for options that are
particularly useful for compatibility.
In addition, the SET statement is allowed by Adaptive Server Anywhere for
the PREFETCH option, for compatibility, but has no effect:
Standards and ♦ SQL/92 Transact-SQL extension
compatibility
♦ Sybase Adaptive Server Anywhere supports a subset of the Adaptive
Server Enterprise database options.
593
SET CONNECTION statement [Interactive SQL][ESQL]
Standards and ♦ SQL/92 Interactive SQL use is a vendor extension. Embedded SQL is
compatibility a Full level feature.
♦ Sybase Supported by Open Client/Open Server.
Example ♦ The following example is in Embedded SQL.
EXEC SQL SET CONNECTION :conn_name;
♦ From Interactive SQL, set the current connection to the connection
named conn1.
SET CONNECTION conn1;
594
Chapter 9 SQL Statements
595
SET OPTION statement
596
Chapter 9 SQL Statements
If you specify a user ID, the option value applies to that user (or, for a group
user ID, the members of that group). If you specify PUBLIC, the option
value applies to all users who don’t have an individual setting for the option.
By default, the option value applies to the currently logged on user ID that
issued the SET OPTION statement..
For example, the following statement applies an option change to the user
DBA, if DBA is the user issuing the SQL statement:
SET OPTION login_mode = mixed
However the following statement applies the change to the PUBLIC user ID,
a user group to which all users belong.
SET OPTION Public.login_mode = standard
Only users with DBA privileges have the authority to set an option for the
PUBLIC user ID.
In embedded SQL, database options can be set only temporarily.
Users can use the SET OPTION statement to change the values for their own
user ID. Setting the value of an option for a user id other then your own is
permitted only if you have DBA authority.
Adding the TEMPORARY keyword to the SET OPTION statement changes
the duration that the change takes effect. By default, the option value is
permanent: it will not change until it is explicitly changed using the SET
OPTION statement.
When the SET TEMPORARY OPTION statement is not qualified with a
user ID, the new option value is in effect only for the current connection.
When SET TEMPORARY OPTION is used for the PUBLIC user ID, the
change is in place for as long as the database is running. When the database
is shut down, TEMPORARY options for the PUBLIC group revert back to
their permanent value.
Setting temporary options for the PUBLIC user ID offers a security benefit.
For example, when the LOGIN_MODE option is enabled, the database relies
on the login security of the system on which it is running. Enabling it
temporarily means that a database relying on the security of a Windows NT
domain will not be compromised if the database is shut down and copied to a
local machine. In that case, the temporary enabling of the LOGIN_MODE
option reverts to its permanent value, which could be Standard, a mode
where integrated logins are not permitted.
If option-value is omitted, the specified option setting will be deleted from
the database. If it was a personal option setting, the value will revert back to
the PUBLIC setting. If a TEMPORARY option is deleted, the option setting
will revert back to the permanent setting.
597
SET OPTION statement
Caution
Changing option settings while fetching rows from a cursor is not
supported, as it can lead to ill-defined behavior. For example, changing
the DATE_FORMAT setting while fetching from a cursor would lead to
different date formats among the rows in the result set. Do not change
option settings while fetching rows.
598
Chapter 9 SQL Statements
599
SET SQLCA statement [ESQL]
600
Chapter 9 SQL Statements
SETUSER statement
Function Use this statement to allow a database administrator to impersonate another
user, and to enable connection pooling.
Syntax { SET SESSION AUTHORIZATION | SETUSER }
[ [ WITH OPTIONS ] userid ]
Permissions Must have DBA authority.
See also "EXECUTE IMMEDIATE statement" on page 504
"GRANT statement" on page 526
"REVOKE statement" on page 581
"SET OPTION statement" on page 596
Description The SETUSER statement is provided to make database administration easier.
It enables a user with DBA authority to impersonate another user of the
database.
SETUSER can also be used from an application server to take advantage of
connection pooling. Connection pooling cuts down the number of distinct
connections that need to be made, which can improve performance.
SETUSER with no user ID undoes all earlier SETUSER statements.
There are several uses for the SETUSER statement, including the following:
♦ Creating objects You can use SETUSER to create a database object
that is to be owned by another user.
♦ Permissions checking By acting as another user, with their
permissions and group memberships, a DBA can test the permissions
and name resolution of queries, procedures, views, and so on.
♦ Providing a safer environment for administrators The DBA has
permission to carry out any action in the database. If you wish to ensure
that you do not accidentally carry out an unintended action, you can use
SETUSER to switch to a different user ID with fewer permissions.
Parameters WITH OPTIONS By default, only permissions (including group
membership) are altered. If WITH OPTIONS is specified, the database
options in effect are changed to the current database options of userid.
Standards and ♦ SQL/92 SET SESSION AUTHORIZATION is SQL 92 compliant.
compatibility SETUSER is a vendor extension.
♦ Sybase Adaptive Server Enterprise supports SETUSER, but not the
WITH OPTIONS keywords.
Examples ♦ The following statements, executed by a user named DBA, change the
user ID to be Joe, then Jane, and then back to DBA
601
SETUSER statement
SETUSER ’Joe’
// ... operations...
SETUSER WITH OPTIONS ’Jane’
// ... operations...
SETUSER
602
Chapter 9 SQL Statements
SIGNAL statement
Function Use this statement to signal an exception condition.
Syntax SIGNAL exception-name
Permissions None.
Side effects None.
See also "DECLARE statement" on page 474
"RESIGNAL statement" on page 576
"BEGIN statement" on page 392
"Using exception handlers in procedures and triggers" on page 466 of the
book ASA User’s Guide
Description SIGNAL allows you to raise an exception. See "Using exception handlers in
procedures and triggers" on page 466 of the book ASA User’s Guide for a
description of how exceptions are handled.
603
START DATABASE statement
AUTOSTOP clause The default setting for the AUTOSTOP clause is ON.
With AUTOSTOP set to ON, the database is unloaded when the last
connection to it is dropped. If AUTOSTOP is set to OFF, the database is not
unloaded.
604
Chapter 9 SQL Statements
605
START ENGINE statement [Interactive SQL]
606
Chapter 9 SQL Statements
607
START LOGGING statement [Interactive SQL]
608
Chapter 9 SQL Statements
609
STOP ENGINE statement
610
Chapter 9 SQL Statements
611
STOP LOGGING statement [Interactive SQL]
612
Chapter 9 SQL Statements
613
TRIGGER EVENT statement
614
Chapter 9 SQL Statements
615
TRUNCATE TABLE statement
616
Chapter 9 SQL Statements
UNION operation
Function Use this statement to combine the results of two or more select statements.
Syntax select-without-order-by
… UNION [ALL] select-without-order-by
… [ UNION [ALL] select-without-order-by ] …
… [ ORDER BY integer [ ASC | DESC ], … ]
Permissions Must have SELECT permission for each of the component SELECT
statements.
Side effects None.
See also "SELECT statement" on page 587
Description The results of several SELECT statements can be combined into a larger
result using UNION. The component SELECT statements must each have
the same number of items in the select list, and cannot contain an
ORDER BY clause.
The results of UNION ALL are the combined results of the component
SELECT statements. The results of UNION are the same as UNION ALL,
except that duplicate rows are eliminated. Eliminating duplicates requires
extra processing, so UNION ALL should be used instead of UNION where
possible.
If corresponding items in two select lists have different data types, Adaptive
Server Anywhere will choose a data type for the corresponding column in
the result and automatically convert the columns in each component
SELECT statement appropriately.
If ORDER BY is used, only integers are allowed in the order by list. These
integers specify the position of the columns to be sorted.
The column names displayed are the same column names that are displayed
for the first SELECT statement.
Standards and ♦ SQL/92 Entry level.
compatibility
♦ Sybase Supported by Adaptive Server Enterprise, which also supports
a COMPUTE clause.
Examples ♦ List all distinct surnames of employees and customers.
SELECT emp_lname
FROM Employee
UNION
SELECT lname
FROM Customer
617
UNLOAD statement
UNLOAD statement
Function Use this statement to export data from a database into an external ASCII-
format file.
Syntax UNLOAD select-statement
… TO 'filename-string'
[ unload-option … ]
unload-option:
DELIMITED BY string
| ESCAPE CHARACTER character
| ESCAPES {ON | OFF}
| FORMAT {ASCII | BCP}
| HEXADECIMAL {ON | OFF}
| ORDER {ON | OFF}
| QUOTES {ON | OFF}
Permissions The permissions required to execute an UNLOAD statement are set on the
database server command line, using the –gl command-line option.
$ For more information, see "–gl command-line option" on page 27.
Side effects None. The query is executed at the current isolation level.
See also "UNLOAD TABLE statement" on page 619
"OUTPUT statement" on page 559
Description The UNLOAD statement allows the result set of a query to be exported to a
comma-delimited file. The result set is not ordered unless the query itself
contains an ORDER BY clause.
When unloading result set columns with binary data types, UNLOAD writes
hexadecimal strings, of the form \xnnnn where n is a hexadecimal digit.
$ For a description of the unload-option parameters, see "UNLOAD
TABLE statement" on page 619.
Parameters filename-string The filename to which the data is to be unloaded.
Because it is the database server that executes the statements, filenames
specify files on the database server machine. Relative filenames specify files
relative to the database server's starting directory. To unload data onto a
client machine, see "OUTPUT statement" on page 559.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase UNLOAD is not supported by Adaptive Server Enterprise.
618
Chapter 9 SQL Statements
619
UNLOAD TABLE statement
QUOTES option With QUOTES turned on (the default), single quotes are
placed around all exported strings.
Standards and ♦ SQL/92 Vendor extension.
compatibility
♦ Sybase UNLOAD TABLE is not supported by Adaptive Server
Enterprise. Similar functionality is provided by the Adaptive Server
Enterprise bulk copy utility (bcp).
620
Chapter 9 SQL Statements
UPDATE statement
Function Use this statement to modify existing rows in database tables.
Syntax 1 UPDATE [ FIRST | TOP n ] table-list
… SET set-item, …
… [ FROM table-list ]
… [ WHERE search-condition ]
… [ ORDER BY expression [ ASC | DESC ], … ]
Syntax 2 UPDATE table-list
… SET set-item, …
… [ VERIFY ( column-name, … ) VALUES ( expression, … ) ]
… [ WHERE search-condition ]
… [ ORDER BY expression [ ASC | DESC ], … ]
Syntax 3 UPDATE table
…PUBLICATION publication
…{ SUBSCRIBE BY expression
| OLD SUBSCRIBE BY expression
NEW SUBSCRIBE BY expression
}
…WHERE search-condition
set-item:
column-name [.field-name…] = expression
| column-name[.field-name…].method-name( [ expression ] )
Permissions Must have UPDATE permission for the columns being modified.
Side effects None.
See also "DELETE statement" on page 482
"INSERT statement" on page 540
"FROM clause" on page 518
"Joins: Retrieving Data from Several Tables" on page 189 of the book ASA
User’s Guide
Description Syntax 1 of the UPDATE statement modifies values in rows of one or more
tables. Syntax 2 and 3 are applicable only to SQL Remote.
Syntax 2 is intended for use with SQL Remote only, in single-row updates
executed by the Message Agent. The VERIFY clause contains a set of values
that are expected to be present in the row being updated. If the values do not
match, any RESOLVE UPDATE triggers are fired before the UPDATE
proceeds. The UPDATE does not fail simply because the VERIFY clause
fails to match.
Syntax 3 of the UPDATE statement is used to implement a specific
SQL Remote feature, and is to be used inside a BEFORE trigger.
621
UPDATE statement
It provides a full list of SUBSCRIBE BY values any time the list changes. It
is placed in SQL Remote triggers so that the database server can compute the
current list of SUBSCRIBE BY values. Both lists are placed in the
transaction log.
The Message Agent uses the two lists to make sure that the row moves to any
remote database that did not have the row and now needs it. The Message
Agent also removes the row from any remote database that has the row and
no longer needs it. A remote database that has the row and still needs it is not
be affected by the UPDATE statement.
For publications created using a subquery in a SUBSCRIBE BY clause, you
must write a trigger containing syntax 3 of the UPDATE statement in order
to ensure that the rows are kept in their proper subscriptions.
Syntax 3 of the UPDATE statement allows the old SUBSCRIBE BY list and
the new SUBSCRIBE BY list to be explicitly specified, which can make
SQL Remote triggers more efficient. In the absence of these lists, the
database server computes the old SUBSCRIBE BY list from the publication
definition. Since the new SUBSCRIBE BY list is commonly only slightly
different from the old SUBSCRIBE BY list, the work to compute the old list
may be done twice. By specifying both the old and new lists, you can avoid
this extra work.
The SUBSCRIBE BY expression is either a value or a subquery.
Syntax 3 of the UPDATE statement makes an entry in the transaction log,
but does not change the database table.
Parameters UPDATE clause The table is either a base table, a temporary table, or a
view. Views can be updated unless the SELECT statement defining the view
contains a GROUP BY clause or aggregate function, or involves a UNION
operation.
FIRST or TOP clause Primarily for use with the ORDER BY clause, this
clause allows you to update only a certain subset of the rows that satisfy the
WHERE clause.
SET clause If you are updating non-Java columns, the SET clause is of
the following form:
SET column-name = expression, ...
Each named column is set to the value of the expression on the right hand
side of the equal sign. There are no restrictions on the expression. If the
expression is a column-name, the old value is used.
If you are updating Java columns, you can use field-name to update the value
of a public field in the column. Alternatively, you can use a method to set the
value. The following clause updates name field of the JProd column using a
method:
622
Chapter 9 SQL Statements
ORDER BY clause Normally, the order in which rows are updated does
not matter. However, in conjunction with the FIRST or TOP clause the order
can be significant.
You must not update columns that appear in the ORDER BY clause unless
you set the ANSI_UPDATE_CONSTRAINTS option to OFF. See
"ANSI_UPDATE_CONSTRAINTS option" on page 159.
Case sensitivity Character strings inserted into tables are always stored in
the same case as they are entered, regardless of whether the database is case
sensitive or not. A CHAR data type column updated with a string Value is
always held in the database with an upper case V and the remainder of the
letters lower case. SELECT statements return the string as Value. If the
database is not case sensitive, however, all comparisons make Value the
same as value, VALUE, and so on. Further, if a single-column primary key
already contains an entry Value, an INSERT of value is rejected, as it would
make the primary key not unique.
Updates that leave a row unchanged If the new value does not differ
from the old value, no change is made to the data. However, BEFORE
UPDATE triggers fire any time an UPDATE occurs on a row, whether or not
the new value differs from the old value. AFTER UPDATE triggers fire only
if the new value is different from the old value.
623
UPDATE statement
Standards and ♦ SQL/92 Syntax 1 is an entry-level feature, except for the FROM and
compatibility ORDER BY clauses, which are vendor extensions. Syntax 2 and 3 are
vendor extensions for use only with SQL Remote.
To enforce SQL/92 compatibility, ensure that the
ANSI_UPDATE_CONSTRAINTS option is set to STRICT.
$ For more information, see "ANSI_UPDATE_CONSTRAINTS
option" on page 159.
♦ Sybase Subject to the expressions being compatible, the syntax of the
UPDATE statement (syntax 1) is compatible between Adaptive Server
Enterprise and Adaptive Server Anywhere. Syntax 2 and 3 are not
supported.
Examples ♦ Transfer employee Philip Chin (employee 129) from the sales
department to the marketing department.
UPDATE employee
SET dept_id = 400
WHERE emp_id = 129;
♦ Sales orders currently start at ID 2001. Renumber all existing sales
orders by subtracting 2000 from the ID.
UPDATE sales_order AS orders
SET orders.id = orders.id - 2000
ORDER BY items.id ASC
This update is possible only if the foreign key of the sales_order_items
table (referencing the primary key sales_order.id) is defined with the
action ON UPDATE CASCADE. The sales_order_items table is then
updated as well.
$ For more information on foreign key properties, see "ALTER
TABLE statement" on page 380 and "CREATE TABLE statement" on
page 453.
624
Chapter 9 SQL Statements
625
UPDATE (positioned) statement
626
Chapter 9 SQL Statements
627
VALIDATE TABLE statement
WITH FULL CHECK In addition to the default checks, carry out a DATA
CHECK and an INDEX CHECK.
628
Chapter 9 SQL Statements
629
WHENEVER statement [ESQL]
630
Chapter 9 SQL Statements
631
WRITETEXT statement [T-SQL]
632
C H A P T E R 1 0
About this chapter This chapter lists all database error messages reported by Adaptive Server
Anywhere. Many of the errors contain the characters %1, %2 and so on.
These are replaced by the parameters to the error message.
Each error has a numeric error code, called the SQLCODE. Negative codes
are considered errors; positive codes are warnings. The SQLCODE 0
indicates successful completion.
The full listing of the error messages is ordered by SQLCODE value. To find
an error message description if you do not have the SQLCODE value, look
up the SQLCODE in the alphabetic or SQLSTATE listing.
Contents
Topic Page
Error messages indexed by Adaptive Server Anywhere SQLCODE 634
Error messages indexed by SQLSTATE 652
Error messages indexed by Sybase error code 670
Alphabetic list of error messages 693
Internal errors (assertion failed) 904
633
Error messages indexed by Adaptive Server Anywhere SQLCODE
634
CHAPTER 10 Database Error Messages
635
Error messages indexed by Adaptive Server Anywhere SQLCODE
636
CHAPTER 10 Database Error Messages
637
Error messages indexed by Adaptive Server Anywhere SQLCODE
638
CHAPTER 10 Database Error Messages
639
Error messages indexed by Adaptive Server Anywhere SQLCODE
640
CHAPTER 10 Database Error Messages
641
Error messages indexed by Adaptive Server Anywhere SQLCODE
642
CHAPTER 10 Database Error Messages
643
Error messages indexed by Adaptive Server Anywhere SQLCODE
644
CHAPTER 10 Database Error Messages
645
Error messages indexed by Adaptive Server Anywhere SQLCODE
646
CHAPTER 10 Database Error Messages
647
Error messages indexed by Adaptive Server Anywhere SQLCODE
648
CHAPTER 10 Database Error Messages
649
Error messages indexed by Adaptive Server Anywhere SQLCODE
650
CHAPTER 10 Database Error Messages
651
Error messages indexed by SQLSTATE
652
CHAPTER 10 Database Error Messages
653
Error messages indexed by SQLSTATE
654
CHAPTER 10 Database Error Messages
655
Error messages indexed by SQLSTATE
656
CHAPTER 10 Database Error Messages
657
Error messages indexed by SQLSTATE
658
CHAPTER 10 Database Error Messages
659
Error messages indexed by SQLSTATE
660
CHAPTER 10 Database Error Messages
661
Error messages indexed by SQLSTATE
662
CHAPTER 10 Database Error Messages
663
Error messages indexed by SQLSTATE
664
CHAPTER 10 Database Error Messages
665
Error messages indexed by SQLSTATE
666
CHAPTER 10 Database Error Messages
667
Error messages indexed by SQLSTATE
668
CHAPTER 10 Database Error Messages
669
Error messages indexed by Sybase error code
670
CHAPTER 10 Database Error Messages
671
Error messages indexed by Sybase error code
672
CHAPTER 10 Database Error Messages
673
Error messages indexed by Sybase error code
674
CHAPTER 10 Database Error Messages
675
Error messages indexed by Sybase error code
676
CHAPTER 10 Database Error Messages
677
Error messages indexed by Sybase error code
678
CHAPTER 10 Database Error Messages
679
Error messages indexed by Sybase error code
680
CHAPTER 10 Database Error Messages
681
Error messages indexed by Sybase error code
682
CHAPTER 10 Database Error Messages
683
Error messages indexed by Sybase error code
684
CHAPTER 10 Database Error Messages
685
Error messages indexed by Sybase error code
686
CHAPTER 10 Database Error Messages
687
Error messages indexed by Sybase error code
688
CHAPTER 10 Database Error Messages
689
Error messages indexed by Sybase error code
690
CHAPTER 10 Database Error Messages
691
Error messages indexed by Sybase error code
692
CHAPTER 10 Database Error Messages
(no message)
Item Value
SQLCODE 0
Constant SQLE_NOERROR
SQLSTATE 00000
Sybase error code 13600
ODBC 2 State 00000
ODBC 3 State 00000
Probable cause This code indicates that there was no error or warning.
(no message)
Item Value
SQLCODE -503
Constant SQLE_PREEMPTED
SQLSTATE WI006
Sybase error code 13692
ODBC 2 State ERROR
ODBC 3 State ERROR
693
Alphabetic list of error messages
(no message)
Item Value
SQLCODE -504
Constant SQLE_RETRY
SQLSTATE WI008
Sybase error code 13693
ODBC 2 State ERROR
ODBC 3 State ERROR
%1
Item Value
SQLCODE -121
Constant SQLE_PERMISSION_DENIED
SQLSTATE 42501
Sybase error code 262
ODBC 2 State 42000
ODBC 3 State 42000
Parameter 1 Description of the type of permission lacking.
Probable cause You do not have the required permission to do the specified action. The
message specifies the actual permission required and the object being acted
upon.
694
CHAPTER 10 Database Error Messages
%1
Item Value
SQLCODE -266
Constant SQLE_OLD_DBINIT
SQLSTATE 42W27
Sybase error code 13639
ODBC 2 State ERROR
ODBC 3 State ERROR
Probable cause The database is missing some system table definitions required for this
statement. These system table definitions are normally created when a
database is initialized. The database should be unloaded and reloaded into a
database that has been initialized with a newer version of Adaptive Server
Anywhere or use DBUPGRADE to upgrade the database to the most recent
version.
%1
Item Value
SQLCODE -682
Constant SQLE_OMNI_DEBUG
SQLSTATE WO010
Sybase error code 13734
ODBC 2 State OK
ODBC 3 State OK
Parameter 1 The debug message for the console
Probable cause This message is used for displaying component integration services debug
mesages on the console.
695
Alphabetic list of error messages
Probable cause You attempted to set the value of an option which is not known to the server.
You should make sure that you did intend to set the specified option as
opposed to having make a typographical error.
Probable cause An unsupported file format was specifed for LOAD TABLE or UNLOAD
TABLE.
696
CHAPTER 10 Database Error Messages
’%1’ is not a public java class, and cannot be referenced from SQL
Item Value
SQLCODE -762
Constant SQLE_NON_PUBLIC_JAVA_CLASS
SQLSTATE WJ023
Sybase error code 13772
ODBC 2 State ERROR
ODBC 3 State ERROR
Parameter 1 Java class name
Probable cause Only public java classes installed into the database are accessible from SQL.
Probable cause The dotted expression is neither a public java class nor a java variable.
697
Alphabetic list of error messages
Probable cause A file passed to the INSTALL JAVA statement was not a valid Java class
file.
Probable cause The write file specified in the ALTER WRITEFILE statement is not a
writefile for the database specified.
698
CHAPTER 10 Database Error Messages
Probable cause You attempted to grant consolidated permissions when your database already
has a consolidated user.
Probable cause A dbspace has grown to its maximum number of disk pages, which is usually
limited by the maximum operating system file size. This is a fatal error.
699
Alphabetic list of error messages
Probable cause This is a Windows95 specific error. An operating system thread could not be
started that is required to execute external functions.
700
CHAPTER 10 Database Error Messages
Probable cause You attempted to read or write a row and it is locked by another user. Also,
all other threads (see database option THREAD_COUNT) are blocked
waiting for a lock to be released. This is a deadlock situation and your
transaction has been chosen as the one to rollback.
Probable cause A primary key clause, foreign key clause, or a uniqueness clause must be the
only clause of an ALTER TABLE statement.
Probable cause Your attempt to delete a database file failed. You may have attempted to
delete a running database. Some parts of the database may have been deleted
before failure.
701
Alphabetic list of error messages
Probable cause This is an internal JDBC object error. If it can be reproduced, it should be
reported to Sybase.
Probable cause This is an internal native Java object error. If it can be reproduced, it should
be reported to Sybase.
702
CHAPTER 10 Database Error Messages
Probable cause You attempted to register a connection with a label already in use for the
same application.
703
Alphabetic list of error messages
Probable cause You passed a null value to a procedure expecting a scalar argument. For
example, a Java procedure which has an ’int’ argument cannot receive a null
value.
Probable cause While reading the database file, an attempt was made to read beyond the end
of the file. This is a fatal internal error.
704
CHAPTER 10 Database Error Messages
Probable cause In Embedded SQL, you attempted to submit a database request while you
have another request in process. This often occurs in Windows when
processing the WM_PAINT message causes a database request, and you get
a second WM_PAINT before the database request has completed.
Authentication failed
Item Value
SQLCODE -218
Constant SQLE_AUTHENTICATION_FAILED
SQLSTATE 08W48
Sybase error code 13621
ODBC 2 State 08001
ODBC 3 State 08001
705
Alphabetic list of error messages
Authentication violation
Item Value
SQLCODE -98
Constant SQLE_AUTHENTICATION_VIOLATION
SQLSTATE 08W21
Sybase error code 13620
ODBC 2 State 08001
ODBC 3 State 08001
Probable cause You attempted to connect to a server which has been authenticated for
exclusive use with a specific application.
Probable cause The format of an archive file to be used during a RESTORE is invalid.
706
CHAPTER 10 Database Error Messages
Probable cause Backwards scrolling cursors are not supported for remote objects. Change
the client program to use forward scrolling cursors only.
Probable cause You attempted to call a stored procedure that, in turn, calls a function in a
dynamically loaded module. The operating system on which this stored
procedure was called does not support such an action.
Probable cause In the C language interface, you attempted to describe the select list of a
statement other than a SELECT statement.
707
Alphabetic list of error messages
Probable cause A file cannot be accessed. For example, a file referenced by LOAD TABLE
does not exist or cannot be read. The message will contain the reason for the
error.
Probable cause Non-static fields or methods must be accessed through an object instance.
708
CHAPTER 10 Database Error Messages
Probable cause IQ was unable to allocate System V resources. Please delete unused System
V semaphores and shared memory segments or increase OS configuration
values for these resources.
Probable cause You may have attempted to delete or modify the definition of a column that
is part of a primary or foreign key. You may have attempted to delete a
column that has an index on it. In this case, DROP the index or key, perform
the ALTER statement, and then add the index or key again.
709
Alphabetic list of error messages
Probable cause Some resultset function such as ’updateRow’ and ’deleteRow’ are invalid
when the cursor of the resultset is positioned at the insert row.
Probable cause You tried to explicitly commit or rollback on a connection that is enlisted in
a transaction. You must use the Commit/Abort protocol of the transaction
instead.
710
CHAPTER 10 Database Error Messages
Cannot convert %1 to a %2
Item Value
SQLCODE -157
Constant SQLE_CONVERSION_ERROR
SQLSTATE 53018
Sybase error code 257
ODBC 2 State 07006
ODBC 3 State 07006
Parameter 1 The value that could not be converted.
Parameter 2 The name of the type for the conversion.
Probable cause You supplied to or fetched from the database an invalid value. For example,
the value 12X might have been supplied where a number was required.
Probable cause An operation requiring an index was attempted in which at attempt was made
to create an index on a Java class type.
711
Alphabetic list of error messages
Probable cause The dbspace specified is invalid. For example, an index must be created in a
dbspace of the same type as the underlying table.
Probable cause You attempted to create a synchronization on a table with BLOB primary
key.
712
CHAPTER 10 Database Error Messages
Probable cause You attempted to delete a column referenced in a trigger definition. DROP
the trigger before performing the ALTER statement.
Probable cause You attempted to deregister an application while there are still active
connection registered to that application.
713
Alphabetic list of error messages
Probable cause Application has not been registered successfully or it has already been
deregistered previously.
Probable cause The persisted Java object cannot be read from the database column. Possibly,
the class of the object has been removed or modified.
714
CHAPTER 10 Database Error Messages
Probable cause You attempted to drop a user who is the creator of a message or user-defined
data type. The message or user-defined data type must be dropped first.
Probable cause You attempted to drop a user who is the creator of a database object involved
in replication. For example. the user may own a table that is part of a
publication.
715
Alphabetic list of error messages
Probable cause You attempted to drop a user who owns procedures whil using the runtime
server. This operation would result in dropping procedures, and the runtime
server cannot drop procedures. Use the full server.
Probable cause You attempted to drop a user who owns tables, while running the runtime
server. This operation would result in dropping tables, which is not permitted
in the runtime server. Use the full server.
716
CHAPTER 10 Database Error Messages
Probable cause You tried to enlist a second transaction on a connection that is already
enlisted in a transaction.
Probable cause You tried to enlist a transaction on a connection that has pending
uncommitted data.
717
Alphabetic list of error messages
Probable cause You attempted to drop an index that does not exist. Check for spelling errors.
Check whether the index name must be qualified by a user ID.
Probable cause System V shared memory was requested but could not be allocated.
718
CHAPTER 10 Database Error Messages
Probable cause Computed column values cannot be modified explicitly. Their value is
determined implicitly from the computed expression value.
719
Alphabetic list of error messages
Probable cause You may have tried to modify a column that you do not have permission to
modify. You may have tried to modify a column defined as an expression
(such as column1+column2) in a view.
720
CHAPTER 10 Database Error Messages
Probable cause You attempted to modify a publication entry using an alter synchronization
statement.
Probable cause You attempted to modify a synchronization entry using an alter publication
statement.
721
Alphabetic list of error messages
Probable cause You misspelled the name of a synchronization publication, or you did not
qualify a publication name with a user name.
Probable cause The database server was unable to open the named transaction log file. The
log file name may include an invalid device or directory. If this is the case,
you can use the DBLOG utility to find out where the transaction log should
be and perhaps change it.
722
CHAPTER 10 Database Error Messages
Probable cause You attempted to start an application but another exclusive instance of the
same application is already registered.
723
Alphabetic list of error messages
Probable cause You attempted to register an exclusive application but another instance of the
same application is already registered.
Probable cause Application registration cannot be found for the given cookie.
724
CHAPTER 10 Database Error Messages
Probable cause You attempted to remove a class file which is still part of a Jar. (It must be
removed with the Jar)
725
Alphabetic list of error messages
Probable cause The Java object cannot be serialized as a persistent database column.
Probable cause TEMPORARY options are set on a connection basis. To change an option
for another user, do not specify TEMPORARY in the SET OPTION
statement.
726
CHAPTER 10 Database Error Messages
Probable cause The server has determined that it cannot be shut down at this time. Normally,
this error should not occur.
727
Alphabetic list of error messages
Cannot synchronize table ’%1’ since it does not have a primary key
Item Value
SQLCODE -777
Constant SQLE_CANNOT_SYNC_TABLE_WITHOUT_PK
SQLSTATE 5RW16
Sybase error code 13787
ODBC 2 State 42000
ODBC 3 State 42S02
Parameter 1 Name of the table
Probable cause Failed to identify a column in a JDBC resultset with the given table name
and column name. This can happen either the given names are not found or
they are ambiguous.
728
CHAPTER 10 Database Error Messages
Probable cause You opened a UNIQUE cursor on a SELECT statement for which a set of
columns uniquely identifying each row cannot be generated. One of the
tables may not be defined with a primary key or uniqueness constraint, or the
SELECT statement may involve a UNION or GROUP BY.
Probable cause You tried to update a column in a query that is a database expression rather
than a column in a table.
729
Alphabetic list of error messages
Probable cause You attempted to update a column that appears in the ORDER BY clause.
The ANSI_UPDATE_CONSTRAINTS option controls whether this update
is allowed.
Cannot update column ’%1’ since it does not appear in the SELECT
clause.
Item Value
SQLCODE -815
Constant SQLE_UPDATE_NOT_IN_SELECT
SQLSTATE 42W38
Sybase error code 7740
ODBC 2 State 42000
ODBC 3 State 42000
Parameter 1 Name of the column that does not appear in the SELECT
clause.
Probable cause You attempted to update a column that does not explicitly appear in the
SELECT list. The ANSI_UPDATE_CONSTRAINTS option controls
whether this update is allowed.
730
CHAPTER 10 Database Error Messages
Probable cause An attempt was made to modify a Java member that was qualified with the
"final" modifier. Such members are constant and cannot be modified.
Probable cause You attempted to modify or delete a row in the specified table, which is part
of the null-supplying side of an outer join. However, the cursor is currently
positioned on a derived row that contains an all-NULL row for this table,
which is the result of the failure of one or more ON conditions to evaluate to
TRUE. Verify that the UPDATE or DELETE statement is correct.
731
Alphabetic list of error messages
Probable cause The primary key of a table involved in replication cannot be updated. The
database option "Allow_replication_pkey_update" can be set to "OFF" to
allow updates to the primary key of table involved in replication.
Probable cause The primary key of a table involved in a synchronization publication cannot
be updated. The database option "Allow_sync_pkey_update" can be set to
"OFF" to allow updates to the primary key of table involved in a
synchronization publication.
732
CHAPTER 10 Database Error Messages
Probable cause The server is unable to do a character translation from the character set the
database is using to the character set the application requested.
Probable cause You cannot use a CHECKPOINT statement when the database server is
running in bulk mode without a rollback log.
733
Alphabetic list of error messages
Probable cause An expression referenced a field which either does not exist or is not public.
Probable cause Your executable uses a database interface library that does not match the
version number of the database server.
734
CHAPTER 10 Database Error Messages
Probable cause The connection failed because the protocol versions of the client and the
server do not match. Make sure the client and server software are the same
version.
Probable cause The data type of the column in the foreign key is not the same as the data
type of the column in the primary key. Change the definition of one of the
columns using ALTER TABLE.
735
Alphabetic list of error messages
Probable cause You have not put a correlation name on a column that is found in more than
one of the tables referenced in a query. You need to add a correlation name
to the reference.
Probable cause You have not supplied a value where a value is required. The column
definition prohibits NULL values or the column is part of a NOT NULL
foreign key.
736
CHAPTER 10 Database Error Messages
Probable cause You misspelled the name of a column, or the column you are looking for is
in a different table.
737
Alphabetic list of error messages
Probable cause You attempted to execute a statement that is not allowed while performing a
trigger action. COMMIT and ROLLBACK statements cannot be executed
from a trigger.
Communication error
Item Value
SQLCODE -85
Constant SQLE_COMMUNICATIONS_ERROR
SQLSTATE 08W12
Sybase error code 1602
ODBC 2 State 08S01
ODBC 3 State 08S01
Probable cause There is a client/server communication problem. The client may have been
unable to start because a communication error occurred while trying to locate
the server.
738
CHAPTER 10 Database Error Messages
Probable cause The current database is an older database and does not have catalog support
for computed (materialized) columns. To use this feature, upgrade your
database to the most recent version.
739
Alphabetic list of error messages
Probable cause Your database connection has been terminated and your transaction has been
rolled back. The connection may have been terminated because a DBA
executed a DROP CONNECTION statement, or because the database server
was shut down, or because your network connection to the database server
was interrupted.
Probable cause Connections to the network database server have been disabled. You will
receive this error until they have been re-enabled on the server console.
740
CHAPTER 10 Database Error Messages
Probable cause During a RESTORE, the contents of a backup that was done to two or more
disk or tape devices were found to be inconsistent.
Probable cause You misspelled a correlation name, or you used a table name instead of the
correlation name.
741
Alphabetic list of error messages
Probable cause Column information for the table could not be accessed. Check privileges for
the table.
Probable cause The external function could not be called due to a shortage of operating
system resources. If the operating system supports threads, the maximum
thread count should be increased.
742
CHAPTER 10 Database Error Messages
Probable cause You attempted to change the SQL statement of an opened prepared statement
or callable statement. Prepared statement and callable statement must be
closed before attempting such changes.
Probable cause The Java runtime library must be installed to extract class files from .ZIPs or
.JARs
743
Alphabetic list of error messages
Probable cause An attempt to locate or execute the backup/restore DLL entry point failed.
Probable cause An attempt to locate or execute the store DLL entry point failed.
744
CHAPTER 10 Database Error Messages
Probable cause The external function could not be found in the dynamic library.
Probable cause This error is usually caused by a failure to load a dynamic library named in
an external function call. This error can also occur if other libraries such as
the Java virtual machine library are missing.
745
Alphabetic list of error messages
746
CHAPTER 10 Database Error Messages
Probable cause Computed columns are not supported in ’CREATE TABLE’ statements
which specify a remote location.
Probable cause You attempted to register this connection more than once.
747
Alphabetic list of error messages
Probable cause You attempted to OPEN a cursor that has not been declared.
Probable cause An illegal FETCH operation has been detected for a NO SCROLL cursor.
For a forward-only cursor the only permitted FETCH operations are FETCH
RELATIVE 0 and FETCH NEXT (FETCH RELATIVE 1).
748
CHAPTER 10 Database Error Messages
Probable cause You attempted to OPEN a cursor that has not been declared.
Probable cause You attempted to perform an operation on the current row of a cursor, but the
row has been modified by a searched UPDATE or DELETE or by a
positioned UPDATE or DELETE.
749
Alphabetic list of error messages
Probable cause The procedure or trigger definition contains a data definition statement (such
as CREATE, DROP, GRANT, REVOKE, ALTER). These statements are
not allowed within procedures or triggers.
Probable cause The database quit abnormally the last time it was used. Database recovery
must be performed before proceeding.
750
CHAPTER 10 Database Error Messages
Probable cause A database backup could not be started. Either you do not have DBA
authority, or another backup has started and not completed.
Probable cause The specified database cannot be started. Either it does not exist, it is not a
database, it is corrupt, or it is an older format.
751
Alphabetic list of error messages
Probable cause Your attempt to initialize a file for a database or for a write file failed.
Database is active
Item Value
SQLCODE -664
Constant SQLE_DATABASE_ACTIVE
SQLSTATE 08W40
Sybase error code 13708
ODBC 2 State ERROR
ODBC 3 State ERROR
Probable cause An attempt was made to create a writefile for a database that is currently
active.
752
CHAPTER 10 Database Error Messages
Probable cause The database cannot be started as its name is conflicting with a previously
started database.
Probable cause You did not supply a database name. A database name is required to start the
database server.
Probable cause Upon processing a connection request for a specific user, the server
processed a database option from the SYSOPTIONS table which had an
invalid setting. The erroneous option setting is ignored; in its place, the
server will use the default option value for the current database.
753
Alphabetic list of error messages
Probable cause You attempted to start a database or create a write file for a database with a
page size that exceeds the maximum page size of the running server. Either
restart the server with this database named on the command line, or restart
the server with a larger page size.
Probable cause The database server was not able to start on a db_start_engine call because it
was already running.
754
CHAPTER 10 Database Error Messages
Probable cause You exceeded the number of computers allowed to connect to the server. If
you are running the network database server, the limit is spelled out in your
license agreement. The server may be running low on cache such that it
cannot accept any more database connections. The personal database server
is restricted to 10 connections.
Probable cause The database server is not running, or the interface library is unable to find it.
755
Alphabetic list of error messages
Probable cause The database server was started for bulk loading (the -b switch) and cannot
be used as a network server. Stop the database server, and start again without
-b.
Probable cause Your attempt to upgrade a database failed. This could be caused by a failure
to locate one of the SQL script files used to define the system table changes.
756
CHAPTER 10 Database Error Messages
Probable cause An attempt to upgrade a database failed. The database is too old to be
upgraded.
Probable cause The SQLCA passed to a dblib entry point has not been initialized by a call to
db_init or the call to db_init failed.
757
Alphabetic list of error messages
Probable cause You tried to access a dbspace that the database server could not find.
Probable cause You tried to access a table in a dbspace that the database server could not
find. You may need to change the filename associated with the dbspace using
the ALTER DBSPACE statement.
758
CHAPTER 10 Database Error Messages
Deadlock detected
Item Value
SQLCODE -306
Constant SQLE_DEADLOCK
SQLSTATE 40001
Sybase error code 1205
ODBC 2 State 40001
ODBC 3 State 40001
Probable cause You attempted to read or write a row and it is locked by another user. Also,
the other user is blocked directly or indirectly on your own transaction. This
is a deadlock situation and your transaction has been chosen as the one to
rollback.
Probable cause The specified column of the derived table has no column name. Use a select
list alias in the query specification or use a derived columns specifier.
759
Alphabetic list of error messages
Probable cause The statement you are trying to execute contains extensions to ANSI 1992
Entry Level SQL. These extensions are not allowed by the current settings.
Probable cause Your hard disk is out of space. A ROLLBACK WORK statement has been
automatically executed.
760
CHAPTER 10 Database Error Messages
Division by zero
Item Value
SQLCODE -628
Constant SQLE_DIV_ZERO_ERROR
SQLSTATE 22012
Sybase error code 36007
ODBC 2 State 22012
ODBC 3 State 22012
Probable cause You tried to enlist a DTC transactions on a platform that does not support
this feature.
761
Alphabetic list of error messages
Probable cause You supplied a duplicate column name in the list of insert columns.
Probable cause You supplied a duplicate column name in the list of referencing columns.
762
CHAPTER 10 Database Error Messages
Error in assignment
Item Value
SQLCODE -641
Constant SQLE_ERROR_IN_ASSIGNMENT
SQLSTATE 22005
Sybase error code 8205
ODBC 2 State 22005
ODBC 3 State 22018
Probable cause In a GET DESCRIPTOR statement, the data type of the host variable must
correspond to the data type of the descriptor item.
763
Alphabetic list of error messages
Probable cause You supplied an invalid error number in a RAISERROR statement. The
number must be greater than or equal to 17000.
Probable cause You attempted to open a cursor on a statement that is not a SELECT
statement or a CALL or EXEC statement.
764
CHAPTER 10 Database Error Messages
Probable cause The connection string could not be parsed. The string or connection
parameter file contains a syntax error.
Probable cause The database server got an I/O error writing the transaction log file. Perhaps
the disk is full or the log file name is invalid.
765
Alphabetic list of error messages
Probable cause You have attempted to create an event with a name that already exists in
SYS.SYSEVENT.
Probable cause You have attempted to reference an event with a name that does not exist in
SYS.SYSEVENT.
766
CHAPTER 10 Database Error Messages
Probable cause Either an external function or Java method is declared to have a parameter or
result data type which is not supported, or a Java field reference with
unsupported result type was attempted.
Probable cause An external login for the server and user does not exist.
767
Alphabetic list of error messages
Probable cause You attempted to carry out an operation or use a feature that is not
implemented in this version of Adaptive Server Anywhere.
Probable cause You attempted to execute a statement or use a feature that is not supported in
an UltraLite database. For example, UltraLite does not support statements
that modify the schema of the database.
768
CHAPTER 10 Database Error Messages
Probable cause An attempt was made to store a SQL null value in a Java object field which
has a Java type that cannot be null. For example, the Java ’int’ type cannot be
null.
Probable cause You attempted to declare a cursor FOR UPDATE on a query that is not
updateable. Queries that contain DISTINCT, GROUP BY, HAVING, or
UNION, or that contain aggregate functions are read only. If the
ANSI_UPDATE_CONSTRAINTS option is on, then queries that contain an
join are read only. If the query references a view then the view may be non-
updateable.
769
Alphabetic list of error messages
Foreign key ’%1’ for table ’%2’ duplicates an existing foreign key
Item Value
SQLCODE -251
Constant SQLE_DUPLICATE_FOREIGN_KEY
SQLSTATE 52W06
Sybase error code 1909
ODBC 2 State 42000
ODBC 3 State 42000
Parameter 1 The role name of the new foreign key.
Parameter 2 The table containing the foreign key.
Probable cause You attempted to define a foreign key that already exists.
Probable cause You misspelled the name of a foreign key, or the foreign key does not exist.
770
CHAPTER 10 Database Error Messages
Probable cause You supplied an invalid argument number in the format string for a PRINT
or RAISERROR statement. The number must be between 1 and 20 and must
not exceed the number of arguments provided.
Probable cause You used a non-aggregate function or column reference in the select list that
does not appear in the GROUP BY clause. In a query using GROUP BY,
select list items that are not aggregate functions must also appear in the
GROUP BY clause. If the select list item is a column reference or an alias,
you may add the column name or alias to the GROUP BY clause. If the
select list item is a scalar function, ensure that the function’s arguments in the
GROUP BY clause match exactly with those in the select list. In some cases,
you may want to use the MAX function on the column name (or another
aggregate function) instead of adding the column to the GROUP BY clause.
771
Alphabetic list of error messages
Probable cause You have attempted to execute a batch which contains host variable
references. Host variables are not supported within a batch.
772
CHAPTER 10 Database Error Messages
Probable cause Adaptive Server Anywhere has detected a problem with your hard disk. A
ROLLBACK WORK statement has been automatically executed.
Probable cause The identity attribute of the column specified in the ’CREATE EXISTING’
statement differs from the identity attribute of the actual column.
773
Alphabetic list of error messages
Probable cause You attempted an illegal cursor operation. For example, you may be
attempting to OPEN a cursor for a statement that is neither a SELECT nor a
BATCH.
Probable cause You specified a user selectivity estimate that is either not a literal constant or
is outside the range 0.0 to 100.0 (estimates are specified as percentages). The
estimate has been ignored.
774
CHAPTER 10 Database Error Messages
Probable cause The last page in the transaction log was read by a call to db_backup. One or
more currently active connections have partially completed transactions,
preventing the transaction log file from being renamed. Reissue the
db_backup call.
Probable cause The store and server DLL versions do not match.
775
Alphabetic list of error messages
Probable cause You attempted to insert or update a row that has the same value as another
row in some column, and there is a constraint that does not allow two rows to
have the same value in that column.
Probable cause A statement has referred to an index name which is not unique. Preface the
index name by an owner name.
776
CHAPTER 10 Database Error Messages
Probable cause You attempted to create an index with the same name as an existing index.
777
Alphabetic list of error messages
Probable cause The range for valid parameters is from 1 up to the number of host variables
specified in the prepared/callable statement.
Probable cause You attempted to insert into a cursor and have specified values for more than
one table; or you attempted to delete from a cursor that involves a join. Insert
into one table at a time. For DELETE, use the FROM clause to specify
which table you wish to delete from.
778
CHAPTER 10 Database Error Messages
Probable cause The integrated login failed. You may not have a system account on the server
machine.
Probable cause The LOGIN_MODE database option is set to STANDARD logon type, and
you attempted an integrated login. Change the option setting or supply an
explicit user ID.
779
Alphabetic list of error messages
Probable cause The current database is an older database and does not have a sys.syslogin
table to map integrated login IDs to database user IDs. You must upgrade
your database to use integrated logins.
780
CHAPTER 10 Database Error Messages
Probable cause While processing a COMMIT or ROLLBACK, corruption was found in the
internal rollback log. This is a fatal internal error.
Probable cause You specified an offset in a FETCH that was invalid or NULL.
781
Alphabetic list of error messages
Probable cause A binary expression passed to the INSTALL JAVA statement was not a
valid Java class.
Probable cause You gave an invalid column number, or the column you are looking for is in
a different table.
Invalid comparison
Item Value
SQLCODE -710
Constant SQLE_INVALID_COMPARISON
SQLSTATE 52W25
Sybase error code 13749
ODBC 2 State 37000
ODBC 3 State 42000
Probable cause An attempt was made to compare two arguments that do not support
comparison. For example, it is not valid to compare a Java object with
another Java object, unless the class of the object supports a valid
compareTo() method.
782
CHAPTER 10 Database Error Messages
Probable cause The database could not convert a value to the required type. The value being
converted was either supplied to the database on an insert, update or as a host
bind variable, or was a value retrieved from the database into a host variable
or SQLDA.
783
Alphabetic list of error messages
Probable cause You attempted to create a database with an invalid page size. The page size
for an Adaptive Server Anywhere database must be either 1024, 2048, or
4096 bytes.
Probable cause It was not possible to start the database server because the command line was
invalid.
784
CHAPTER 10 Database Error Messages
Probable cause You have attempted to create a schedule with an invalid day-of-week name
or day-of-month number.
Probable cause The index number used with respect to a descriptor area is out of range.
785
Alphabetic list of error messages
Probable cause The escape character string length must be exactly one.
Probable cause A LIKE pattern contains an invalid use of the escape character. The escape
character may only precede the special characters ’%’, ’_’, ’[’, and the escape
character itself.
786
CHAPTER 10 Database Error Messages
Probable cause An expression in the WHERE clause of a query which uses Transact-SQL
syntax contains a comparison of a column from the null-supplying table with
a subquery or an expression which references a column from another table.
Probable cause You supplied an expression which the database server cannot understand.
For example, you may have tried to add two dates.
787
Alphabetic list of error messages
Probable cause You supplied an invalid host variable to the database using the C language
interface. You may have supplied the variable as a host variable or through a
SQLDA.
Probable cause An invalid command line option was used. The option began with ’-iq’, but is
either invalid or contained a bad parameter.
788
CHAPTER 10 Database Error Messages
Probable cause A file passed to the INSTALL JAVA statement was not a valid jar file.
Probable cause An invalid resultset concurrency was used when creating a JDBC statement.
789
Alphabetic list of error messages
Probable cause An invalid resultset type was used when creating a JDBC statement.
Probable cause An invalid join type was used with a query that contains Transact-SQL outer
join comparison operators.
Probable cause An invalid database switch was found in the DBS (DatabaseSwitches)
connection parameter.
790
CHAPTER 10 Database Error Messages
Probable cause An illegal attempt was made to access a closed JDBC object.
Probable cause An illegal attempt was made to access a closed native Java object.
791
Alphabetic list of error messages
Probable cause You may have misspelled the name of an option in the SET OPTION
statement. You can only define an option for a user if the database
administrator has supplied a PUBLIC value for that option.
Invalid parameter
Item Value
SQLCODE -735
Constant SQLE_INVALID_PARAMETER
SQLSTATE 08W24
Sybase error code 5864
ODBC 2 State 08004
ODBC 3 State 08004
792
CHAPTER 10 Database Error Messages
Probable cause You supplied an invalid REFERENCES clause in a trigger definition. You
may have specified an OLD correlation name in a BEFORE INSERT trigger,
or a NEW correlation name in an AFTER DELETE trigger. In both cases,
the values do not exist and cannot be referenced.
793
Alphabetic list of error messages
Probable cause You attempted to scroll to a position that is not supported. Scroll positions
must be between -2147483647 and 2147483646.
Probable cause You supplied an invalid value for an option in the SET statement. Some
options only allow numeric values, while other options only allow the values
"on" and "off".
794
CHAPTER 10 Database Error Messages
Probable cause You attempted to deallocate a descriptor that has not been allocated.
Probable cause An invalid identifier was supplied through the C language interface. For
example, you may have supplied a NULL string for a cursor name.
795
Alphabetic list of error messages
Probable cause You have specified an event starting date or time which has already passed.
Invalid statement
Item Value
SQLCODE -130
Constant SQLE_INVALID_STATEMENT
SQLSTATE 07W02
Sybase error code 13628
ODBC 2 State ERROR
ODBC 3 State ERROR
Probable cause The statement identifier generated by a PREPARE passed to the database for
a further operation is invalid.
796
CHAPTER 10 Database Error Messages
Probable cause You supplied an invalid value as the TEXTPTR for a WRITETEXT or
READTEXT statement.
Probable cause You have attempted to create a schedule with an invalid start or stop time.
797
Alphabetic list of error messages
Probable cause A Java type specified on a DESCRIBE statement has no corresponding SQL
type.
798
CHAPTER 10 Database Error Messages
799
Alphabetic list of error messages
Probable cause You specified an invalid user ID or password when a module was
preprocessed.
Probable cause You attempted an insert or update that violates a CHECK constraint. A
CHECK constraint is violated if it evaluates to FALSE; it is deemed to hold
if the condition evaluates to TRUE or UNKNOWN.
Probable cause You attempted to create a file, table, view, column, foreign key, or
publication with the same name as an existing one.
800
CHAPTER 10 Database Error Messages
Probable cause The jar with this name does not exist in SYSJAR.
Probable cause The Java class with this name does not exist in SYSJAVACLASS.
801
Alphabetic list of error messages
Probable cause A problem was encountered starting the Java virtual machine. Possible
problems include not enough memory, or incomplete installation of the Java
runtime support classes.
Probable cause The amount of space allocated for the Java VM is insufficient to continue
allocating new objects. Increase the size by using: set option
public.java_heap_size = nnnnnnnn
802
CHAPTER 10 Database Error Messages
Probable cause An attempt was made to use a feature of JDBC that is not supported.
Probable cause An error occurred when executing a statement in the batch. The rest of the
statements in the batch will be abandoned.
803
Alphabetic list of error messages
Probable cause You reference a label in a LEAVE statement, but the label could not be
found.
Language extension
Item Value
SQLCODE -135
Constant SQLE_LANGUAGE_EXTENSION
SQLSTATE 0AW01
Sybase error code 401
ODBC 2 State 37000
ODBC 3 State ERROR
Probable cause You used a SQL statement that may be valid in some versions of SQL, but
not in Adaptive Server Anywhere.
804
CHAPTER 10 Database Error Messages
Probable cause The statement you are executing contains extensions to ANSI 1992 Entry
level SQL.
Probable cause The UltraLite runtime has received an unexpected error from the system calls
being used to store the UltraLite database. For example, a write to persistent
memory failed. This is an internal error and indicates faulty or corrupt
persistent storage on the device. A ROLLBACK WORK statement has been
automatically executed.
805
Alphabetic list of error messages
Probable cause The method cannot be called at this time. Check that the method is not being
called out of order.
Probable cause A call to an external entry point in a dynamically loaded module was
qualified by an operating system which was not the operating system on
which the server is currently executing.
806
CHAPTER 10 Database Error Messages
Probable cause You attempted an update operation on a database that was declared as read-
only.
More columns are being dropped from table %1 than are defined
Item Value
SQLCODE -124
Constant SQLE_TOO_MANY_COLUMNS_DELETED
SQLSTATE 42W44
Sybase error code 207
ODBC 2 State 37000
ODBC 3 State 42000
Probable cause The number of columns in a table can never fall below one. Your ALTER
TABLE has more drop/delete column clauses than the current number of
columns in the table.
807
Alphabetic list of error messages
Probable cause More information is required to complete the request. This is used internally
in the database interface library to process a unified logon. It should not be
returned to an application.
Probable cause You identified two tables in the same FROM clause with the same
correlation name.
808
CHAPTER 10 Database Error Messages
Probable cause The primary key of the table must be included in the synchronization entry.
Probable cause The amount of space allocated for the Java Namespace is insufficient to
continue loading Java classes etc. Increase the size by using: set option
public.java_namespace_size = nnnnnnnn
809
Alphabetic list of error messages
Probable cause You must provide a library name specifier in the name of the external
function to call.
Probable cause You attempted to perform an operation on the current row of a cursor, but the
cursor is not positioned on a row. The cursor is before the first row of the
cursor, after the last row, or is on a row that has since been deleted.
810
CHAPTER 10 Database Error Messages
Probable cause The database server was started but there was no specified database file. The
server is stopped.
Probable cause You tried to retrieve a value from the database that was NULL, but you did
not provide an indicator variable for that value.
811
Alphabetic list of error messages
Probable cause You attempted to insert or update a row that has a foreign key for another
table. The value for the foreign key is not NULL and there is not a
corresponding value in the primary key
Probable cause You attempted a data definition language operation that cannot be completed
while another user is connected.
812
CHAPTER 10 Database Error Messages
Probable cause You are not connected to a database, or you executed the DISCONNECT
statement and have not connected to a database again.
Probable cause There are not enough fields in the SQLDA to retrieve all of the values
requested.
813
Alphabetic list of error messages
Probable cause The Java heap size and Java name space configuration values in sysoptions
must be increased to allow the loading of the Java classes used for remote
access.
Probable cause The database server was started but was unable to start because there is not
enough memory to run properly.
814
CHAPTER 10 Database Error Messages
Probable cause You have not provided enough host variables for either the number of bind
variables, or the statement, or the number of select list items.
Probable cause The null attribute of the column specified in the ’CREATE EXISTING’
statement differs from the null attribute of the actual column.
815
Alphabetic list of error messages
Probable cause The expression argument of the aggregate function evaluated to NULL for
one or more rows.
Probable cause You used an integer in an ORDER BY list and the integer is larger than the
number of columns in the select list.
816
CHAPTER 10 Database Error Messages
Probable cause You attempted to create or modify a table definition such that the number of
columns that allow nulls is now more than the limit on such columns. The
limit is a function of database page size and is approximately 8*(page_size -
30).
Number of columns defined for the view does not match SELECT
statement
Item Value
SQLCODE -114
Constant SQLE_VIEW_DEFINITION_ERROR
SQLSTATE 53011
Sybase error code 4409
ODBC 2 State 21S02
ODBC 3 State 21S02
Probable cause You attempted to create a view, but the column list specified as part of the
CREATE VIEW statement does not correspond to the list of items in the
view’s SELECT statement.
817
Alphabetic list of error messages
Probable cause OMNI encountered a complicated expression involving remote tables inside
a stored procedure. OMNI cannot always deal with such expressions.
Probable cause The option specified in the SET OPTION statement is PUBLIC only. You
cannot define this option for any other user.
818
CHAPTER 10 Database Error Messages
Probable cause The option specified in the SET OPTION statement can only be set by a user
having DBA authority.
Probable cause You attempted to add a member to group that would result in a member
belonging to itself. The membership may be direct or indirect.
819
Alphabetic list of error messages
Probable cause You supplied a procedure parameter name that does not match a parameter
for this procedure. Check the spelling of the parameter name.
Probable cause Positional arguments were specified after keyword arguments in a call to this
procedure.
820
CHAPTER 10 Database Error Messages
Probable cause The parameter must be registered as an output parameter before the value of
the parameter can be obtained.
Probable cause An invalid data source name was used in the connection string.
821
Alphabetic list of error messages
Probable cause Passthrough is additive, in that subsequent passthrough statements add to the
list of users receiving passthrough. The passthrough statements must all be
PASSTHROUGH ONLY or none should be PASSTHROUGH ONLY.
Probable cause The password is shorter than that allowed by the current
MIN_PASSWORD_LENGTH option setting. :EN-
822
CHAPTER 10 Database Error Messages
Probable cause You listed the same column name twice in the definition of a primary key.
Probable cause You attempted to delete or modify a row whose primary key value is
referenced elsewhere in the database.
823
Alphabetic list of error messages
Probable cause You attempted to add a new row to a table, but the new row has the same
primary key as an existing row. The database has not added the incorrect row
to the database. For example, you might have added a student with student
number 86004 and there is already a row for a student with that number.
Probable cause You misspelled the name of a procedure, or you did not qualify a procedure
name with a user name.
824
CHAPTER 10 Database Error Messages
Probable cause A Java procedure terminated with an active exception, and this exception is
reflected in SQL as an error status.
Probable cause There are no more result sets available for this procedure. An OPEN or a
RESUME statement may have caused the procedure to execute to
completion. You may have attempted to RESUME a cursor on a SELECT
statement.
825
Alphabetic list of error messages
Procedure in use
Item Value
SQLCODE -215
Constant SQLE_PROCEDURE_IN_USE
SQLSTATE 42W23
Sybase error code 3702
ODBC 2 State 40001
ODBC 3 State 40001
Probable cause You attempted to DROP a procedure that is being used by other active users
of the database.
Probable cause You may have defined a procedure or trigger that causes unlimited recursion.
826
CHAPTER 10 Database Error Messages
Probable cause You misspelled the name of a publication, or you did not qualify a
publication name with a user name.
RAISERROR executed: %1
Item Value
SQLCODE -631
Constant SQLE_RAISERROR_STMT
SQLSTATE WW012
Sybase error code 0
ODBC 2 State ERROR
ODBC 3 State ERROR
Parameter 1 RAISERROR message string
827
Alphabetic list of error messages
Probable cause You referred to a remote message type that is not defined in this database.
Use CREATE REMOTE TYPE to define remote message types.
828
CHAPTER 10 Database Error Messages
Probable cause You attempted to define an object on a server that has not been added. Use
CREATE SERVER to add the remote server definition.
Probable cause You attempted to perform an update on an object located on a server that is
configured as read only. Use ALTER SERVER to reconfigure the remote
server to be updatable.
829
Alphabetic list of error messages
Remote server does not have the ability to support this statement
Item Value
SQLCODE -706
Constant SQLE_OMNI_SERVER_NOT_CAPABLE
SQLSTATE WO012
Sybase error code 11227
ODBC 2 State ERROR
ODBC 3 State ERROR
Probable cause You attempted to execute a statement that requires a capability that is not
supported by a remote server.
Probable cause This SQLSTATE can be signaled within a trigger to prevent DBREMOTE
from displaying an error message in the output. This exception will only
occur when a trigger or procedure SIGNALS it. This is useful for ignoring
replication errors that are permitted by design.
830
CHAPTER 10 Database Error Messages
Probable cause The server has denied your request as there are currently no running
databases.
Probable cause You do not have permission to start or stop a database. The required
permission is determined on the server command line.
831
Alphabetic list of error messages
Probable cause The resource governor for the stated resource has determined that the usage
of the resource has exceeded its limit.
Probable cause RESTORE was unable to open one of the database files.
832
CHAPTER 10 Database Error Messages
Probable cause After a RESTORE, the resulting database could not be started.
Probable cause RESTORE was unable to write to one of the database files.
833
Alphabetic list of error messages
Probable cause You used a SELECT statement with no INTO clause or a RESULT
CURSOR statement within an atomic compound statement.
Probable cause The Java type void does not map onto any SQL type, hence a procedure
returning void cannot be used in any SQL expression.
834
CHAPTER 10 Database Error Messages
Probable cause Setting a value for the return parameter of a callable statement is not
allowed.
Probable cause Non-space characters were truncated upon the assignment of string data.
835
Alphabetic list of error messages
Probable cause One of the cursors that was opened with prefetch enabled was performing
fetch operations, and a deadlock occurred during a prefetch. This is a
deadlock situation and your transaction has been chosen as the one to
rollback.
Probable cause You fetched a row from a SCROLL cursor. The row was previously fetched
from the same cursor, and one or more columns in the row has been updated
since the previous fetch. The column(s) updated may or may not be fetched
by the cursor; this warning just indicates that the row from the table has been
updated. If the cursor involves more than one table, a row from one or more
of the tables has been updated.
836
CHAPTER 10 Database Error Messages
Probable cause You positioned a cursor beyond the beginning or past the end of the query.
There is no row at that position.
837
Alphabetic list of error messages
Probable cause You attempted to rollback to a savepoint that does not exist.
838
CHAPTER 10 Database Error Messages
Probable cause You cannot use savepoints when the database server is running in bulk mode
without a rollback log.
Probable cause You have attempted to create a schedule with a name that already exists in
SYS.SYSSCHEDULE for the named event.
839
Alphabetic list of error messages
Probable cause You have attempted to reference a schedule with a name that does not exist
in SYS.SYSSCHEDULE for the named event.
Probable cause There is no row zero on JDBC resultSets. The valid row numbers are 1, 2, ...,
-2, -1.
840
CHAPTER 10 Database Error Messages
Probable cause You specified a UNION but the SELECT statements involved in the union
do not have the same number of columns in the select list.
Probable cause You tried to use a SELECT statement without a cursor, but the statement
cursor returns more than one row. Only a single row SELECT statement can
be used in this context.
841
Alphabetic list of error messages
Server %1: %2
Item Value
SQLCODE -660
Constant SQLE_OMNI_REMOTE_ERROR
SQLSTATE WO005
Sybase error code 13732
ODBC 2 State ERROR
ODBC 3 State ERROR
Parameter 1 The name of the remote server.
Parameter 2 The message from the remote server.
Probable cause A message was generated by a remote server. The message text is included."
Probable cause An ALTER SERVER statement was attempted on a capability that was not
defined.
842
CHAPTER 10 Database Error Messages
Probable cause Could not connect to a server, and was unable to autostart a server. Autostart
may have failed because no database file was supplied.
Probable cause The number of types in the signature must match the number of procedure
parameters. If a ’dynamic result sets’ clause was specified, the number of
dynamic result sets must match the quantity found in the signature.
843
Alphabetic list of error messages
Probable cause The database server could not start the specified database because the file is
already in use.
Probable cause The database file you specified is invalid. The database server is stopped.
844
CHAPTER 10 Database Error Messages
Probable cause The database server was started but was unable to find the specified
database. The database server may be attempting to start a database file that
cannot be opened or that cannot be found on the network. You may be
attempting to connect to a database name that is not running. The database
server is stopped.
Probable cause The statement identifier (generated by PREPARE) passed to the database for
a further operation is invalid.
Probable cause The data type specified for a SQLDA variable is invalid.
845
Alphabetic list of error messages
Probable cause Not all of the rows in a multi-rows SQLDA have been defined identically for
an array operation (insert, fetch, or execute). A given column must be
defined the same (type and length) in each row.
Probable cause Your executable has source files with Embedded SQL that were
preprocessed with a preprocessor that does not match the database interface
library.
846
CHAPTER 10 Database Error Messages
Probable cause The LOGIN_MODE database option is set to integrated login type, and you
attempted a standard logon. Change the option setting or use an integrated
login.
Probable cause You specified a statement for the PREPARE..WITH EXECUTE statement
that cannot be executed. If you specified an output SQLDA, it may contain a
DESCRIBE of the prepared statement.
847
Alphabetic list of error messages
Probable cause You canceled a statement during its execution. The database was able to stop
the operation without doing a rollback. If the statement is INSERT,
UPDATE, or DELETE, any changes made by the statement will be canceled.
If the statement is a data definition statement (for example CREATE
TABLE), the statement will be canceled, but the COMMIT that was done as
a side effect will not be canceled.
Probable cause You tried to execute a statement that cannot be executed while in
passthrough mode. For example, you may have executed a batch statement.
848
CHAPTER 10 Database Error Messages
Probable cause FIRST or TOP n are used in a SELECT statement to limit the size of a result.
The size limit ’n’ must be a constant integer greater than 0 and less than
32767.
Probable cause You entered a subquery which has more than one column in the select list.
Change the select list to have only one column.
849
Alphabetic list of error messages
Probable cause You used a subquery that returns more than one row, in a context where only
a single row can be used. If the subquery is in the WHERE clause, you might
be able to use the IN keyword.
850
CHAPTER 10 Database Error Messages
Probable cause You attempted to drop, start, or synchronize a subscription that does not
exist.
Probable cause You referred to a synchronization message type that is not defined in this
database.
851
Alphabetic list of error messages
Probable cause You attempted to set a synchronization option with an invalid value.
852
CHAPTER 10 Database Error Messages
Probable cause Synchronization option list cannot be longer than database page size.
Probable cause You attempted to synchronize an UltraLite database and during the
synchronization session, a complete upload stream was sent that could not be
commited to the consolidated database. The reason for the upload failure can
be found in the synchronization log file.
853
Alphabetic list of error messages
Probable cause You attempted to create a synchronization site with a non-unique site name.
Probable cause The database server cannot understand the statement you are trying to
execute. If you used a keyword (such as DATE) for a column name, try
enclosing the keyword in quotation marks ("DATE").
854
CHAPTER 10 Database Error Messages
Probable cause The database server cannot understand the statement you are trying to
execute. If you used a keyword (such as DATE) for a column name, try
enclosing the keyword in quotation marks ("DATE").
Probable cause You have attempted to create an event with a system event type name that
does not exist in SYS.SYSEVENTTYPE.
855
Alphabetic list of error messages
Probable cause The table could not be renamed as it has a foreign key with a referential
action. To rename the table, first drop the foreign key constraints.
856
CHAPTER 10 Database Error Messages
Probable cause You attempted to add a foreign key referring to a table that does not have a
primary key. You must add a primary key to the referenced table.
Probable cause You attempted to drop a table that has publications defined.
857
Alphabetic list of error messages
Probable cause You specified outer joins that create a cycle of tables.
858
CHAPTER 10 Database Error Messages
Probable cause You misspelled the name of a table, or you did not qualify a table name with
a user name. For example, you might have referred to employee instead of
"DBA".employee,
Probable cause You specified a join that joins a table to itself. You need to use unique
correlation names in order to have multiple instances of a table.
859
Alphabetic list of error messages
Probable cause You attempted to add a primary key on a table that already has a primary key
defined. You must delete the current primary key before adding a new one.
Probable cause You specified the primary key twice in a CREATE TABLE statement.
Table in use
Item Value
SQLCODE -214
Constant SQLE_TABLE_IN_USE
SQLSTATE 42W21
Sybase error code 3702
ODBC 2 State 40001
ODBC 3 State 40001
860
CHAPTER 10 Database Error Messages
Probable cause You attempted to ALTER or DROP a table that is being used by other active
users of the database.
Probable cause You attempted to modify a table, and the database server can only perform
the change if there are no rows in the table.
Probable cause You canceled a statement while the database was executing. A ROLLBACK
WORK statement has been automatically executed.
861
Alphabetic list of error messages
Probable cause The column specified in the ’CREATE EXISTING’ statement does not exist
in the remote table.
Probable cause An attempt was made to parse a connection string containing a connection
profile but the connection parameters file could not be found.
862
CHAPTER 10 Database Error Messages
Probable cause You attempted to declare a cursor with a name that already exists. Cursor
names must be unique within a connection.
Probable cause The column is defined with a data type that is not supported for remote
tables.
863
Alphabetic list of error messages
The data type specified for column ’%1’ is not compatible with the
actual data type
Item Value
SQLCODE -721
Constant SQLE_OMNI_DATATYPE_MISMATCH
SQLSTATE WO015
Sybase error code 11209
ODBC 2 State ERROR
ODBC 3 State ERROR
Parameter 1 The name of the column.
Probable cause The data type of the column specified in the ’CREATE EXISTING’
statement is not compatible with the actual data type of the column in the
remote table.
Probable cause The Java virtual machine could not be started because the database does not
have the proper support. It may be that the database was created with an
older version of the software, or was created with the Java support disabled.
If the database was created with an older version of the software the database
should be upgraded to the most recent version. If the database was created
with Java support disabled, then the instjava.sql script should be run against
the database to enable java support.
864
CHAPTER 10 Database Error Messages
Probable cause You attempted to call an external function. An attempt to load the attempted
library failed because of incompatibility with the server. Incompatibility may
arise because the dynamic library is using an external function api that is
either not supported by the server or is newer than the one supported by the
server.
Probable cause You attempted to map the guest login ID to something other than guest
865
Alphabetic list of error messages
Probable cause Resultset functions such as ’insertRow’ can only be called when the resultset
is positioned on the insert row.
The length specified for column ’%1’ is different than the actual
length
Item Value
SQLCODE -723
Constant SQLE_OMNI_LENGTH_MISMATCH
SQLSTATE WO017
Sybase error code 11210
ODBC 2 State OK
ODBC 3 State OK
Parameter 1 The name of the column.
Probable cause The length of the column specified in the ’CREATE EXISTING’ statement is
different than the length of the column in the remote table.
866
CHAPTER 10 Database Error Messages
The login ID ’%1’ has not been mapped to any database user ID
Item Value
SQLCODE -313
Constant SQLE_INTEGRATED_LOGON_UNMAPPED
SQLSTATE 28W09
Sybase error code 13698
ODBC 2 State 28000
ODBC 3 State 28000
Probable cause You attempted to drop a login ID that had not been mapped yet
867
Alphabetic list of error messages
Probable cause The database server was unable to construct a valid access plan for the given
request. This is an Adaptive Server Anywhere internal error. If it can be
reproduced, it should be reported by Sybase. You may be able to work
around this problem by modifying the query statement.
Probable cause The option specified in the SET OPTION statement can only be set as a
temporary option.
Probable cause The option specified in the SET OPTION statement can only be set as a
temporary option.
868
CHAPTER 10 Database Error Messages
Probable cause The pattern for the LIKE operator is too long. All patterns of 126 characters
or less are supported. Some patterns as long as 254 characters are supported,
depending on their contents. Patterns longer than 254 characters are not
supported.
Probable cause Auto-incrementing data types can only be supported in a proxy table when
the backend server supports this feature.
869
Alphabetic list of error messages
Probable cause The table could not be found on the remote server. Check the remote table
name and the user privileges on that table.
The Select list for the derived table ’%1’ has no expression to
match %2
Item Value
SQLCODE -812
Constant SQLE_NO_MATCHING_SELECT_ITEM
SQLSTATE 42W59
Sybase error code 13822
ODBC 2 State 37000
ODBC 3 State 42000
Parameter 1 Name of the derived table.
Parameter 2 Name of the alias for which there is no matching
expression.
Probable cause The specified alias from the derived table’s AS clause has no matching
expression from the Select statement for that derived table. Ensure that each
Select list item has a matching alias in the derived table’s AS clause, and
vice-versa.
870
CHAPTER 10 Database Error Messages
Probable cause The selected database is in an inactive state. The database may be in the
process of being started or of being shut down.
Probable cause The database attempted to access a page whose page number is beyond the
maximum possible number of disk pages. This is a fatal internal error.
871
Alphabetic list of error messages
Probable cause You attempted to create a foreign key that can not be enforced. In order to
enforceable, the primary and foreign table for the specified key must exist on
the same server. You can use the ’unenforced’ keyword to create a foreign
key specification that is not to be enforced.
872
CHAPTER 10 Database Error Messages
Probable cause The streams environment could not be created. Either there are insufficient
resources to create the environment or the language resource file cannot be
found.
The table specification ’%1’ identifies more than one remote table
Item Value
SQLCODE -726
Constant SQLE_OMNI_RMT_TABLE_NOTUNIQUE
SQLSTATE WO020
Sybase error code 11215
ODBC 2 State ERROR
ODBC 3 State ERROR
Parameter 1 The complete name of the remote table
Probable cause More than one table was found on the remote server for the given table
specification. Add a database or owner name to the specification.
873
Alphabetic list of error messages
Probable cause You attempted to shut down a database which still has active connections.
Probable cause You attempted to CREATE a variable with the name of another variable that
already exists.
874
CHAPTER 10 Database Error Messages
Probable cause You are attempting to KEY JOIN two tables, and there are two or more
foreign keys relating the two tables. There may be two foreign keys from the
first table to the second table It may be that each table has a foreign key to
the other table. You must use a correlation name for the primary key table
which is the same as the role name of the desired foreign key relationship.
Probable cause You may have attempted a KEY JOIN between two tables and there is no
foreign key on one of the tables that references the primary key of the other
table. You may have attempted a NATURAL JOIN between two tables that
have no common column names.
875
Alphabetic list of error messages
Probable cause You executed a CREATE TABLE or ALTER TABLE statement, which
attempted to add a column to a table. The resulting number of columns in the
table would exceed the limit for the current database page size.
Probable cause There is a maximum of 256 parameters to an external function call in 32-bit
Windows.
876
CHAPTER 10 Database Error Messages
Probable cause You attempted to use a Transact-SQL feature that is not supported in
Adaptive Server Anywhere.
877
Alphabetic list of error messages
Probable cause An operation was being performed on the transaction log such as SQL
Remote or Replication Agent processing and the transaction log was
truncated by an independent backup during that operation.
878
CHAPTER 10 Database Error Messages
Probable cause You misspelled the name of a trigger, or you did not qualify a trigger name
with a user name.
Probable cause You attempted to create a trigger, but a trigger with the same name already
exists.
879
Alphabetic list of error messages
Probable cause You attempted to call a stored procedure or have modified a row in a table on
which a trigger is defined and you are using the runtime server. Triggers and
stored procedures are not supported in the runtime server. You must be
running the full server to use these features.
Probable cause You attempted to use TRUNCATE TABLE on a view. The TRUNCATE
TABLE statement deletes every row from a table and cannot be used to
delete rows from a view. Replace the view reference with the name of a base
table.
880
CHAPTER 10 Database Error Messages
Probable cause You attempted to connect to a remote server. Check that the remote server is
running.
Probable cause You attempted to delete a database file, but it could not be deleted. The
filename should not be the same as any database file that is currently in use.
881
Alphabetic list of error messages
Probable cause You tried to enlist a transaction but DTC does not seem to be available at this
time.
882
CHAPTER 10 Database Error Messages
Probable cause The server was unable to open the backup log to record the execution of a
BACKUP or RESTORE statement. Check the settings of the environment
variables used to locate the backup log file. The directory to contain the log
must already exist.
Probable cause You tried to recover a transaction but DTC does not seem to be available at
this time.
883
Alphabetic list of error messages
Probable cause It was not possible to start the database server. There may not be enough
memory to run the database server. It may be that the executable cannot be
found.
Probable cause The database server was started but was unable to find the specified
database. No specific reason is known.
884
CHAPTER 10 Database Error Messages
Probable cause You attempted to define a remote synchronization site using an undefined
synchronization template.
Probable cause You specified an invalid backup statement operation in a call to db_backup.
885
Alphabetic list of error messages
Probable cause You misspelled the name of a database function (such as MAXIMUM
instead of MAX) in a query definition or in a query column name.
Probable cause UNLOAD TABLE was specified with the name of a view. UNLOAD
TABLE may only be used to unload tables.
886
CHAPTER 10 Database Error Messages
Probable cause The character set that the application requested is not supported by the server
to which the application was attempting a connection.
Probable cause The character set that the application requested is not supported by the server
to which the application is connecting. The language that the application
requested is not supported either. Language strings will be sent in the
language specified.
887
Alphabetic list of error messages
Probable cause The language that the application requested is not supported by the server to
which the application is connecting. Language strings will be sent in the
language specified.
Unterminated C string
Item Value
SQLCODE -634
Constant SQLE_UNTERMINATED_C_STR
SQLSTATE 22024
Sybase error code 13682
ODBC 2 State 22024
ODBC 3 State 22024
Probable cause The least significant character of a C string host variable must contain the
null character.
888
CHAPTER 10 Database Error Messages
Probable cause You attempted an update operation on a cursor that was explicitly declared
as read-only.
Probable cause You attempted an insert, update, or delete operation on a query that is
implicitly read-only. Queries that contain DISTINCT, GROUP BY,
HAVING, or UNION, or that contain aggregate functions, or that involve a
join, are implicitly read only. If the query references a view then the view
may be non-updatable.
889
Alphabetic list of error messages
Probable cause You attempted an update, or delete operation on a remote table that is
currently not implemented. Examples of such operations include positioned
updates and updates that require building of work tables.
Probable cause You attempted to give a user GRANT OPTION and that user already has
GRANT OPTION.
890
CHAPTER 10 Database Error Messages
Probable cause You attempted to give a membership in a group to a user that already has
such membership.
Probable cause You attempted to read or write a row and it is locked by another user, while
the BLOCKING database option is set to OFF.
891
Alphabetic list of error messages
Probable cause You attempted to GRANT PUBLISH to a user ID, when a publisher already
exists.
892
CHAPTER 10 Database Error Messages
Probable cause You attempted to add a member to group, but the user ID specified as a
group has not been granted the GROUP special privilege.
893
Alphabetic list of error messages
Probable cause The message with this error number already exists in the
SYSUSERMESSAGES system table.
Probable cause The message with this error number does not exist in
SYSUSERMESSAGES.
894
CHAPTER 10 Database Error Messages
Probable cause You attempted to REVOKE CONNECT from a user that owns a procedure
being used by other active users of the database.
Probable cause You attempted to REVOKE CONNECT from a user that owns a table being
used by other active users of the database.
895
Alphabetic list of error messages
Probable cause A stored procedure or trigger signaled a user-defined exception. This error
state is reserved for use within stored procedures or triggers which contain
exception handlers, as a way of signaling an exception which can be
guaranteed to not have been caused by the database server. Valid
SQLSTATE values range from 99000 to 99999 and are set by the user when
executing the signal SQL statement.
Probable cause The user-defined type with this name does not exist in SYSUSERTYPE.
896
CHAPTER 10 Database Error Messages
Probable cause A temporary table has been created in order to satisfy the query. It can only
occur on an OPEN statement.
Probable cause The VALIDATE TABLE statement must refer to a local base table; it cannot
refer to a view, an IQ table, or an object on a remote server.
897
Alphabetic list of error messages
Probable cause You supplied to or fetched from the database a value that is out of range for
the destination column or host variable. For example, the value 10 may have
been supplied for a DECIMAL(3,2) field.
Probable cause A replicated UPDATE has found a value in an updated column that does not
match the value when the original UPDATE was made.
898
CHAPTER 10 Database Error Messages
Value truncated
Item Value
SQLCODE 101
Constant SQLE_TRUNCATED
SQLSTATE 01004
Sybase error code 7337
ODBC 2 State 01004
ODBC 3 State 01004
Probable cause You may have tried to insert, update, or select a value in the database that is
too large to fit in the destination. You may have fetched data into a host
variable or SQLDA variable not large enough to receive the value.
Probable cause You attempted to DROP or SET the value of a SQL variable that was not
created or was previously dropped.
899
Alphabetic list of error messages
Probable cause Views must refer only to permanent objects, not to temporary objects such as
local temporary tables.
Warning
Item Value
SQLCODE 200
Constant SQLE_WARNING
SQLSTATE 01000
Sybase error code 13619
ODBC 2 State OK
ODBC 3 State OK
Probable cause A warning has occurred. The message indicates the condition that caused the
warning.
900
CHAPTER 10 Database Error Messages
Probable cause You attempted an insert or update operation on the indicated base table
through a view (possibly nested). However, one or more values in the
modified row(s) triggered a WITH CHECK OPTION violation. This
violation occurs when a modified value causes one or more rows to fall
outside the range of the view by making the view’s WHERE clause evaluate
to FALSE or UNKNOWN for that row.
901
Alphabetic list of error messages
Probable cause The number of values you are trying to insert does not match the number of
columns specified in the INSERT statement, or the number of columns in the
table if no columns are specified.
Probable cause You specified a number of variables in a FETCH statement that does not
match the number of select list items.
902
CHAPTER 10 Database Error Messages
Probable cause You attempted to synchronize an UltraLite database and there are changes in
the UltraLite database that have not been committed.
903
Internal errors (assertion failed)
904
C H A P T E R 1 1
About this chapter This chapter presents a list of all SQL preprocessor errors and warnings.
Contents
Topic Page
SQL Preprocessor error messages indexed by error message value 906
SQLPP errors 910
905
SQL Preprocessor error messages indexed by error message value
906
Chapter 11 SQL Preprocessor Error Messages
907
SQL Preprocessor error messages indexed by error message value
908
Chapter 11 SQL Preprocessor Error Messages
909
SQLPP errors
SQLPP errors
This section lists messages generated by the SQL preprocessor. The
messages may be errors or warnings, or either depending on which
command-line options are set.
$ For more information about the SQL Preprocessor and its command-
line options, see "The SQL preprocessor" on page 79 of the book ASA
Programming Interfaces Guide.
Probable cause A C string was required in an embedded SQL statement (for a cursor name,
option name etc.) and the value supplied was not a C string.
Probable cause You have used a host variable that is not of integer type in a statement where
only an integer type host variable is allowed.
910
Chapter 11 SQL Preprocessor Error Messages
Probable cause The specified include file was not found. Note that the preprocessor will use
the INCLUDE environment variable to search for include files.
Probable cause You have used the DECL_FIXCHAR macro to declare a host variable of
type FIXCHAR but have not specified a length.
911
SQLPP errors
Probable cause A preprocessor macro has been defined twice, possibly in a header file.
912
Chapter 11 SQL Preprocessor Error Messages
Probable cause You declared a host variable of a type not understood by the SQL
preprocessor.
Probable cause You have attempted to declare a host variable as a pointer to a VARCHAR
or BINARY. This is not a legal host variable type.
Probable cause You have attempted to declare a VARCHAR or BINARY host variable using
the DECL_VARCHAR or DECL_BINARY macro but have not specified a
size for the array.
Probable cause You have attempted to declare a host variable as an array of FIXCHAR
arrays. This is not a legal host variable type.
913
SQLPP errors
Probable cause You have attempted to declare a host variable as an array of VARCHAR or
BINARY. This is not a legal host variable type.
Probable cause You have attempted to declare a host variable as an array of DECIMAL. A
decimal array is not a legal host variable type.
Probable cause You have attempted to declare a host variable array of a type that is not
supported.
914
Chapter 11 SQL Preprocessor Error Messages
Probable cause You have used an array of pointers as a host variable. This is not legal.
Probable cause An embedded SQL cursor name has been used (in a FETCH, OPEN, CLOSE
etc.) without first being declared.
Probable cause The variable used in the SET DESCRIPTOR statement hasn’t been declared
as a host variable.
915
SQLPP errors
Probable cause The same keyword has been used more than once inside a single SET
DESCRIPTOR statement.
Probable cause The same host variable name was defined with two different types within the
same module. Note that host variable names are global to a C module.
Probable cause You have used a host variable in a statement and that host variable has not
been declared in a declare section.
916
Chapter 11 SQL Preprocessor Error Messages
Probable cause Host variables are not allowed on the declare statement for the specified
cursor. If the cursor name is provided through a host variable, then you
should use full dynamic SQL and prepare the statement. A prepared
statement may have host variables in it.
Probable cause You have specified host variables for a cursor on both the declare and the
open statements. In the static case, you should specify the host variables on
the declare statement. In the dynamic case, specify them on the open.
Probable cause An embedded SQL specific statement (OPEN, DECLARE, FETCH etc.) has
a syntax error.
917
SQLPP errors
Probable cause You have used a indicator variable in a statement and that indicator variable
has not been declared in a declare section.
Probable cause You can not specify a C variable initializer for a host variable of type
VARCHAR or BINARY. You must initialize this variable in regular C
executable code.
918
Chapter 11 SQL Preprocessor Error Messages
Probable cause You have used a host variable that is not a string type in a place where the
preprocessor was expecting a host variable of a string type.
invalid integer
Message value Message Type
2614 Error
Probable cause An integer was required in an embedded SQL statement (for a fetch offset, or
a host variable array index, etc.) and the preprocessor was unable to convert
what was supplied into an integer.
Probable cause Indicator variables must be of type short int. You have used a variable of a
different type as an indicator variable.
919
SQLPP errors
Probable cause You have specified a string constant in an embedded SQL statement, but
there is no ending quote before the end of line or end of file.
Probable cause The specified statement requires host variables to be specified either in a host
variable list or from an SQLDA.
920
Chapter 11 SQL Preprocessor Error Messages
Probable cause You specified an embedded static SELECT statement but you did not specify
an INTO clause for the results.
Probable cause A cursor is declared, and possibly used, but is never opened.
Probable cause The EXEC SQL INCLUDE SQLCA statement is missing from the source
file.
921
SQLPP errors
Probable cause You have attempted to declare a host variable as an array of character arrays.
This is not a legal host variable type.
Probable cause You must specify the precision when declaring a packed decimal host
variable using the DECL_DECIMAL macro. The scale is optional.
Probable cause An embedded SQL statement name has been used (EXECUTE) without first
being prepared.
922
Chapter 11 SQL Preprocessor Error Messages
Probable cause You have used a static statement name and preprocessed with the -r
reentrancy switch. Static statement names cause static variables to be
generated that are filled in by the database. If two threads use the same
statement, contention arises over this variable. Use a local host variable as
the statement identifier instead of a static name.
Probable cause You have attempted to index a host variable that is an array with a value too
large for the array.
Probable cause The SQL preprocessor has a maximum token length of 2K. Any token longer
than 2K will produce this error. For constant strings in embedded SQL
commands (the main place this error shows up) use string concatenation to
make a longer string.
923
SQLPP errors
Probable cause You have used a SQL function that is unknown to the preprocessor and will
probably cause an error when the statement is sent to the database engine.
Probable cause You attempted to drop an embedded SQL statement that doesn’t exist.
Probable cause You have used a SQL statement that will probably cause a syntax error when
the statement is sent to the database engine.
vendor extension
Message value Message Type
2666 Flag (warning or error)
924
Chapter 11 SQL Preprocessor Error Messages
Probable cause You have used a SQL function with the wrong number of parameters. This
will likely cause an error when the statement is sent to the database engine.
925
SQLPP errors
926
C H A P T E R 1 2
About this chapter Adaptive Server Anywhere conforms to the ANSI SQL89 standard but has
many additional features defined in IBM’s DB2 and SAA specification, and
in ANSI SQL/92.
This chapter describes those features of Adaptive Server Anywhere that are
not commonly found in other SQL implementations.
Contents
Topic Page
Adaptive Server Anywhere SQL features 928
927
Adaptive Server Anywhere SQL features
928
Chapter 12 Differences from Other SQL Dialects
Additional Adaptive Server Anywhere supports several functions not in the ANSI SQL
functions definition. See "SQL Functions" on page 291 for a full list of available
functions.
Cursors When using Embedded SQL, cursor positions can be moved arbitrarily on
the FETCH statement. Cursors can be moved forward or backward relative
to the current position or a given number of records from the beginning or
end of the cursor.
929
Adaptive Server Anywhere SQL features
930
C H A P T E R 1 3
Physical Limitations
About this chapter This chapter describes the limitations on size and number of objects in
Adaptive Server Anywhere databases.
Contents
Topic Page
Size and number limitations 932
931
Size and number limitations
Item Limitation
Database size 12 files per database. For each file,
the largest file allowed by operating
system and file system.
Field size 2 GB
File size (FAT 12) 16 MB
File size (FAT 16) 2 GB
File size (FAT 32) 4 GB
File size (NTFS, HP-UX 11.0 and later, 256 GB (for 1K pages)
Solaris 2.6 and later) 512 GB (for 2K pages)
1 TB (for 4K pages)
File size (all other platforms and file 2 GB
systems)
Maximum index entry size No limit
Number of columns per table 999 (using 4K pages)
Number of indexes The maximum number of indexes per
table is based on the database page
size:
♦ 4K or less 2048 indexes
♦ 8K 1024 indexes
♦ 16K 512 indexes
♦ 32K 256 indexes
Number of rows per database Limited by file size
Number of rows per table Limited by file size
Number of tables per database 2^32 – 1 (4294967295)
Number of tables referenced per transaction No limit
Row size Limited by file size
Table size Maximum file size. User-created
indexes for the table can be stored
separately from the table.
932
C H A P T E R 1 4
About this chapter This chapter documents the system-supplied catalog stored procedures in
Adaptive Server Anywhere databases, used to retrieve system information.
The chapter also documents system-supplied extended procedures, including
procedures for sending e-mail messages on a MAPI e-mail system.
Contents
Topic Page
System procedure overview 934
System and catalog stored procedures 935
System extended stored procedures 950
Adaptive Server Enterprise system and catalog procedures 957
933
System procedure overview
934
Chapter 14 System Procedures and Functions
935
System and catalog stored procedures
The returned parameters indicate the name of a table containing a row that is
currently violating referential integrity, and the name of the corresponding
foreign key index.
Examples The following set of commands can be executed from Interactive SQL. It
deletes rows from the department table in the sample database, in such a way
as to violate referential integrity. The call to sa_check_commit checks
which tables and keys have outstanding violations, and the rollback cancels
the change:
SET TEMPORARY OPTION WAIT_FOR_COMMIT=’ON’
go
DELETE FROM department
go
CREATE VARIABLE tname VARCHAR( 128 )
CREATE VARIABLE keyname VARCHAR( 128 )
go
CALL sa_check_commit( tname, keyname )
go
SELECT tname, keyname
go
ROLLBACK
go
♦ ReqType
♦ CommLink
♦ NodeAddr
♦ LastIdle
♦ CurrTaskSwitch
♦ BlockedOn
♦ UncmtOps.
♦ LockName
In a deadlock situation, the BlockedOn value returned by this procedure
allows you to check which users are blocked, and who they are blocked on.
The sa_locks procedure can be used to display the locks held by the blocking
connection; and if A holds locks on several tables you can match the
LockName value between sa_locks and sa_conn_info.
$ For information on these properties, see "Connection-level properties"
on page 1060.
937
System and catalog stored procedures
Permissions None.
Side effects None
See also "sa_conn_properties system procedure" on page 937
"Connection-level properties" on page 1060
Description This is a variant on the sa_conn_properties system procedure, and returns the
same result columns.It returns results only for connection properties that
match the property-name string. You can use wild cards in property-name, as
the comparison uses a LIKE operator. The result set is sorted by connection
number and property name.
$ For a listing of available connection properties, see "Connection-level
properties" on page 1060.
Example ♦ The following statement returns the AnsiNull option setting for all
connections:
call sa_conn_properties_by_conn( ’ansinull’ )
♦ The following statement returns the Ansi-related option settings for all
connections:
call sa_conn_properties_by_conn( ’ansi%’ )
938
Chapter 14 System Procedures and Functions
Permissions None.
Side effects None
See also "sa_db_properties system procedure" on page 939
"Database-level properties" on page 1070
Description Returns a single row containing the Number, Alias, File, ConnCount,
PageSize, and LogName for the specified database.
Examples ♦ The following statement returns a single row describing the current
database:
call sa_db_info
Sample values are as follows:
Property Value
Number 0
Alias asademo
File c:\asa6\asademo.db
ConnCount 1
PageSize 1024
LogName c:\asa6\asademo.log
939
System and catalog stored procedures
Syntax sa_eng_properties
Permissions None.
Side effects None
See also "Server-level properties" on page 1065
Description Returns the PropNum, PropName, PropDescription, and Value for each
available server property.
$ For a listing of available engine properties, see "System functions" on
page 298.
Example ♦ The following statement returns a set of available server properties
call sa_eng_properties()
940
Chapter 14 System Procedures and Functions
941
System and catalog stored procedures
lock_name The LockName value identifying the lock. This value can be
matched with sa_conn_info output to determine the responsible locks in a
blocking situation.
$ For more information, see "Connection-level properties" on page 1060,
and "sa_conn_info system procedure" on page 936.
lock type The lock type is a string of characters indicating the type of
lock. These characters are:
♦ S Shared
♦ E Exclusive
♦ P Phantom
♦ A Anti-phantom
All locks listed have exactly one of S or E specified, and may also have P, A,
or both. If a lock is a phantom or anti-phantom lock, a qualifier is added to
the lock type. The qualifier is as follows:
♦ T The lock is with respect to a sequential scan
♦ * The lock is with respect to all scans.
♦ nnn An index number. The lock is with respect to a particular index.
942
Chapter 14 System Procedures and Functions
Description Database administrators can use this procedure to override some database
server command-line options without restarting the database server.
The options that can be reset are as follows:
943
System and catalog stored procedures
♦ STOP ENGINE
♦ STOP DATABASE
♦ Statement preparation
♦ Statement execution
♦ EXECUTE IMMEDIATE statements
♦ Option settings
♦ COMMIT statements
♦ ROLLBACK statements
♦ PREPARE TO COMMIT operations.
♦ Connections
♦ Disconnections
♦ Beginnings of transactions
♦ DROP STATEMENT statement.
♦ Cursor explanations
♦ Cursor closings
♦ Cursor resume
♦ Errors
You can find the current value of this setting using the RequestLogging
property function.
$ For more information, see "–zr command-line option" on page 40, and
"Server-level properties" on page 1065.
Example The following statement disallows new connections to the database server.
call sa_server_option( ’disable_connections’, ’ON’)
944
Chapter 14 System Procedures and Functions
Description The results include the same information provided by the Information utility.
$ For information on the Information utility, see "The Information utility"
on page 90.
owner_name Validate only the tables owned by the specified user. When
NULL (the default), validate tables for all users.
946
Chapter 14 System Procedures and Functions
947
System and catalog stored procedures
"Server Classes for Remote Data Access" on page 899 of the book ASA
User’s Guide
"CREATE SERVER statement" on page 451
Description This procedure displays information about a remote server’s capabilities.
Adaptive Server Anywhere uses this capability information to determine how
much of a SQL statement can be forwarded to a remote server. The system
tables which contain server capabilities are not populated until after Adaptive
Server Anywhere first connects to the remote server. This information
comes from SYSCAPABILITY and SYSCAPABILITYNAME. The
servername specified must be the same servername used in the CREATE
SERVER statement.
Standards and ♦ Sybase Supported by Open Client/Open Server.
compatibility
Example ♦ To display information about the remote server testasa issue the
following stored procedure:
sp_servercaps testasa
948
Chapter 14 System Procedures and Functions
-- ASA datastore
set temporary option AUTOMATIC_TIMESTAMP=’ON’
end if;
set temporary option ANSINULL=’OFF’;
set temporary option TSQL_VARIABLES=’ON’;
set temporary option ANSI_BLANKS=’ON’;
set temporary option TSQL_HEX_CONSTANT=’ON’;
set temporary option CHAINED=’OFF’;
set temporary option QUOTED_IDENTIFIER=’OFF’;
set temporary option ALLOW_NULLS_BY_DEFAULT=’OFF’;
set temporary option FLOAT_AS_DOUBLE=’ON’;
set temporary option ON_TSQL_ERROR=’CONTINUE’;
set temporary option ISOLATION_LEVEL=’1’;
set temporary option DATE_FORMAT=’YYYY-MM-DD’;
set temporary option TIMESTAMP_FORMAT=’YYYY-MM-DD
HH:NN:SS.SSS’;
set temporary option TIME_FORMAT=’HH:NN:SS.SSS’;
set temporary option DATE_ORDER=’MDY’;
set temporary option ESCAPE_CHARACTER=’OFF’
end
949
System extended stored procedures
950
Chapter 14 System Procedures and Functions
951
System extended stored procedures
Example The following call sends a message to the user ID Sales Group containing
the file prices.doc as a mail attachment:
CALL xp_sendmail(recipient=’Sales Group’,
subject=’New Pricing’,
include_file = ’C:\\DOCS\\PRICES.DOC’
)
952
Chapter 14 System Procedures and Functions
953
System extended stored procedures
Argument Description
ProductName The name of the product (Sybase Adaptive Server
Anywhere)
ProductVersion The version number, followed by the build number. The
format is as follows:
6.5.02 (1200)
CompanyName Returns the following string:
Sybase Inc.
FileDescription Returns the name of the product, followed by the name of
the operating system.
LegalCopyright Returns a copyright string for the software
LegalTrademarks Returns trademark information for the software
Permissions None.
See also "System functions" on page 298
Description xp_msver returns product, company, version, and other information.
Example ♦ The following statement requests the version and operating system
description:
select xp_msver( ’ProductVersion’) Version,
xp_msver(’FileDescription’) Description
Sample output is as follows:
Version Description
6.5.02 (1438) Sybase Adaptive Server Anywhere Windows
NT
954
Chapter 14 System Procedures and Functions
955
System extended stored procedures
956
Chapter 14 System Procedures and Functions
You may need to reset the width of your Interactive SQL output to see the
full text, by selecting Command➤Options and entering a new Limit Display
Columns value.
957
Adaptive Server Enterprise system and catalog procedures
958
Chapter 14 System Procedures and Functions
959
Adaptive Server Enterprise system and catalog procedures
960
C H A P T E R 1 5
System Tables
About this chapter The structure of every database is described in a number of system tables.
The Entity-Relationship diagram on the next page shows all the system
tables and the foreign keys that connect them.
The system tables are owned by the SYS user ID. The contents of these
tables can be changed only by the database system. The UPDATE, DELETE,
and INSERT commands cannot be used to modify the contents of these
tables. Further, the structure of these tables cannot be changed using the
ALTER TABLE and DROP commands.
Contents
Topic Page
System tables diagram 963
System table descriptions 965
DUMMY system table 966
SYSARTICLE system table 967
SYSARTICLECOL system table 968
SYSCAPABILITY system table 969
SYSCAPABILITYNAME system table 970
SYSCOLLATION system table 971
SYSCOLLATIONMAPPINGS system table 972
SYSCOLPERM system table 973
SYSCOLUMN system table 974
SYSDOMAIN system table 976
SYSEXTENT system table 977
SYSEXTERNLOGINS system table 978
SYSFILE system table 979
SYSFKCOL system table 980
SYSFOREIGNKEY system table 981
SYSGROUP system table 983
961
System tables diagram
962
Chapter 15 System Tables
963
System tables diagram
CLASS_ID = REPLACED_BY
SYSJAVACLASS
CLASS_ID <pk> smallint
REPLACED_BY <fk> smallint
JAR_ID smallint
CLASS_NAME long varchar
PUBLIC char(1)
COMPONENT_ID <fk> smallint
CREATE_TIME timestamp
UPDATE_TIME timestamp
CLASS_DESCRIPTOR long binary
REMARKS long varchar
COMPONENT_ID = COMPONENT_ID
SYSJARCOMPONENT
COMPONENT_ID <pk> smallint
JAR_ID <fk> smallint
COMPONENT_NAME long varchar
COMPONENT_TYPE char(1)
CREATE_TIME timestamp
CONTENTS long binary
REMARKS long varchar
JAR_ID = JAR_ID
SYSJAR
JAR_ID <pk> smallint
CREATOR smallint
JAR_NAME long varchar
JAR_FILE long varchar
CREATE_TIME timestamp
UPDATE_TIME timestamp
REMARKS long varchar
964
Chapter 15 System Tables
965
DUMMY system table
The DUMMY table is provided as a read-only table that always has exactly
one row. This can be useful for extracting information from the database, as
in the following example that gets the current user ID and the current date
from the database.
SELECT USER, today(*) FROM SYS.DUMMY
Use of FROM SYS.DUMMY in the FROM clause is optional. If no table is
specified in the FROM clause, the table is assumed to be SYS.DUMMY. The
above example could be written as follows:
SELECT USER, today(*)
966
Chapter 15 System Tables
table_id Each article consists of columns and rows from a single table.
This column contains the table ID for this table.
967
SYSARTICLECOL system table
968
Chapter 15 System Tables
969
SYSCAPABILITYNAME system table
970
Chapter 15 System Tables
971
SYSCOLLATIONMAPPINGS system table
972
Chapter 15 System Tables
table_id The table number for the table containing the column.
grantee The user number of the user ID that is given UPDATE permission
on the column. If the grantee is the user number for the special PUBLIC
user ID, the UPDATE permission is given to all user IDs.
grantor The user number of the user ID that grants the permission.
column_id This column number, together with the table_id, identifies the
column for which UPDATE permission has been granted.
is_grantable (Y/N)
Indicates if the permission on the column was granted
WITH GRANT OPTION.
973
SYSCOLUMN system table
table_id A number that uniquely identifies the table or view to which this
column belongs.
974
Chapter 15 System Tables
pkey (Y/N) Indicate whether this column is part of the primary key for the
table.
domain_id The data type for the column, indicated by a data type number
listed in the SYSDOMAIN table.
nulls (Y/N) Indicates whether the NULL value is allowed in this column.
scale The number of digits after the decimal point for numeric data type
columns, and zero for all other data types.
max_identity
The largest value of the column, if it is an
AUTOINCREMENT, IDENTITY, or GLOBAL AUTOINCREMENT
column.
default The default value for the column. This value is only used when an
INSERT statement does not specify a value for the column.
remote_type The type of the remote column. This value is defined by the
remote server or interface.
975
SYSDOMAIN system table
domain_id The unique number assigned to each data type. These numbers
cannot be changed.
precision The number of significant digits that can be stored using this
data type. The column value is NULL for non-numeric data types.
976
Chapter 15 System Tables
977
SYSEXTERNLOGINS system table
remote_login The login name for this user, for the remote server.
remote_password The password for this user, for the remote server.
978
Chapter 15 System Tables
Every database consists of one or more operating system files. Each file is
recorded in SYSFILE.
979
SYSFKCOL system table
foreign_key_id The key number of the FOREIGN KEY for the foreign
table. Together, foreign_table_id and foreign_key_id uniquely identify one
row in SYSFOREIGNKEY. The table number for the primary table can be
obtained from that row (using the SYSFOREIGNKEY table).
980
Chapter 15 System Tables
root Foreign keys are stored in the database as B-trees. The root identifies
the location of the root of the B-tree in the database file.
981
SYSFOREIGNKEY system table
nulls (Y/N) Indicates whether the columns in the foreign key are allowed
to contain the NULL value. Note that this setting is independent of the nulls
setting in the columns contained in the foreign key.
role The name of the relationship between the foreign table and the
primary table. Unless otherwise specified, the role name will be the same as
the name of the primary table. The foreign table cannot have two foreign
keys with the same role name.
982
Chapter 15 System Tables
There is one row in SYSGROUP for every member of every group. This
table describes a many-to-many relationship between groups and members.
A group may have many members, and a user may be a member of many
groups.
983
SYSINDEX system table
index_id Each index for one particular table is assigned a unique index
number.
root Indexes are stored in the database as B-trees. The root identifies the
location of the root of the B-tree in the database file.
file_id
The index is completely contained in the file with this file_id (see
SYSFILE).
creator The user number of the creator of the index. This user is always
the same as the creator of the table identified by table_id.
984
Chapter 15 System Tables
index_name The name of the index. A user ID cannot have two indexes
with the same name in tables that it owns..
985
SYSINFO system table
page_size The page size specified, in bytes. The default value is 1024.
encryption (Y/N) Indicates whether the -e switch was used with DBINIT.
986
Chapter 15 System Tables
987
SYSIXCOL system table
Every index has one row in SYSIXCOL for each column in the index.
order (A/D) Indicate whether this column in the index is kept in ascending
or descending order.
988
Chapter 15 System Tables
jar_id A field containing the id of the jar file. This field also references
the SYSJAR system table.
989
SYSJARCOMPONENT system table
jar_id A field containing the ID number of the jar. This field also
references the SYSJAR system table.
990
Chapter 15 System Tables
class_id This field contains the id of the java class. Also the primary key
for the table.
creator This field contains the user_id of the creator of the class. This
field references the user_id field in the SYSUSERPERM system table to
obtain the name of the user.
991
SYSJAVACLASS system table
jar_id This field contains the id of the jar file from which the class came.
type_id This field contains the id of the user type. This field references
the SYSUSERTYPE system table to obtain the id of the user.
public This field determines whether or not the class is public or private.
992
Chapter 15 System Tables
This table contains all the User Profile names that can be used to connect to
the database using an integrated logon. As a security measure, only users
with DBA authority can view the contents of this table.
993
SYSOPTION system table
Options settings are stored in the SYSOPTION table by the SET command.
Each user can have their own setting for each option. In addition, settings for
the PUBLIC user ID define the default settings to be used for user IDs that
do not have their own setting.
994
Chapter 15 System Tables
creator This user number identifies the owner of the procedure. The name
of the user can be found by looking in SYSUSERPERM.
proc_name The name of the procedure. One creator cannot have two
procedures with the same name.
995
SYSPROCPARM system table
996
Chapter 15 System Tables
domain_id Identifies the data type for the parameter, by the data type
number listed in the SYSDOMAIN table.
scale The number of digits after the decimal point for numeric data type
parameters, and zero for all other data type.
default Unused.
997
SYSPROCPERM system table
Only users who have been granted permission can call a procedure. Each row
of the SYSPROCPERM table corresponds to one user granted permission to
call one procedure.
998
Chapter 15 System Tables
999
SYSREMOTEOPTION system table
1000
Chapter 15 System Tables
1001
SYSREMOTETYPE system table
1002
Chapter 15 System Tables
consolidate
(Y/N) Indicates whether the user was granted
CONSOLIDATE permissions (Y) or REMOTE permissions (N).
1003
SYSREMOTEUSER system table
address The address to which SQL Remote messages are to be sent. The
address must be appropriate for the address_type.
time_sent The time the most recent message was sent to this subscriber.
log_sent The log offset for the most recently sent operation.
confirm_sent The log offset for the most recently confirmed operation
from this subscriber.
time_received The time when the most recent message was received from
this subscriber.
log_received The log offset in the subscriber’s database for the operation
that was most recently received at the current database.
confirm_received The log offset in the subscriber’s database for the most
recent operation for which a confirmation message has been sent.
1004
Chapter 15 System Tables
1005
SYSSQLSERVERTYPE system table
1006
Chapter 15 System Tables
Each row describes a subscription from one user ID (which must have
REMOTE permissions) to one publication.
created The offset in the transaction log at which the subscription was
created.
started The offset in the transaction log at which the subscription was
started.
1007
SYSTABLE system table
file_id
Indicates which database file contains the table. The file_id is a
FOREIGN KEY for SYSFILE.
1008
Chapter 15 System Tables
count The number of rows in the table is updated during each successful
CHECKPOINT. This number is used by Adaptive Server Anywhere when
optimizing database access. The count is always 0 for a view.
last_page The last page that contains information for this table. The
last_page is always 0 for a view.
creator The user number of the owner of the table or view. The name of
the user can be found by looking in SYSUSERPERM.
table_name The name of the table or view. One creator cannot have two
tables or views with the same name.
table_type This column is BASE for base tables, VIEW for views, and be
GBL TEMP for global temporary tables. No entry is created for local
temporary tables.
view_def For a view, this column contains the CREATE VIEW command
that was used to create the view. For a table, this column contains any
CHECK constraints for the table.
1009
SYSTABLEPERM system table
1010
Chapter 15 System Tables
♦ G The grantee has been given this permission and can grant the same
permission to another user (with grant options).
Permissions
The grantee might have been given permission for the same table by
another grantor. If so, this information would be recorded in a different
row of SYSTABLEPERM.
stable_id The table number of the table or view to which the permissions
apply.
1011
SYSTRIGGER system table
table_id The table number uniquely identifies the table to which this
trigger belongs.
event The event or events that cause the trigger to fire. This single-
character value corresponds to the trigger event that was specified when the
trigger was created.
1012
Chapter 15 System Tables
trigger_time The time at which the trigger will fire. This single-character
value corresponds to the trigger time that was specified when the trigger was
created.
♦ A AFTER
♦ B BEFORE
trigger_order The order in which the trigger will fire. This determines the
order that triggers are fired when there are triggers of the same type (insert,
update, or delete) that fire at the same time (before or after).
foreign_key_id The foreign key number of the foreign key for the table
referenced by foreign_table_id.
trigger_name The name of the trigger. One table cannot have two triggers
with the same name.
1013
SYSTYPEMAP system table
nullable This field describes whether or not the type can or cannot be null.
1014
Chapter 15 System Tables
langid Reserved.
1015
SYSUSERPERM system table
password The password for the user ID. The password contains the
NULL value for the special user IDs SYS and PUBLIC. This prevents
anyone from connecting to these user IDs.
1016
Chapter 15 System Tables
publishauth (Y/N) Indicates whether the user has the SQL Remote
publisher authority.
remotedbaauth (Y/N) Indicates whether the user has the SQL Remote
remote DBA authority.
1017
SYSUSERTYPE system table
domain_id The data type on which this user defined data type is based,
indicated by a data type number listed in the SYSDOMAIN table.
nulls (Y/N) Indicates whether the user-defined data type allows nulls.
scale The number of digits after the decimal point for numeric data type
columns, and zero for all other data types.
type_name The name for the data type, which must be a valid identifier.
1018
Chapter 15 System Tables
1019
SYSUSERTYPE system table
1020
C H A P T E R 1 6
System Views
About this chapter This chapter lists predefined views for the system tables.
The system tables described in "System Tables" on page 961 use numbers to
identify tables, user IDs, and so forth. While this is efficient for internal use,
it makes these tables difficult for people to interpret. A number of predefined
system views are provided that present the information in the system tables
in a more readable format.
The definitions for the system views are included with their descriptions.
Some of these definitions are complicated, but need not be understood to use
the views. They serve as good examples of what can be accomplished using
the SELECT command and views.
Contents
Topic Page
SYSARTICLECOLS system view 1023
SYSARTICLES system view 1024
SYSCAPABILITIES system view 1025
SYSCATALOG system view 1026
SYSCOLAUTH system view 1027
SYSCOLUMNS system view 1028
SYSFOREIGNKEYS system view 1029
SYSGROUPS system view 1030
SYSINDEXES system view 1031
SYSOPTIONS system view 1032
SYSPROCAUTH system view 1033
SYSPROCPARMS system view 1034
SYSPUBLICATIONS system view 1035
SYSREMOTEOPTIONS system view 1036
SYSREMOTETYPES system views 1037
SYSREMOTEUSERS system view 1038
1021
SYSARTICLECOLS system view
1022
Chapter 16 System Views
1023
SYSARTICLES system view
1024
Chapter 16 System Views
1025
SYSCATALOG system view
1026
Chapter 16 System Views
1027
SYSCOLUMNS system view
1028
Chapter 16 System Views
1029
SYSGROUPS system view
1030
Chapter 16 System Views
1031
SYSOPTIONS system view
1032
Chapter 16 System Views
1033
SYSPROCPARMS system view
1034
Chapter 16 System Views
1035
SYSREMOTEOPTIONS system view
1036
Chapter 16 System Views
1037
SYSREMOTEUSERS system view
1038
Chapter 16 System Views
1039
SYSTABAUTH system view
1040
Chapter 16 System Views
1041
SYSUSERAUTH system view
1042
Chapter 16 System Views
1043
SYSUSEROPTIONS system view
1044
Chapter 16 System Views
1045
SYSVIEWS system view
1046
Chapter 16 System Views
1047
Views for Transact-SQL Compatibility
1048
Chapter 16 System Views
1049
Views for Transact-SQL Compatibility
1050
A P P E N D I X A
About this This appendix contains information and tables relating to database
Appendix performance monitoring and database connection parameters.
Contents
Topic Page
Database performance statistics 1052
Database properties 1060
1051
Database performance statistics
1052
Appendix A Database Performance and Connection Properties
Checkpoint and These statistics isolate the checkpoint and recovery actions performed when
recovery statistics the database is in an idle state.
1053
Database performance statistics
1054
Appendix A Database Performance and Connection Properties
Disk I/O statistics These statistics combine disk reads and disk writes to give overall
information about the amount of activity devoted to disk I/O.
Disk read statistics These statistics describe the amount and type of activity devoted to reading
information from disk.
1055
Database performance statistics
Disk write statistics These statistics describe the amount and type of activity devoted to reading
information from disk.
1056
Appendix A Database Performance and Connection Properties
Java VM statistics These statistics describe the memory used by the Java VM.
1057
Database performance statistics
Memory pages These statistics describe the amount and purpose of memory used by the
statistics database server.
Request statistics These statistics describe the database server activity devoted to responding to
requests from client applications.
1058
Appendix A Database Performance and Connection Properties
1059
Database properties
Database properties
Adaptive Server Anywhere provides a set of properties that are made
available to client applications. These properties describe aspects of
connection, database and database server behavior.
Accessing Each type of property can be accessed by supplying its name as an argument
properties to a system function.
Connection-level properties
1060
Appendix A Database Performance and Connection Properties
1061
Database properties
Property Description
Commit The number of Commit requests that have been
handled.
CommLink The communication link for the connection. This
is one of the network protocols supported by
Adaptive Server Anywhere, or is local for a same-
machine connection.
CommProtocol Returns CmdSeq for Adaptive Server Anywhere
protocol (ODBC and Embedded SQL) or TDS for
Open Client and jConnect connections.
Continue_after_raiserror "CONTINUE_AFTER_RAISERROR option" on
page 167
Conversion_error "CONVERSION_ERROR option" on page 168
Cooperative_commit_time "COOPERATIVE_COMMIT_TIMEOUT option"
out on page 169
Cooperative_commits "COOPERATIVE_COMMITS option" on
page 168
CurrTaskSwitch The number of current request context switches.
Cursor The number of declared cursors that are currently
being maintained by the server.
CursorOpen The number of open cursors that are currently
being maintained by the server.
Date_format "DATE_FORMAT option" on page 169
Date_order "DATE_ORDER option" on page 171
DBNumber The ID number of the database.
Default_timestamp_incre "DEFAULT_TIMESTAMP_INCREMENT
ment option" on page 171
Delayed_commit_timeout "DELAYED_COMMIT_TIMEOUT option" on
page 172
Delayed_commite "DELAYED_COMMITS option" on page 172
DiskRead The number of pages that have been read from
disk.
DiskReadIndInt The number of index internal-node pages that have
been read from disk.
DiskReadIndLeaf The number of index leaf pages that have been read
from disk.
DiskReadTable The number of table pages that have been read
from disk.
DiskWrite The number of modified pages that have been
1062
Appendix A Database Performance and Connection Properties
Property Description
written to disk.
Divide_by_zero_error "DIVIDE_BY_ZERO_ERROR option" on
page 173
Escape_character "ESCAPE_CHARACTER option" on page 174
Extended_join_syntax "EXTENDED_JOIN_SYNTAX option" on
page 174
Fire_triggers "FIRE_TRIGGERS option" on page 175
Float_as_double "FLOAT_AS_DOUBLE option" on page 175
FullCompare The number of comparisons that have been
performed beyond the hash value in an index.
IndAdd The number of entries that have been added to
indexes.
IndLookup The number of entries that have been looked up in
indexes.
Java_heap_size "JAVA_HEAP_SIZE option" on page 182
Java_input_output "JAVA_INPUT_OUTPUT option" on page 182
Java_namespace_size "JAVA_NAMESPACE_SIZE option" on page 183
Java_page_buffer_size The page buffer size used by the Java VM
JavaHeapSize The heap size per Java VM
Language The locale language
LastIdle The number of ticks between requests.
LastReqTime The time at which the last request for the specified
connection started.
Lock_rejected_rows Reserved
LockName A 64-bit unsigned integer value representing the
lock for which a connection is waiting.
LogFreeCommit The number of Redo Free Commits. A "Redo Free
Commit" occurs when a commit of the transaction
log is requested but the log has already been
written (so the commit was done for "free").
Login_mode "LOGIN_MODE option" on page 183
Login_procedure "LOGIN_PROCEDURE option" on page 184
LogWrite The number of pages that have been written to the
transaction log.
Max_cursor_count "MAX_CURSOR_COUNT option" on page 184
Max_statement_count "MAX_STATEMENT_COUNT option" on
1063
Database properties
Property Description
page 186
Min_password_length "MIN_PASSWORD_LENGTH option" on
page 186
Name The name of the current connection.
Nearest_century "NEAREST_CENTURY option" on page 187
NodeAddress The node for the client in a client/server
connection.
Non_keywords "NON_KEYWORDS option" on page 187
Number The ID number of the connection.
On_tsql_error "ON_TSQL_ERROR option" on page 189
Optimization_goal Reserved
Optimization_level Reserved
Percent_as_comment "PERCENT_AS_COMMENT option" on page 192
Port An application-specific number for each client
machine, identifying the connection port.
Precision "PRECISION option" on page 193
Prefetch "PREFETCH option" on page 193
Prepares Number of statement preparations carried out.
PrepStmt The number of prepared statements currently being
maintained by the server.
Query_plan_on_open "QUERY_PLAN_ON_OPEN option" on page 194
Quoted_identifier "QUOTED_IDENTIFIER option" on page 195
Recovery_time "RECOVERY_TIME option" on page 195
Replicate_all "REPLICATE_ALL option" on page 196
ReqType A string for the type of the last request.
RI_Trigger_time "RI_TRIGGER_TIME option" on page 197
Rlbk The number of Rollback requests that have been
handled.
RollbackLogPages The number of pages in the rollback log
Row_counts "ROW_COUNTS option" on page 196
Scale "SCALE option" on page 198
SQL_flagger_error_level "SQL_FLAGGER_ERROR_LEVEL option" on
page 198
SQL_flagger_warning_lev "SQL_FLAGGER_WARNING_LEVEL option"
1064
Appendix A Database Performance and Connection Properties
Property Description
el on page 199
String_rtruncation "STRING_TRUNCATION option" on page 200
TaskSwitch The number of times the current server thread has
been changed.
Thread_count "THREAD_COUNT option" on page 200
Time_format "TIME_FORMAT option" on page 200
Timestamp_format "TIMESTAMP_FORMAT option" on page 201
Truncate_with_autocomm "TRUNCATE_WITH_AUTO_COMMIT option"
it on page 202
Tsql_hex_constant "TSQL_HEX_CONSTANT option" on page 203
Tsql_variables "TSQL_VARIABLES option" on page 204
UncommitOp The number of uncommitted operations
Userid The user ID for the connection.
Wait_for_commit "WAIT_FOR_COMMIT option" on page 205
Server-level properties
The following table lists properties that apply across the server as a whole.
Examples
v To retrieve the value of a server property:
♦ Use the property system function: For example: the following statement
returns the number of cache pages being used to hold the main heap:
select property ( ’MainHeapPages’)
1065
Database properties
1066
Appendix A Database Performance and Connection Properties
Property Description
CompanyName The name of the company owning this software.
ConnsDisabled Returns ON or OFF, to indicate the current setting of
the server option to disable new connections.
1067
Database properties
Property Description
IdleWrite The number of disk writes that have been issued by the
server’s idle thread.
IndAdd The number of entries that have been added to indexes.
IndLookup The number of entries that have been looked up in
indexes.
IOToRecover The estimated number of IO operations required to
recover the database.
IsNetworkServer Returns YES if connected to a network database
server, and NO if connected to a personal database
server.
IsRuntimeServer Returns YES if connected to the limited desktop
runtime database server, and NO otherwise.
JavaGlobFix Java VM global fixed size
JavaHeapSize Heap size per Java VM
JavaNSSize Java VM Namespace size
Language The locale language for the server
LegalCopyright The copyright string for the software.
LegalTrademarks Trademark information for the software.
LivenessTimeout The client liveness timeout default
LockedHeapPages The number of heap pages locked in the cache.
LockTablePages The number of pages used to store lock information
LogFreeCommit The number of Redo Free Commits. A "Redo Free
Commit" occurs when a commit of the transaction log
is requested but the log has already been written (so the
commit was done for "free").
LogWrite The number of pages that have been written to the
transaction log.
MainHeapBytes The number of bytes used for global server data
structures.
MainHeapPages The number of pages used for global server data
structures.
MapPages The number of map pages used for accessing the lock
table, frequency table, and table layout.
MaxCacheSize The maximum allowed cache size, in kilobytes.
MaxIO The maximum value that Curr IO has reached.
MaxRead The maximum value that Curr Read has reached.
1068
Appendix A Database Performance and Connection Properties
Property Description
MaxWrite The maximum value that Curr Write has reached.
Message The initial message displayed in the server window on
startup.
MinCacheSize The minimum allowed cache size, in kilobytes.
MultiPacketsReceived The number of multi-packet deliveries received during
client/server communications.
MultiPacketsSent The number of multi-packet deliveries sent during
client/server communications.
Name The name of the server.
PacketsCorrupted The number of packets corrupted during client/server
communications.
PacketsDropped The number of client/server communication packets
dropped.
PacketsReceived The number of client/server communication packets
received.
PacketsRereceived The number of duplicate client/server communication
packets received.
PacketsResent The number of client/server communication packets
resent.
PacketsSent The number of client/server communication packets
sent.
PageRelocations The number of relocatable heap pages that have been
read from the temporary file.
PeakCacheSize The largest value the cache has reached in the current
session, in kilobytes.
Platform The operating system on which the software is running.
ProcedurePages The number of relocatable heap pages that have been
used for procedures.
ProcessCPU Process CPU usage
ProcessCPUSystem Process CPU system usage
ProcessCPUUser Process CPU user usage
ProductName The name of the software.
ProductVersion The version of the software being run.
QuittingTime Shutdown time for the server. If none is specified, the
value is none.
RecoveryUrgency An estimate of the amount of time required to recover
1069
Database properties
Property Description
the database.
RelocatableHeapPages The number of pages used for relocatable heaps
(cursors, statements, procedures, triggers, views, etc.).
RemoteputWait The number of times the communication link has had
to wait because it does not have buffers available to
send information. This statistic is collected for
NetBIOS and IPX protocols only.
Req The number of times the server has been entered to
allow it to handle a new request or continue processing
an existing request.
RequestLogFile The name of the request-level logging filename. An
empty string is returned if there is no request level
logging.
Database-level properties
The following table lists properties available for each database on the server.
1070
Appendix A Database Performance and Connection Properties
1071
Database properties
Property Description
PageSize The page size of the database, in bytes.
ReadOnly ON if the database is being run in read-only mode.
OFF if the database is not being run in read-only
mode.
RecoveryUrgency An estimate of the amount of time required to recover
the database.
RemoteTrunc The minimal confirmed log offset for the
SQL Remote Message Agent.
SyncTrunc The minimal confirmed log offset for the MobiLink
client dbmlsync executable.
1072
Index
1073
A–A
1074
B–B
1075
C–C
1076
C–C
1077
C–C
1078
C–C
1079
C–C
1080
C–C
1081
D–D
1082
D–D
1083
D–D
1084
D–D
1085
D–D
1086
E–E
1087
E–E
e-mail ENDIF
extended stored procedures, 950 SQL IF expressions, 220
system procedures, 951 ending
embedded SQL rolling back transactions, 583
ALLOCATE DESCRIPTOR statement syntax, ENG connection parameter, 55
369 engine properties
BEGIN DECLARE statement syntax, 473 displaying, 935
CLOSE statement syntax, 404 EngineName connection parameter, 55
CONNECT statement syntax, 411 engines
DEALLOCATE DESCRIPTOR statement starting database, 606
syntax, 472 stopping database, 610
DECLARE CURSOR statement syntax, 475 enlistment
DELETE (positioned) statement syntax, 484 distributed transactions, 35
DESCRIBE statement syntax, 486 ENP connection parameter, 55
DISCONNECT statement syntax, 490 entity integrity, 928
DROP STATEMENT statement syntax, 498 environment variable
END DECLARE statement syntax, 473 switches, 19
EXECUTE IMMEDIATE statement syntax, 504 environment variables
EXECUTE statement syntax, 500 about, 6
EXPLAIN statement syntax, 507 ASTMP, 6
FETCH statement syntax, 509 LD_LIBRARY_PATH, 7
GET DATA statement syntax, 521 PATH, 7
GET DESCRIPTOR statement syntax, 523 SATMP, 7
GET OPTION statement syntax, 524 setting, 6
INCLUDE statement syntax, 535 SQLCONNECT, 8
OPEN statement syntax, 556 SQLLOCALE, 8
PREPARE statement syntax, 564 SQLPATH, 8
PUT statement syntax, 568 SQLREMOTE, 9
SET CONNECTION statement syntax, 594 SYBASE, 9
SET DESCRIPTOR statement syntax, 595 TMP, TEMP, and TEMPDIR, 9
SET SQLCA statement syntax, 600 erase utility, 88
WHENEVER statement syntax, 630 erasing databases, 88
ENC connection parameter, 56 error handling
EncryptedPassword connection parameter, 55 Transact-SQL procedures, 189
encryption ErrorNumber event condition
cllient/server communications, 24 about, 323
communications, 56, 68 errors
creating databases with dbinit, 93 codes, 633, 652
database files, 417 creating events for, 423
passwords, 55 divide by zero, 173
Encryption connection parameter, 56 error messages, 693
END in Interactive SQL, 188
SQL CASE expression, 221 messages, 633
END DELCARE statement raising in Transact-SQL, 570
SQL syntax, 473 signaling, 603
END keyword, 393 SQLSTATE values, 652
END LOOP statement Transact-SQL procedures, 189
SQL syntax, 553 trapping in embedded SQL, 630
END statement user-defined messages, 1015
SQL syntax, 392
1088
E–E
1089
F–F
1090
F–F
COUNT function SQL syntax, 312 IFNULL function SQL syntax, 328
creating, 432 image SQL, 300
curunreservedpgs Adaptive Server Enterprise index_col Adaptive Server Enterprise function,
function, 298 298
data type conversion SQL, 292 INDEX_ESTIMATE function SQL syntax, 329
data_pgs Adaptive Server Enterprise function, INSERTSTR function SQL syntax, 329
298 INTTOHEX function SQL syntax, 330
datalength Adaptive Server Enterprise function, ISNULL function SQL syntax, 330
298 LCASE function SQL syntax, 330
DATALENGTH function SQL syntax, 313 lct_admin Adaptive Server Enterprise function,
date and time SQL, 292 298
DATE function SQL syntax, 313 LEFT function SQL syntax, 331
DATEADD function SQL syntax, 314 LENGTH function SQL syntax, 331
DATEDIFF function SQL syntax, 314 LIST function SQL syntax, 332
DATEFORMAT function SQL syntax, 316 LOCATE function SQL syntax, 333
DATENAME function SQL syntax, 316 LOG function SQL syntax, 333
DATEPART function SQL syntax, 317 LOG10 function SQL syntax, 334
DATETIME function SQL syntax, 317 LOWER function SQL syntax, 334
DAY function SQL syntax, 318 LTRIM function SQL syntax, 334
DAYNAME function SQL syntax, 318 MAX function SQL syntax, 335
DAYS function SQL syntax, 318 MIN function SQL syntax, 335
db_id Adaptive Server Enterprise function, 298 MINUTE function SQL syntax, 336
DB_ID function SQL syntax, 319 MINUTES function SQL syntax, 336
db_name Adaptive Server Enterprise function, miscellaneous SQL, 295
298 MOD function SQL syntax, 337
DB_NAME function SQL syntax, 320 MONTH function SQL syntax, 338
DB_PROPERTY function SQL syntax, 320 MONTHNAME function SQL syntax, 338
DEGREES function SQL syntax, 321 MONTHS function SQL syntax, 338
DIFFERENCE function SQL syntax, 321 NEXT_CONNECTION function SQL syntax,
DOW function SQL syntax, 321 339
dropping, 491 NEXT_DATABASE function SQL syntax, 340
ESTIMATE function SQL syntax, 322 NOW function SQL syntax, 341
ESTIMATE_SOURCE function SQL syntax, NULLIF function SQL syntax, 341
322 NUMBER function SQL syntax, 342
EVENT_CONDITION function SQL syntax, 323 numeric SQL, 296
EVENT_CONDITION_NAME function SQL object_id Adaptive Server Enterprise function,
syntax, 324 298
EVENT_PARAMETER function SQL syntax, object_name Adaptive Server Enterprise
324 function, 298
exiting from user-defined, 579 PATINDEX function SQL syntax, 342
EXP function SQL syntax, 325 PI function SQL syntax, 343
EXPERIENCE_ESTIMATE function SQL PLAN function SQL syntax, 344
syntax, 326 POWER function SQL syntax, 344
FLOOR function SQL syntax, 326 proc_role Adaptive Server Enterprise function,
GETDATE function SQL syntax, 326 298
HEXTOINT function SQL syntax, 327 PROPERTY function SQL syntax, 345
host_id Adaptive Server Enterprise function, 298 PROPERTY_DESCRIPTION function SQL
host_name Adaptive Server Enterprise function, syntax, 344
298 PROPERTY_NAME function SQL syntax, 345
HOUR function SQL syntax, 327 PROPERTY_NUMBER function SQL syntax,
HOURS function SQL syntax, 327 346
1091
G–G
QUARTER function SQL syntax, 346 user_id Adaptive Server Enterprise function, 298
RADIANS function SQL syntax, 347 user_name Adaptive Server Enterprise function,
RAND function SQL syntax, 347 298
REMAINDER function SQL syntax, 348 user-defined SQL, 294
REPEAT function SQL syntax, 348 valid_name Adaptive Server Enterprise function,
REPLACE function SQL syntax, 348 298
REPLICATE function SQL syntax, 349 valid_user Adaptive Server Enterprise function,
reserved_pgs Adaptive Server Enterprise 298
function, 298 WEEKS function SQL syntax, 362
returning values from user-defined, 579 YEARS function SQL syntax, 363
RIGHT function SQL syntax, 350 YMD function SQL syntax, 364
ROUND function SQL syntax, 350 functions system SQL, 298
rowcnt Adaptive Server Enterprise function, 298 functions, numeric
RTRIM function SQL syntax, 351 ATAN, 303
SECOND function SQL syntax, 351
SECONDS function SQL syntax, 351
show_role Adaptive Server Enterprise function,
298 G
SIGN function SQL syntax, 352 GET DATA statement
SIMILAR function SQL syntax, 353 SQL syntax, 521
SIN function SQL syntax, 353 GET DESCRIPTOR statement
SOUNDEX function SQL syntax, 354 SQL syntax, 523
SPACE function SQL syntax, 354 GET OPTION statement
SQL syntax, 291 SQL syntax, 524
SQRT function SQL syntax, 355 GETDATE function
STR function SQL syntax, 355 SQL syntax, 326
STRING function SQL syntax, 356 getting
string SQL, 297 binary data from columns, 521
STUFF function SQL syntax, 356 information from descriptor areas, 523
SUBSTR function SQL syntax, 357 option values, 524
SUBSTRING function SQL syntax, 357 global autoincrement
SUM function SQL syntax, 358 creating events for, 423
suser_id Adaptive Server Enterprise function, global temporary tables
298 creating, 453
suser_name Adaptive Server Enterprise function, global variables
298 @@char_convert, 241
system, 298 @@client_csid, 241
TAN function SQL syntax, 358 @@client_csname, 241
text SQL, 300 @@connections, 241
TEXTPTR function SQL syntax, 359 @@cpu_busy, 241
TODAY function SQL syntax, 359 @@error, 240, 241
TRACEBACK function SQL syntax, 359 @@identity, 240, 241, 244
Transact-SQL, 298 @@idle, 241
TRIM function SQL syntax, 360 @@io_busy, 241
TRUNCATE function SQL syntax, 360 @@isolation, 240, 241
TRUNCNUM function SQL syntax, 361 @@langid, 241
tsequal Adaptive Server Enterprise function, 298 @@language, 241
UCASE function SQL syntax, 361 @@max_connections, 241
UPPER function SQL syntax, 362 @@maxcharlen, 241
used_pgs Adaptive Server Enterprise function, @@ncharsize, 241
298 @@nestlevel, 241
1092
H–I
1093
I–I
1094
J–J
1095
J–J
1096
K–L
1097
M–M
1098
N–N
messages names
creating, 439 SQL column names, 219
displaying, 554 NATURAL JOIN
messages windows SQL syntax, 518
printing messages in, 567 NDS
method signatures filenames, 18
Java, 444 NEAREST_CENTURY, 187
Microsoft Access Nearest_century property, 1061
TIMESTAMP comparison, 171 nesting
millenium issues, 285 user-defined transactions, 395
MIN function NetBIOS
SQL syntax, 335 about, 37
MIN_PASSWORD_LENGTH, 186 server configuration, 61
Min_password_length property, 1061 NetWare
MinCacheSize property, 1065 cache buffers, 21
MINUTE function database server, 18
SQL syntax, 336 file locations, 3
MINUTES function installation, 3
SQL syntax, 336 server performance, 21
MOD function subdirectories, 3
SQL syntax, 337 network communications
modulo operator command line switches, 61
PERCENT_AS_COMMENT option, 192 network number
MONEY data type in IPX address, 62
about, 263 NEXT_CONNECTION function
monitoring performance, 1052 SQL syntax, 339
MONTH function NEXT_DATABASE function
SQL syntax, 338 SQL syntax, 340
MONTHNAME function NO SCROLL cursors
SQL syntax, 338 declaring, 475
MONTHS function NodeAddress property, 1061
SQL syntax, 338 NON_KEYWORDS, 187
multi-byte character sets Non_keywords property, 1061
unloading data, 620 NOT
MultiByteCharSet property, 1070 SQL logical operators, 214
MultiPacketsReceived property, 1065 NOW function
MultiPacketsSent property, 1065 SQL syntax, 341
multi-row fetches NULL value
FETCH statement, 511 ANSI behavior, 160
OPEN statement, 557 ISNULL function, 330
multi-row inserts, 501 NULLS option, 188
MYIP communication parameter, 65 SQL special value, 247
three-valued logic, 247
Transact-SQL behavior, 160
NULLIF function, 222
N about, 341
name nulls
database, 42 defining for output, 192
Name property, 1061, 1065, 1070 NULLS option
NamedPipes Interactive SQL option, 188
about, 37
1099
O–O
1100
O–O
1101
P–P
1102
P–P
1103
Q–R
1104
R–R
1105
R–R
1106
S–S
1107
S–S
1108
S–S
servers shutdown
altering remote attributes, 378 specifying time, 36
creating, 451 SIGN function
dropping remote, 497 SQL syntax, 352
locating, 114, 116 SIGNAL statement
properties of, 1065 SQL syntax, 603
starting database, 606 signaling
starting from batch files, 117 errors, 570, 603
stopping database, 610 exceptions, 576
services signatures
event log, 18 Java methods, 444
registry entries, 10 SIMILAR function
Windows 95/98, 39 SQL syntax, 353
SESSIONS communication parameter, 67 SIN function
SET CONNECTION statement SQL syntax, 353
SQL syntax, 594 SLQ functions
SET DEFAULT, 461 date and time, 292
SET DESCRIPTOR statement SMALLDATETIME data type
SQL syntax, 595 about, 269, 270
SET NULL action, 461 SMALLINT data type
SET OPTION statement about, 261
Interactive SQL syntax, 155, 599 SMP
SQL syntax, 596 number of processors, 29
syntax, 144 software
Transact-SQL syntax, 593 dberase, 88
using, 144 dblog, 121
SET PERMANENT statement dbshrink, 82
Interactive SQL syntax, 599 dbtran, 110
SET SQLCA statement Interactive SQL, 99
SQL syntax, 600 REBUILD, 115
SET statement software license
SQL syntax, 591 licensing servers, 101
Transact-SQL syntax, 593 software version
SET TEMPORARY OPTION statement database server, 37
Interactive SQL syntax, 155, 599 SOME conditions
SQL syntax, 596 SQL syntax, 227
syntax, 144 sorting
setting in the system tables, 971
connections, 594 SOUNDEX function
descriptor areas, 595 SQL syntax, 354
options, 596 SP
options in Interactive SQL, 410, 599 statement indicator, 368
options in Transact-SQL, 593 sp_addgroup system procedure, 957
SQLCAs, 600 sp_addlogin system procedure, 957
users, 601 sp_addmessage system procedure, 439, 957
values of SQL variables, 591 sp_addtype system procedure, 957
SETUSER statement sp_adduser system procedure, 957
SQL syntax, 601 sp_changegroup system procedure, 957
shared memory sp_column_privileges
about, 37, 50 catalog procedure, 958
show_role Adaptive Server Enterprise function, 298 sp_column_privileges catalog procedure, 958
1109
S–S
1110
S–S
1111
S–S
1112
S–S
1113
S–S
1114
S–S
1115
S–S
1116
S–S
subdirectories syntax
NetWare, 3 SQL ALL conditions, 227
Windows CE, 3 SQL ANY conditions, 227
subqueries SQL arithmetic operators, 214
in SQL search conditions, 227 SQL BETWEEN conditions, 227
SQL syntax, 220 SQL bitwise operators, 215
SUBSCRIBE_BY_REMOTE SQL CASE expression, 221
replication option, 200 SQL column names, 219
subscriptions SQL comments, 246
updating, 621 SQL comparison operators, 213
SUBSTR function SQL connection-level variables, 238
SQL syntax, 357 SQL constants, 219
SUBSTRING function SQL CURRENT DATE special value, 234
SQL syntax, 357 SQL CURRENT PUBLISHER special value, 235
substrings SQL CURRENT TIME special value, 234
about, 357 SQL CURRENT TIMESTAMP special value,
replacing, 348 234
SUM function SQL CURRENT USER special value, 235
SQL syntax, 358 SQL EXISTS conditions, 231
sun.* packages SQL explicit selectivity estimates, 232
unsupported classes, 277 SQL expressions, 218
supported classes SQL functions, 291
Java, 276 SQL global variables, 239
java.beans, 276 SQL identifiers, 211
java.io, 277 SQL IF expressions, 220
java.lang, 277 SQL IN conditions, 230
java.lang.reflect, 277 SQL IS NULL conditions, 231
java.math, 277 SQL IS TRUE or FALSE conditions, 231
java.net, 277 SQL Java expressions, 222
java.rmi, 277 SQL join operators, 216
java.rmi.dgc, 277 SQL keywords, 208
java.rmi.registry, 277 SQL language elements, 207
java.rmi.server, 277 SQL LAST USER special value, 236
java.security, 277 SQL LIKE conditions, 228
java.security.acl, 277 SQL local variables, 237
java.security.interfaces, 277 SQL logical operators, 214
java.sql, 277 SQL NULL value, 247
java.text, 277 SQL operator precedence, 216
java.util, 277 SQL operators, 213
java.util.zip, 277 SQL predicates, 226
suser_id Adaptive Server Enterprise function, 298 SQL reserved words, 208
suser_name Adaptive Server Enterprise function, SQL search conditions, 226
298 SQL SOME conditions, 227
Sybase Central SQL special values, 234
quoted identifiers, 195 SQL SQLCODE special value, 235
registry entries, 11 SQL SQLSTATE special value, 235
starting Interactive SQL from, 100 SQL statements, 365
syntax highlighting, 192 SQL string operators, 215
SYBASE environment variable, 9 SQL strings, 212
SQL subqueries, 220
SQL subqueries in search conditions, 227
1117
S–S
1118
T–T
1119
T–T
1120
T–T
Transact-SQL triggering
ALLOW_NULLS_BY_DEFAULT option, 157 events, 614
AUTOMATIC_TIMESTAMP option, 161 TriggerPages property, 1065
bit data type compatibility, 264 triggers
bitwise operators, 215 @@identity global variable, 245
BREAK statement syntax, 631 altering, 386
catalog procedures, 958 and referential integrity actions, 197
column NULLs compatibility, 157, 195 and replication, 174, 175
compatibility options, 152 creating, 464
constants, 224 creating in Transact-SQL, 467
CONTINUE statement syntax, 631 disabling, 27
CREATE MESSAGE SQL statement syntax, 439 dropping, 491
CREATE PROCEDURE statement syntax, 447 rolling back, 585
CREATE SCHEMA statement syntax, 449 row-level, 464
CREATE TABLE statement syntax, 461 statement-level, 464
CREATE TRIGGER statement syntax, 467 TRUNCATE TABLE statement, 615
datetime compatibility, 265 TRIM function
DECLARE CURSOR statement syntax, 480 SQL syntax, 360
DECLARE section, 393 troubleshooting
delete permissions, 158 connections, 114, 116
domains, 275 debugging, 39, 40
EXECUTE statement syntax, 502 identifying client applications, 46
global variables, 239 locks, 941
GOTO statement syntax, 525 logging operations, 943
IF statement syntax, 533 logging server operations, 40
join operators, 216 request_level_logging, 942
local variables, 237, 238 TRUE conditions
money data types, 263 IS TRUE conditions, 231
NULL behavior, 160 TRUNCATE function
PRINT statement syntax, 567 SQL syntax, 360
QUOTED_IDENTIFIER option, 195, 224 TRUNCATE TABLE statement
RAISERROR statement syntax, 570 autocommit behavior, 202
READTEXT statement syntax, 573 SQL syntax, 615
SET OPTION statement syntax, 593 TRUNCATE_DATE_VALUES option
SET statement syntax, 593 about, 202
SQL comparison operators, 213 TRUNCATE_WITH_AUTO_COMMIT option
SQL expression compatibility, 223 about, 202
statement syntax, 365 Truncate_with_autocomproperty, 1061
strings, 224 truncating
system catalog, 1047 tables, 615
system functions, 298 Truncation
system procedures, 957 of character strings, 200
time compatibility, 265 truncation length
update permissions, 158 Interactive SQL option, 203
user-defined data types, 275 TRUNCNUM function
WHILE statement syntax, 631 SQL syntax, 361
WRITETEXT statement syntax, 632 tsequal Adaptive Server Enterprise function, 298
trapping TSQL
errors in embedded SQL, 630 statement indicator, 368
TRIGGER EVENT statement TSQL_HEX_CONSTANT option, 203
SQL syntax, 614 Tsql_hex_constant property, 1061
1121
U–U
1122
V–V
returning values from, 579 valid_user Adaptive Server Enterprise function, 298
SQL, 294 VALIDATE INDEX statement
Userid connection parameter, 60 SQL syntax, 627
Userid property, 1061 VALIDATE TABLE statement
users SQL syntax, 628
dropping, 581 validating
setting, 601 databases, 136, 945
user-supplied selectivity estimates indexes, 627
SQL syntax, 232 tables, 628
UseUDP communication parameter, 69 validation utility
utilities command-line syntax, 137
backup, 74 values
collation, 78 returning from procedures, 579
compression, 81 VARBINARY data type
dbbackup command-line syntax, 75 about, 273
dbcollat command-line syntax, 78 VARCHAR data type, 253
dbconsol command-line syntax, 83 variable result sets
dbdsn command-line syntax, 84 from procedures, 441, 488, 565
dberase command-line syntax, 89 variables
dbexpand command-line syntax, 124 creating SQL, 468
dbinfo command-line syntax, 90 declaring SQL, 474
dbinit command-line syntax, 93 dropping SQL, 499
dbisql command-line syntax, 99 getting from within a descriptor area, 523
dblic command-line syntax, 101 setting values, 591
dblocate command-line syntax, 116 SQL global variables, 238, 239
dblog command-line syntax, 120 SQL local variables, 237
dbltm command-line syntax, 103 SQL syntax, 237
dbping command-line syntax, 114 VERIFY_ALL_COLUMNS
dbshrink command-line syntax, 81 replication option, 204
dbspawn command-line syntax, 117 VERIFY_THRESHOLD
dbstop command-line syntax, 118 replication option, 204
dbtran command-line syntax, 109 version
dbunload command-line syntax, 127 database server, 37
dbupgrad command-line syntax, 134 version mismatch
dbvalid command-line syntax, 137 file locations, 4
dbwrite command-line syntax, 140 version number
erase, 88 retrieving, 953
information, 90 ViewPages property, 1065
initialization, 92 views
Interactive SQL, 99 altering, 387
log translation, 109 creating, 469
rebuild, 115 dropping, 491
rebuild command-line syntax, 115 examples, 1021
utility commands indexes, 435
permissions, 30 system views, 1046
updatable, 540
VM
starting Java, 607
V stopping Java, 611
valid_name Adaptive Server Enterprise function,
298
1123
W–Y
1124