Sets Adaptive Server query-processing options for the duration of the user’s work session; sets some options inside a trigger or stored procedure.
set @variable = expression [, @variable = expression...]
set ansinull {on | off}
set ansi_permissions {on | off}
set arithabort [arith_overflow | numeric_truncation] {on | off}
set arithignore [arith_overflow] {on | off}
set bulk array size number
set bulk batch size number
set {chained, close on endtran, nocount, noexec, parseonly, procid, self_recursion, showplan, sort_resources} {on | off}
set char_convert {off | on [with {error | no_error}] | charset [with {error | no_error}]}
set cis_rpc_handling {on | off}
set [clientname client_name | clienthostname host_name | clientapplname application_name]
set cursor rows number for cursor_name
set {datefirst number, dateformat format, language language}
set fipsflagger {on | off}
set flushmessage {on | off}
set forceplan {on | off}
set identity_insert [database.[owner.]]table_name {on | off} set identity_update table_name {on | off}
set jtc {on | off}
set lock { wait [ numsecs ] | nowait }
set offsets {select, from, order, compute, table, procedure, statement, param, execute} {on | off}
set parallel_degree number
set plan {dump | load } [group_name] {on | off}
set plan exists check {on | off}
set plan replace {on | off}
set prefetch [on|off]
set proc_output_params on | off
set proc_return_status on | off
set process_limit_action {abort | quiet | warning}
set proxy login_name
set quoted_identifier {on | off}
set role {"sa_role" | "sso_role" | "oper_role" | role_name [with passwd "password"]} {on | off}
set {rowcount number, textsize number}
set scan_parallel_degree number
set session authorization login_name
set sort_merge {on | off}
set statistics {io, subquerycache, time} {on | off}
set statistics simulate { on | off }
set strict_dtm_enforcement {on | off}
set string_rtruncation {on | off}
set table count number
set textsize {number}
set transaction isolation level { [ read uncommitted | 0 ] | [ read committed | 1 ] | [ repeatable read | 2 ]| [ serializable | 3 ] }
set transactional_rpc {on | off}
allows multiple variable assignments in one statement. The set @variable = expression command is an identical — and an alternative — command to select @variable = expression in Transact-SQL.
includes constant, function, any combination of constants, and functions connected by arithmetic or bitwise operators, or a subquery.
impacts on both aggregate and comparison behaviors:
Aggregate behavior ansinull determines whether evaluation of NULL-valued operands in aggregate functions is compliant with the ANSI SQL standard. If you use set ansinull on, Adaptive Server generates a warning when an aggregate function eliminates a null-valued operand from the calculation.
For example, if you perform the following query on the titles table with set ansinull off (the default value):
select max(total_sales) from titles
Adaptive Server returns:
----------- 22246
However, if you perform the same query with set ansinull on, Adaptive Server returns the same value and an error message because the total_sales column contains NULL values:
----------- 22246 Warning - null value eliminated in set function
This message indicates that some entries in total_sales contain NULL instead of a real amount, so you do not have complete data on total sales for all books in this table. However, of the available data, the value returned is the highest.
Comparison behavior The SQL standard requires that if either one of the two operands of an equality comparison is NULL, the result is UNKNOWN. Transact-SQL treats NULL values differently. If one of the operands is a column, parameter, or variable, and the other operand is the NULL constant or a parameter or variable whose value is NULL, the result is either TRUE or FALSE:
Sybase NULL mode – “val = NULL
” is
true when “val
” is
NULL
ANSI NULL mode – “val = NULL
” is
unknown when “val
” is
NULL
The ANSI rule for the where and on clauses return rows that are true, and rejects rows that are both false and unknown.
The ANSI rule for a check constraint rejects values that are false. For this reason, unknown or true results are not rejected.
If you:
Enable ansinull mode – do
not use the Sybase NULL comparisons (val = NULL
or val != NULL
).
Expect to use ANSI-null mode during insert and update – do not use the Sybase NULL comparisons in check constraints.
Instead, use the ANSI IS NULL or IS NOT NULL syntax to prevent from having unexpected results.
determines whether ANSI SQL permission requirements for delete and update statements are checked. The default is off. Table 1-36 summarizes permission requirements:
Command |
Permissions required with set ansi_permissions off |
Permissions required with set ansi_permissions on |
---|---|---|
update |
|
|
delete |
|
|
determines how Adaptive Server behaves when an arithmetic error occurs. The two arithabort options, arithabort arith_overflow and arithabort numeric_truncation, handle different types of arithmetic errors. You can set each option independently or set both options with a single set arithabort on or set arithabort off statement.
arithabort arith_overflow specifies Adaptive Server’s behavior following a divide-by-zero error or a loss of precision during an explicit or implicit datatype conversion. This type of error is serious. The default setting, arithabort arith_overflow on, rolls back the entire transaction in which the error occurs. If the error occurs in a batch that does not contain a transaction, arithabort arith_overflow on does not roll back earlier commands in the batch; however, Adaptive Server does not execute any statements in the batch that follow the error-generating statement.
If you set arithabort arith_overflow off, Adaptive Server aborts the statement that causes the error, but continues to process other statements in the transaction or batch.
arithabort numeric_truncation specifies Adaptive Server’s behavior following a loss of scale by an exact numeric type during an implicit datatype conversion. (When an explicit conversion results in a loss of scale, the results are truncated without warning.) The default setting, arithabort numeric_truncation on, aborts the statement that causes the error, but Adaptive Server continues to process other statements in the transaction or batch. If you set arithabort numeric_truncation off, Adaptive Server truncates the query results and continues processing.
determines whether Adaptive Server displays a message after a divide-by-zero error or a loss of precision. By default, the arithignore option is set to off. This causes Adaptive Server to display a warning message after any query that results in numeric overflow. To have Adaptive Server ignore overflow errors, use set arithignore on. You can omit the optional arith_overflow keyword without any effect.
establishes the number of rows that are buffered in local server memory before being transferred using the bulk copy interface.
Use this option only with Component Integration Services for transferring rows to a remote server using select into.
View your current setting using the @@bulkarraysize global variable.
number indicates the number of rows to buffer. If the rows being transferred contain text, image or java ADTs, then the bulk copy interface ignores the current setting for array size and uses a value of 1. Also, the array size actually used will never exceed the value of @@bulkbatchzise. If @@bulkbatchsize is smaller than array size, then the smaller value is used.
The initial value of the array size is inherited by new connections from the current setting of the configuration property cis bulk insert array size, which defaults to 50. Setting this value to 0 will reset the value to the default.
establishes the number of rows transferred to a remote server via select into proxy_table when the bulk interface is used. The bulk interface is available to all Adaptive Servers, as well as DirectConnect for Oracle version 12.5.1.
Use this option only with Component Integration Services for transferring rows to a remote server using select into.
View your current setting using the @@bulkbatchsize global variable.
The bulk interface allows a commit after a specified number of rows. This allows the remote server to free any log space being consumed by the bulk transfer operation, and enables the transfer of large data sets from one server to another without filling the transaction log.
The initial value of the batch size is inherited by new connections from the current setting of the configuration property cis bulk insert batch size, which by default is 0. A value of 0 indicates that no rows should be committed until after the last row is transferred.
begins a transaction just before the first data retrieval or data modification statement at the beginning of a session and after a transaction ends. In chained mode, Adaptive Server implicitly executes a begin transaction command before the following statements: delete, fetch, insert, lock table, open, select, and update. You cannot execute set chained within a transaction.
enables or disables character set conversion between Adaptive Server and a client. If the client is using Open Client DB-Library release 4.6 or later, and the client and server use different character sets, conversion is turned on during the login process and is set to a default based on the character set the client is using. You can also use set char_convert charset to start conversion between the server character set and a different client character set.
charset can be either the character set’s ID or a name from syscharsets with a type value of less than 2000.
set char_convert off turns conversion off so that characters are sent and received unchanged. set char_convert on turns conversion on if it is turned off. If character set conversion was not turned on during the login process or by the set char_convert command, set char_convert on generates an error message.
If you request character set conversion with set char_convert charset, and Adaptive Server cannot perform the requested conversion, the conversion state remains the same as it was before the request. For example, if conversion is set to off prior to the set char_convert charset command, conversion remains turned off if the request fails.
When the with no_error option is included, Adaptive Server does not notify an application when characters from Adaptive Server cannot be converted to the client’s character set. Error reporting is initially turned on when a client connects with Adaptive Server: if you do not want error reporting, you must turn it off for each session with set char_convert {on | charset} with no_error. To turn error reporting back on within a session, use set char_convert {on | charset} with error.
Whether or not error reporting is turned on, the bytes that cannot be converted are replaced with ASCII question marks (?).
See the System Administration Guide for a more complete discussion of error handling in character set conversion.
determines whether Component Integration Services handles outbound remote procedure call (RPC) requests by default.
assigns an application an individual name. This is useful for differentiating among clients in a system where many clients connect to Adaptive Server using the same application name. After you assign a new name to an application, it appears in the sysprocesses table under the new name.
assigns a host an individual name. This is useful for differentiating among clients in a system where many clients connect to Adaptive Server using the same host name. After you assign a new name to a host, it appears in the sysprocesses table under the new name.
assigns a client an individual name. This is useful for differentiating among clients in a system where many clients connect to Adaptive Server using the same client name. After you assign a new name to a user, they appear in the sysprocesses table under the new name.
causes Adaptive Server to close all cursors opened within a transaction at the end of that transaction. A transaction ends by the use of either the commit or rollback statement. However, only cursors declared within the scope that sets this option (stored procedure, trigger, and so on) are affected. For more information about cursor scopes, see the Transact-SQL User’s Guide.
For more information about the evaluated configuration, see the System Administration Guide.
causes Adaptive Server to return the number of rows for each cursor fetch request from a client application. The number can be a numeric literal with no decimal point or a local variable of type integer. If the number is less than or equal to zero, the value is set to 1. You can set the cursor rows option for a cursor, whether it is open or closed. However, this option does not affect a fetch request containing an into clause. cursor_name specifies the cursor for which to set the number of rows returned.
uses numeric settings to specify the first day of the week. The us_english language default is Sunday. To set the first day of the week, use the following:
To set the first day of the week as |
Use this setting |
---|---|
Monday |
1 |
Tuesday |
2 |
Wednesday |
3 |
Thursday |
4 |
Friday |
5 |
Saturday |
6 |
Sunday (us_english language default) |
7 |
Regardless of which day you set as the first day of the week, the value of that first day becomes 1. This value is not the same as the numeric setting you use in set datefirst n. For example, if you set Sunday as your first day of the week, its value is 1. If you set Monday as your first day of the week, Monday’s value becomes 1. If you set Wednesday as your first day of the week, Wednesday’s value becomes 1, and so on.
sets the order of the date parts month/day/year for entering datetime , smalldatetime, date or time data. Valid arguments are mdy, dmy, ymd, ydm, myd, and dym. The us_english language default is mdy.
when set to true, causes any attempts to start an implicit transaction, or send an RPC to a remote server outside a transaction, to fail.All other commands succeed.
determines whether Adaptive Server displays a warning message when Transact-SQL extensions to entry-level ANSI SQL are used. By default, Adaptive Server does not tell you when you use nonstandard SQL. This option does not disable SQL extensions. Processing completes when you issue the non-ANSI SQL command.
determines when Adaptive Server returns messages to the user. By default, messages are stored in a buffer until the query that generated them is completed or the buffer is filled to capacity. Use set flushmessage on to return messages to the user immediately, as they are generated.
causes the query optimizer to use the order of the tables in the from clause of a query as the join order for the query plan. forceplan is generally used when the optimizer fails to choose a good plan. Forcing an incorrect plan can have severely bad effects on I/O and performance. For more information, see the Performance and Tuning Guide.
determines whether explicit inserts into a table’s IDENTITY column are allowed. (Updates to an IDENTITY column are never allowed.) This option can be used only with base tables. It cannot be used with views or set within a trigger.
Setting identity_insert table_name on allows the table owner, Database Owner, or System Administrator to explicitly insert a value into an IDENTITY column. Inserting a value into the IDENTITY column allows you to specify a seed value for the column or to restore a row that was deleted in error. Unless you have created a unique index on the IDENTITY column, Adaptive Server does not verify the uniqueness of the inserted value; you can insert any positive integer.
The table owner, Database Owner, or System Administrator can use the set identity_insert table_name on command on a table with an IDENTITY column to enable the manual insertion of a value into an IDENTITY column. However, only the following users can actually insert a value into an IDENTITY column, when identity_insert is on:
Table owner
Database Owner:
if granted explicit insert permission on the column by the table owner
impersonating the table owner by using the setuser command
Setting identity_insert table_name off restores the default behavior by prohibiting explicit inserts to IDENTITY columns. At any time, you can use set identity_insert table_name on for a single database table within a session.
With set identity_update on, you can explicitly update the value of the IDENTITY column on a table. identity_update changes the identity column value for the qualified rows. When identity_update is enabled, you can update the identity value to any value greater than 0. However, if the input value is greater than the identity burn max value, a new set of ID values is allocated, and the identity burn max value on the OAM page is updated accordingly. If update is included in a transaction, the new identity burn max value cannot be rolled back. You can use syb_identity to point to the identity column for update. For example:
update table_name set syb_identity = value where clause
Adaptive Server does not check for duplicates entries or verify that entries are unique. You can update an existing value to any positive integer within the range allowed by the column's declared precision. You can check for duplicate entries by creating a unique index on the identity column
toggles join transitive closure. For more information, see the Performance and Tuning Guide.
is the official name of the language that displays system messages. The language must be installed on Adaptive Server. The default is us_english.
controls the display of rows affected by a statement. set nocount on disables the display of rows; set nocount off reenables the count of rows.
compiles each query but does not execute it. noexec is often used with showplan. After you set noexec on, no subsequent commands are executed (including other set commands) until you set noexec off.
compiles each subsequent query but does not execute it. set fmtonly on is often used with showplan for troubleshooting. Set noexec on immediately after executing a query. After you set noexec on, no subsequent commands are executed (including other set commands) until you set noexec off. set noexec can be used in stored procedures.
specifies the length of time that a command waits to acquire locks before aborting and returning an error.
specifies the number of seconds a command is to wait to acquire a lock. Valid values are from 0 to 2147483647, the maximum value for an integer.
specifies that if a command cannot acquire a lock immediately, it returns an error and fails. set lock nowait is equivalent to set lock wait 0.
returns the position of specified keywords (with relation to the beginning of the query) in Transact-SQL statements. The keyword list is a comma-separated list that can include any of the following Transact-SQL constructs: select, from, order, compute, table, procedure, statement, param, and execute. Adaptive Server returns offsets if there are no errors. This option is used in Open Client DB-Library only.
specifies an upper limit for the number of worker processes used in the parallel execution of a query. This number must be less than or equal to the number of worker processes per query, as set by the max parallel degree configuration parameter. The @@parallel_degree global variable stores the current setting.
checks the syntax of each query and returns any error messages without compiling or executing the query. Do not use parseonly inside a stored procedure or trigger.
introduces an abstract plan command. For more information, see Chapter 30, “Creating and Using Abstract Plans,” in the Performance and Tuning Guide.
enables or disables capturing abstract plans for the current connection. If a group_name is not specified, the plans are stored in the default group, ap_stdout.
enables or disables loading abstract plans for the current connection. If a group_name is not specified, the plans are loaded from the default group, ap_stdin.
is the name of the abstract plan group to use for loading or storing plans.
when used with set plan load, stores hash keys for up to 20 queries from an abstract plan group in a per-user cache.
enables or disables replacing existing abstract plans during plan capture mode. By default, plan replacement is off.
enables or disables large I/Os to the data cache.
controls sending of output parameters that a stored procedure generates back to the client. set proc_output_params off suppresses sending the output parameters back to the client. The default for this parameter is on.
controls sending of a return status TDS token back
to the client. set proc_return_status
off suppresses sending the return status token to the
client, and isql client does not display the (return
status = 0)
message. The default for
this parameter is on.
WARNING! If the client application that executes a procedure relies on the success or failure of the procedure based on the return status, then do not use the set proc_return_status off option.
specifies whether Adaptive Server executes parallel queries when an insufficient number of worker processes is available. Under these circumstances, when process_limit_action is set to quiet, Adaptive Server silently adjusts the plan to use a degree of parallelism that does not exceed the number of available processes. If process_limit_action is set to warning when an insufficient number of worker processes are available, Adaptive Server issues a warning message when adjusting the plan; and if process_limit_action is set to abort, Adaptive Server aborts the query and issues an explanatory message an insufficient number of worker processes are available.
returns the ID number of the stored procedure to Open Client DB-Library/C (not to the user) before sending rows generated by the stored procedure.
allows you to assume the permissions, login name, and suid (server user ID) of login_name. For login_name, specify a valid login from master..syslogins, enclosed in quotation marks. To revert to your original login name and suid, use set proxy with your original login_name.
Without explicit permission, neither the “sa_role” nor the “sso_role” can issue the set proxy login_name command. To use set proxy login_name, any user, including the System Security Officer, must have permission explicitly granted by the System Security Officer.
See “Using proxies” for more information.
determines whether Adaptive Server recognizes delimited identifiers. By default, quoted_identifier is off and all identifiers must conform to the rules for valid identifiers. If you use set quoted_identifier on, you can use table, view, and column names that begin with a nonalphabetic character, include characters that would not otherwise be allowed, or are reserved words, by enclosing the identifiers within double quotation marks. Delimited identifiers cannot exceed 28 bytes, may not be recognized by all front-end products, and may produce unexpected results when used as parameters to system procedures.
When quoted_identifier is on, all character strings enclosed within double quotes are treated as identifiers. Use single quotes around character or binary strings.
turns the specified role on or off during the current session. When you log in, all system roles that have been granted to you are turned on. Use set role role_name off to turn a role off, and set role role_name on to turn it back on again, as needed. System roles are “sa_role”, “sso_role”, and “oper_role”. If you are not a user in the current database, and if there is no “guest” user, you cannot set sa_role off, because there is no server user ID for you to assume.
is the name of any user-defined role created by the System Security Officer. User-defined roles are not turned on by default. To set user-defined roles to activate at login, the user or the System Security Officer must use set role on.
specifies the password to activate the role. If a user-defined role has an attached password, you must specify the password to activate the role.
causes Adaptive Server to stop processing the query (select, insert, update, or delete) after the specified number of rows are affected. The number can be a numeric literal with no decimal point or a local variable of type integer. To turn this option off, use:
set rowcount 0
specifies the maximum session-specific degree of parallelism for hash-based scans (parallel index scans and parallel table scans on nonpartitioned tables). This number must be less than or equal to the current value of the max scan parallel degree configuration parameter. The @@scan_parallel_degree global variable stores the current setting.
determines whether Adaptive Server allows triggers to cause themselves to fire again (this is called self recursion). By default, Adaptive Server does not allow self recursion in triggers. You can turn this option on only for the duration of a current client session; its effect is limited by the scope of the trigger that sets it. For example, if the trigger that sets self_recursion on returns or causes another trigger to fire, this option reverts to off. This option works only within a trigger and has no effect on user sessions.
is identical to set proxy, with this exception: set session authorization follows the SQL standard, while set proxy is a Transact-SQL extension.
generates a description of the processing plan for the query. The results of showplan are of use in performance diagnostics. showplan does not print results when it is used inside a stored procedure or trigger. For parallel queries, showplan output also includes the adjusted query plan at runtime, if applicable. For more information, see the Performance and Tuning Guide.
enables or disables the use of sort-merge joins during a session. For more information, see the Performance and Tuning Guide.
generates a description of the sorting plan for a create index statement. The results of sort_resources are of use in determining whether a sort operation will be done serially or in parallel. When sort_resouces is on, Adaptive Server prints the sorting plan but does not execute the create index statement. For more information, see Chapter 24, “Parallel Sorting,” in the Performance and Tuning Guide.
displays the following statistics information for each table referenced in the statement:
the number of times the table is accessed (scan count)
the number of logical reads (pages accessed in memory)
and the number of physical reads (database device accesses)
For each command, statistics io displays the number of buffers written.
If Adaptive Server has been configured to enforce resource limits, statistics io also displays the total I/O cost. For more information, see Chapter 34, “Using the set statistics Commands” in the Performance and Tuning Guide.
displays the number of cache hits, misses, and the number of rows in the subquery cache for each subquery.
displays the amount of time Adaptive Server used to parse and compile for each command. For each step of the command, statistics time displays the amount of time Adaptive Server used to execute the command. Times are given in milliseconds and timeticks, the exact value of which is machine-dependent.
specifies that the optimizer should use simulated statistics to optimize the query.
determines whether the server propagates transactions to servers that do not support Adaptive Server transaction coordination services. The default value is inherited from the value of the strict dtm enforcement configuration parameter.
determines whether Adaptive Server raises a SQLSTATE exception when an insert or update command truncates a char, unichar, varchar or univarchar string. If the truncated characters consist only of spaces, no exception is raised. The default setting, off, does not raise the SQLSTATE exception, and the character string is silently truncated.
sets the number of tables that Adaptive Server considers at one time while optimizing a join. The default used depends on the number of tables in the join:
Tables joined |
Tables considered at a time |
---|---|
2 – 25 |
4 |
26 – 37 |
3 |
38 – 50 |
2 |
Valid values are 0 – 8. A value of 0 resets the default behavior. A value greater than 8 defaults to 8. table count may improve the optimization of certain join queries, but it increases the compilation cost.
specifies the maximum size in bytes of text or image type data that is returned with a select statement. The @@textsize global variable stores the current setting. To reset textsize to the default size (32K), use:
set textsize 0
The default setting is 32K in isql. Some client software sets other default values.
sets the transaction isolation level for your session. After you set this option, any current or future transactions operate at that isolation level.
scans at isolation level 0 do not acquire any locks. Therefore, the result set of a level 0 scan may change while the scan is in progress. If the scan position is lost due to changes in the underlying table, a unique index is required to restart the scan. In the absence of a unique index, the scan may be aborted.
By default, a unique index is required for a level 0 scan on a table that does not reside in a read-only database. You can override this requirement by forcing the Adaptive Server to choose a nonunique index or a table scan, as follows:
select * from table_name (index table_name)
Activity on the underlying table may cause the scan to be aborted before completion.
By default, Adaptive Server’s transaction isolation level is read committed or 1, which allows shared read locks on data.
prevents nonrepeatable reads.
specify isolation level 3, Adaptive Server applies a holdlock to all select and readtext operations in a transaction, which holds the queries’ read locks until the end of that transaction. If you also set chained mode, that isolation level remains in effect for any data retrieval or modification statement that implicitly begins a transaction.
controls the handling of remote procedure calls. If this option is set to on, when a transaction is pending, the RPC is coordinated by Adaptive Server. If this option is set to off, the remote procedure call is handled by the Adaptive Server site handler. The default value is inherited from the value of the enable xact coordination configuration parameter.
Tells Adaptive Server to evaluate NULL-valued operands of equality (=) and inequality (!=) comparisons and aggregate functions in compliance with the entry level ANSI SQL standard:
set ansinull on
When you use set ansinull on, aggregate functions and row aggregates raise the following SQLSTATE warning when Adaptive Server finds null values in one or more columns or rows:
Warning - null value eliminated in set function
If the value of either the equality or the inequality operands is NULL, the comparison’s result is UNKNOWN. For example, the following query returns no rows in ansinull mode:
select * from titles where price = null
If you use set ansinull off, the same query returns rows in which price is NULL.
Activates character set conversion, setting it to a default based on the character set the client is using. Adaptive Server also notifies the client or application when characters cannot be converted to the client’s character set:
set char_convert on with error
Specifies that Component Integration Services handles outbound RPC requests by default:
set cis_rpc_handling on
Assigns this user:
The client name alison
The host name money1
The application name webserver2
set clientname 'alison' set clienthostname 'money1' set clientapplname 'webserver2'
Returns five rows for each succeeding fetch statement requested by a client using test_cursor:
set cursor rows 5 for test_cursor
Inserts a value of 100 into the IDENTITY column of the stores_south table, then prohibits further explicit inserts into this column. Note the use of the syb_identity keyword; Adaptive Server replaces the keyword with the name of the IDENTITY column:
set identity_insert stores_south on go insert stores_south (syb_identity) values (100) go set identity_insert stores_south off go
Enables idenity_update and updates tables with values 1 and 10, respectively, then disables identity_update:
set identity_update t1 on update t1 set c2 = 10 where c1 =1 select * from t1
c1 c2 _ _ _ _ _ _ _ _ _ 1 10
set identity_update t1 off
Tells Adaptive Server to display a warning message if you use a Transact-SQL extension:
set fipsflagger on
Then, if you use nonstandard SQL, like this:
use pubs2 go
Adaptive Server displays:
SQL statement on line number 1 contains Non-ANSI text. The error is caused due to the use of use database.
Subsequent commands in the session or stored procedure return an error and fail if they cannot get requested locks immediately:
set lock nowait
Subsequent commands in the current session or stored procedure wait indefinitely long to acquire locks:
set lock wait
Subsequent commands in the session or stored procedure wait 5 seconds to acquire locks before generating an error message and failing:
set lock wait 5
Enables capturing abstract plans to the dev_plans group:
set plan dump dev_plans on
Enables loading of abstract plans from the dev_plans group for queries in the current session:
set plan load dev_plans on
Suppresses the output of parameter information:
1> create procedure sp_pout (@x int output) as select @x = @x + 1 2> go 1> set proc_output_params off 2> go 1> declare @x int 2> select @x = 1 3> exec sp_pout @x output 4> print "Value of @x returned from sproc is: %1!", @x 5> go
(1 row affected) (return status = 0) Value of @x returned from sproc is: 2
If you do not perform set proc_output_params
off, the output after (return status = 0)
includes
the following:
Return parameters: ----------- 2
Suppresses the output of both parameters and the return status TDS token:
set proc_output_params OFF go set proc_return_status OFF go declare @x int select @x = 2 exec sp_pout @x output print "Value of @x returned from sproc is: %1!", @x go(1 row affected) Value of @x returned from sproc is: 3 (1 row affected)
In addition, you can also suppress the lines reporting the number of rows affected to generate output with no extra messages using the set nocount on option before running this batch.
The user executing this command now operates within the server as the login “mary” and Mary’s server user ID:
set proxy "mary"
For each insert, update, delete, and select statement, Adaptive Server stops processing the query after it affects the first four rows. For example:
select title_id, price from titles
title_id price -------- ---------- BU1032 19.99 BU1111 11.95 BU2075 2.99 BU7832 19.99 (4 rows affected)
set rowcount 4
Tells Adaptive Server to treat any character string enclosed in double quotes as an identifier. The table name “!*&strange_table” and the column name “emp’s_name” are legal identifier names while quoted_identifier is on:
set quoted_identifier on go create table "!*&strange_table" ("emp’s_name" char(10), age int) go set quoted_identifier off go
Activates the “doctor” role. This command is used by users to specify the roles they want activated:
set role doctor_role on
Deactivates the user’s System Administrator role for the current session:
set role "sa_role" off
Activates the “doctor” role when the user enters the password:
set role doctor_role with passwd "physician" on
Deactivates the “doctor” role:
set role doctor_role off
Specifies a maximum degree of parallelism of 4 for parallel index scans and parallel table scans on nonpartitioned tables:
set scan_parallel_degree 4
An alternative way of stating example 5:
set session authorization "mary"
For each query, returns a description of the processing plan, but does not execute it:
set showplan, noexec on go select * from publishers go
Causes Adaptive Server to generate an exception when truncating a char, unichar, or nchar string:
set string_rtruncation on
If an insert or update statement would truncate a string, Adaptive Server displays:
string data, right truncation
Sets the limit on text or image data returned with a select statement to 100 bytes:
set textsize 100
Specifies that when a transaction is pending, the RPC is handled by the Component Integration Services access methods rather than by the Adaptive Server site handler:
set transactional_rpc on
All subsequent queries in the session run at the repeatable reads transaction isolation level:
set transaction isolation level 2
Implements read-locks with each select statement in a transaction for the duration of that transaction:
set transaction isolation level 3
Some set options can be grouped together, as follows:
parseonly, noexec, prefetch, showplan, rowcount, and nocount control the way a query is executed. It does not make sense to set both parseonly and noexec on. The default setting for rowcount is 0 (return all rows); the default for the others is off.
The statistics options display performance statistics after each query. The default setting for the statistics options is off. For more information about noexec, prefetch, showplan and statistics, see the Performance and Tuning Guide.
You can update up to 1024 columns in the set clause using literals, variables, or expressions returned from a subquery.
offsets and procid are used in DB-Library to interpret results from Adaptive Server. The default setting for these options is on.
datefirst, dateformat, and language affect date functions, date order, and message display. If used within a trigger or stored procedure, these options do not revert to their previous settings.
In the default language, us_english, datefirst is 1 (Sunday), dateformat is mdy, and messages are displayed in us_english. Some language defaults (including us_english) produce Sunday=1, Monday=2, and so on; others produce Monday=1, Tuesday=2, and so on.
set language implies that Adaptive Server should use the first weekday and date format of the language it specifies, but does not override an explicit set datefirst or set dateformat command issued earlier in the current session.
cursor rows and close on endtran affect the way Adaptive Server handles cursors. The default setting for cursor rows with all cursors is 1. The default setting for close on endtran is off.
chained and transaction isolation level allow Adaptive Server to handle transactions in a way that is compliant with the SQL standards.
fipsflagger, string_rtruncation, ansinull, ansi_permissions, arithabort, and arithignore affect aspects of Adaptive Server error handling and compliance to SQL standards.
The arithabort and arithignore options were redefined for version 10.0 and later. If you use these options in your applications, examine them to verify they are still producing the desired effect.
You can use the cis_rpc_handling and transactional_rpc options only when Component Integration Services is enabled.
When the quoted_identifier option is set to on, you do not need to use double quotes around an identifier if the syntax of the statement requires that a quoted string contain an identifier. For example:
set quoted_identifier on create table "1one" (c1 int)
However, object_id requires a string, so you must include the table name in quotes to select the information:
select object_id('1one')
----------------------- 896003192
You can include an embedded double quote in a quoted identifier by doubling the quote:
create table "embedded""quote" (c1 int)
However, there is no need to double the quote when the statement syntax requires the object name to be expressed as a string:
select object_id('embedded"quote')
parallel_degree and scan_parallel_degree limit the degree of parallelism for queries, if Adaptive Server is configured for parallelism. When you use these options, you give the optimizer a hint to limit parallel queries to use fewer worker processes than allowed by the configuration parameters. Setting these parameters to 0 restores the server-wide configuration values.
If you specify a number that is greater than the numbers allowed by the configuration parameters, Adaptive Server issues a warning message and uses the value set by the configuration parameter.
If you use the set command inside a trigger or stored procedure, most set options revert to their former settings after the trigger or procedure executes.
The following options do not revert to their former settings after the procedure or trigger executes, but remain for the entire Adaptive Server session or until you explicitly reset them:
datefirst
dateformat
identity_insert
language
quoted_identifier
If you specify more than one set option, the first syntax error causes all following options to be ignored. However, the options specified before the error are executed, and the new option values are set.
If you assign a user a client name, host name, or application name, these assignments are only active for the current session. You must reassign these the next time the user logs in. Although the new names appear in sysprocesses, they are not used for permission checks, and sp_who still shows the client connection as belonging to the original login. For more information about setting user processes, see the System Administration Guide.
All set options except showplan and char_convert take effect immediately. showplan takes effect in the following batch. Here are two examples that use set showplan on:
set showplan on select * from publishers go
pub_id pub_name city state ------- --------------------- ----------- --- 0736 New Age Books Boston MA 0877 Binnet & Hardley Washington DC 1389 Algodata Infosystems Berkeley CA (3 rows affected)
But:
set showplan on go select * from publishers go
QUERY PLAN FOR STATEMENT 1 (at line 1). STEP 1 The type of query is SELECT FROM TABLE publishers Nested iteration Table Scan Ascending Scan. Positioning at start of table. pub_id pub_name city state ------ -------------------- ---------- ---- 0736 New Age Books Boston MA 0877 Binnet & Hardley Washington DC 1389 Algodata Infosystems Berkeley CA (3 rows affected)
When you log in to Adaptive Server, all system-defined roles granted to you are automatically activated. User-defined roles granted to you are not automatically activated. To automatically activate user-defined roles granted to you, use sp_modifylogin. See sp_modifylogin in Reference Manual: Procedures. Use set role role_name on or set role role_name off to turn roles on and off.
For example, if you have been granted the System Administrator role, you assume the identity (and user ID) of Database Owner in the current database. To assume your real user ID, execute this command:
set role "sa_role" off
If you are not a user in the current database, and if there is no “guest” user, you cannot set sa_role off.
If the user-defined role you intend to activate has an attached password, you must specify the password to turn the role on. Thus, you would enter:
set role "role_name" with passwd "password" on
The behavior of the cis rpc handling configuration property and the set transactional_rpc commands changed with the introduction of ASTC. In versions earlier than 12.0, enabling cis rpc handling caused all RPCs to be routed through CIS’s Client-Library connection. As a result, whenever cis rpc handling was enabled, transactional_rpc behavior occurred whether or not it had been specifically set. As of Adaptive Server 12.0, this behavior has changed. If cis rpc handling is enabled and transactional_rpc is off, RPCs within a transaction are routed through the site handler. RPCs executed outside a transaction are sent via CIS’s Client-Library connection.
When Adaptive Server distributed transaction management services are enabled, you can place RPCs within transactions. These RPCs are called transactional RPCs. A transactional RPC is an RPC whose work can be included in the context of a current transaction. This remote unit of work can be committed or rolled back along with the work performed by the local transaction.
To use transactional RPCs, enable CIS and distributed transaction management with sp_configure, then issue the set transactional_rpc command. When set transactional_rpc is on and a transaction is pending, the Adaptive Server (as opposed to the Adaptive Server site handler) coordinates the RPC.
The set transactional_rpc command default is off. The set cis_rpc_handling command overrides the set transactional_rpc command. If you set cis_rpc_handling on, all outbound RPCs are handled by Component Integration Services.
See the Component Integration Services User’s Guide for a discussion of using set transactional_rpc, set cis_rpc_handling, and sp_configure.
Without explicit permission, neither the “sa_role” nor the “sso_role” can issue the set proxy login_name command. To use set proxy login_name, any user, including the System Security Officer, must have permission explicitly granted by the System Security Officer.
Before you can use the set proxy or set session authorization command, a System Security Officer must grant permission to execute set proxy or set session authorization from the master database.
Executing set proxy or set session authorization with the original login_name reestablishes your previous identity.
You cannot execute set proxy or set session authorization from within a transaction.
Adaptive Server permits only one level of login identity change. Therefore, after you use set proxy or set session authorization to change identity, you must return to your original identity before changing it again. For example, assume that your login name is “ralph”. To create a table as “mary”, create a view as “joe”, then return to your own login identity. Use the following statements:
set proxy "mary" create table mary_sales (stor_id char(4), ord_num varchar(20), date datetime) grant select on mary_sales to public set proxy "ralph" set proxy "joe" create view joes_view (publisher, city, state) as select stor_id, ord_num, date from mary_sales set proxy "ralph"
By default, an Adaptive Server task that cannot immediately acquire a lock waits until incompatible locks are released, then continues processing. This is equivalent to set lock wait with no value specified in the numsecs parameter.
You can set a server-wide lock wait period by using sp_configure with the lock wait period option.
lock wait period, with the session-level setting set lock wait nnn, is only applicable for user-defined tables. These settings have no influence on system tables.
A lock wait period defined at the session level or in a stored procedure with the set lock command overrides a server-level lock-wait period.
If set lock wait is used by itself, with no value for numsecs, all subsequent commands in the current session wait indefinitely to acquire requested locks.
sp_sysmon reports the number of times that tasks waiting for a lock could not acquire the lock within the waiting period.
The repeatable-reads isolation level, also known as transaction isolation level 2, holds locks on all pages read by the statement until the transaction completes.
A nonrepeatable read occurs when one transaction reads rows from a table and a second transaction can modify the same rows and commit the changes before the first transaction completes. If the first transaction rereads the rows, they now have different values, so the initial read is not repeatable. Repeatable reads hold shared locks for the duration of a transaction, blocking transactions that update the locked rows or rows on the locked pages.
You can load simulated statistics into a database using the simulate mode of the optdiag utility program. If set statistics simulate on has been issued in a session, queries are optimized using simulated statistics, rather than the actual statistics for a table.
Table 1-37 lists the global variables that contain information about the session options controlled by the set command.
Global variable |
Description |
---|---|
@@char_convert |
Contains 0 if character set conversion not in effect. Contains 1 if character set conversion is in effect. |
@@isolation |
Contains the current isolation level of the Transact-SQL program. @@isolation takes the value of the active level (0, 1, or 3). |
@@options |
Contains a hexadecimal representation of the session’s set options. |
@@parallel_degree |
Contains the current maximum parallel degree setting. |
@@rowcount |
Contains the number of rows affected by the last query. @@rowcount is set to 0 by any command that does not return rows, such as an if, update, or delete statement. With cursors, @@rowcount represents the cumulative number of rows returned from the cursor result set to the client, up to the last fetch request. @@rowcount is updated even when nocount is on. |
@@scan_parallel_degree |
Contains the current maximum parallel degree setting for nonclustered index scans. |
@@textsize |
Contains the limit on the number of bytes of text or image data a select returns. Default limit is 32K bytes for isql; the default depends on the client software. Can be changed for a session with set textsize. |
@@tranchained |
Contains the current transaction mode of the Transact-SQL program. @@tranchained returns 0 for unchained or 1 for chained. |
When fipsflagger is on, Adaptive Server displays a warning message when these extensions are used:
The installjava utility
The remove java command
Column and variable declarations that reference Java classes as datatypes
Statements that use Java-SQL expressions for member references
The status of fipsflagger does not affect arithmetic expressions performed by Java methods.
For more information about Java in the database, see Java in Adaptive Server Enterprise.
ANSI SQL – Compliance level: Transact-SQL extension.
The ANSI SQL standard specifies behavior that differs from Transact-SQL behavior in earlier Adaptive Server versions. Compliant behavior is enabled by default for all Embedded-SQL precompiler applications. Other applications needing to match this standard of behavior can use the set options listed in Table 1-38.
Option |
Setting |
---|---|
ansi_permissions |
on |
ansinull |
on |
arithabort |
off |
arithabort numeric_truncation |
on |
arithignore |
off |
chained |
on |
close on endtran |
on |
fipsflagger |
on |
quoted_identifier |
on |
string_rtruncation |
on |
transaction isolation level |
3 |
In general, set permission defaults to all users and no special permissions are required to use it. Exceptions include set role, set proxy, and set session authorization.
To use set role, a System Administrator or System Security Officer must have granted you the role. If you gain entry to a database only because you have a certain role, you cannot turn that role off while you are using the database. For example, if you are not normally authorized to use a database info_plan, but you use it as a System Administrator, Adaptive Server returns an error message if you try to set sa_role off while you are still in info_plan.
To use set proxy or set session authorization, you must have been granted permission by a System Security Officer.
Commands create trigger, fetch, grant, insert, lock table, revoke
Functions convert