4. PC DB-Net, PC Net Library, Powersoft Portfolio, Replication Agent, Replication
Driver, Replication Server Manager, Report-Execute, Report Workbench, Resource
Manager, RW-DisplayLib, RW-Library, SAFE, SDF, Secure SQL Server, Secure SQL
Toolset, SKILS, SQL Anywhere, SQL Code Checker, SQL Edit, SQL Edit/TPU, SQL
Server, SQL Server/CFT, SQL Server/DBM, SQL Server Manager, SQL Server
Monitor, SQL Station, SQL Toolset, SQR Developers Kit, SQR Execute, SQR
Toolkit, SQR Workbench, Sybase Client/Server Interfaces, Sybase Gateways,
Sybase Intermedia, Sybase Interplay, Sybase IQ, Sybase MPP, Sybase SQL Desktop,
Sybase SQL Lifecycle, Sybase SQL Workgroup, Sybase Synergy Program, Sybase
Virtual Server Architecture, Sybase User Workbench, SyBooks, System 10, System
11, the System XI logo, Tabular Data Stream, The Enterprise Client/Server
Company, The Online Information Center, Warehouse WORKS, Watcom SQL,
WebSights, WorkGroup SQL Server, XA-Library, and XA-Server are trademarks of
Sybase, Inc.
All other company and product names used herein may be trademarks or
registered trademarks of their respective companies.
Restricted Rights
Use, duplication, or disclosure by the government is subject to the restrictions set
forth in subparagraph (c)(1)(ii) of DFARS 52.227-7013 for the DOD and as set forth
in FAR 52.227-19(a)-(d) for civilian agencies.
Sybase, Inc., 6475 Christie Avenue, Emeryville, CA 94608.
11. List of Figures
Figure 3-1: File naming convention for database dumps ........................................................3-175
Figure 3-2: Dumping several databases to the same volume..................................................3-177
Figure 3-3: File naming convention for transaction log dumps..............................................3-190
Figure 3-4: Dumping three transaction logs to a single volume.............................................3-192
Figure 5-1: Nesting transaction statements................................................................................5-114
SQL Server Reference Manual xi
13. List of Tables
Table 1: Syntax statement conventions .....................................................................................xix
Table 2: Types of expressions used in syntax statements ..................................................... xxii
Table 2-1: Datatype categories .......................................................................................................2-1
Table 2-2: Range and storage size for SQL Server system datatypes.......................................2-2
Table 2-3: Precision and scale after arithmetic operations.........................................................2-7
Table 2-4: Automatic conversion of fixed-length datatypes......................................................2-7
Table 2-5: Integer datatypes .........................................................................................................2-10
Table 2-6: Valid integer values .....................................................................................................2-10
Table 2-7: Invalid integer values..................................................................................................2-11
Table 2-8: Valid decimal values ...................................................................................................2-12
Table 2-9: Invalid decimal values ................................................................................................2-12
Table 2-10: Approximate numeric datatypes...............................................................................2-14
Table 2-11: Money datatypes .........................................................................................................2-16
Table 2-12: Transact-SQL datatypes for storing dates and times..............................................2-20
Table 2-13: Date formats for datetime and smalldatetime datatypes ......................................2-21
Table 2-14: Examples of datetime entries .....................................................................................2-23
Table 2-15: Character datatypes.....................................................................................................2-25
Table 2-16: Storage of text and image data ..................................................................................2-36
Table 2-17: text and image global variables .................................................................................2-38
Table 3-1: Transact-SQL commands..............................................................................................3-1
Table 3-2: Information stored about referential integrity constraints ....................................3-17
Table 3-3: Row aggregate functions used with the compute clause ......................................3-32
Table 3-4: compute by clauses and detail rows .........................................................................3-38
Table 3-5: Relationship between nulls and column defaults...................................................3-50
Table 3-6: Duplicate row options.................................................................................................3-55
Table 3-7: Index options................................................................................................................3-55
Table 3-8: Rule binding precedence ............................................................................................3-71
Table 3-9: Variable-length datatypes used to store nulls .........................................................3-85
Table 3-10: Methods of integrity enforcement.............................................................................3-87
Table 3-11: Information stored about cross-database referential integrity constraints .........3-92
Table 3-12: Information stored about referential integrity constraints ..................................3-162
Table 3-13: Commands used to back up databases and logs ..................................................3-171
Table 3-14: Commands used to back up databases ..................................................................3-184
Table 3-15: @@sqlstatus values ....................................................................................................3-200
Table 3-16: Object access permissions.........................................................................................3-204
Table 3-17: Command and object permissions..........................................................................3-207
Table 3-18: Status values reported by sp_who ..........................................................................3-240
Table 3-19: Commands used to restore databases from dumps .............................................3-245
SQL Server Reference Manual xiii
14. Sybase SQL Server Release 11.0.x
Table 3-20: Commands used to restore databases ....................................................................3-254
Table 3-21: Effect of sort order choices .......................................................................................3-266
Table 3-22: SQL Server error return values................................................................................3-285
Table 3-23: Object access permissions.........................................................................................3-288
Table 3-24: Results of using aggregates with group by............................................................3-304
Table 3-25: Permissions required for update and delete..........................................................3-314
Table 3-26: Options to set for entry level SQL92 compliance..................................................3-325
Table 3-27: Comparing datatypes in union operations ............................................................3-336
Table 3-28: Comparison operators ..............................................................................................3-353
Table 3-29: Arithmetic operators .................................................................................................3-354
Table 3-30: Bitwise operators .......................................................................................................3-354
Table 3-31: Wildcard characters...................................................................................................3-356
Table 4-1: Transact-SQL functions.................................................................................................4-1
Table 4-2: Aggregate functions ......................................................................................................4-2
Table 4-3: Datatype conversion functions ....................................................................................4-9
Table 4-4: Display formats for date/time information.............................................................4-10
Table 4-5: Explicit, implicit, and unsupported datatype conversions ...................................4-12
Table 4-6: Date functions ..............................................................................................................4-19
Table 4-7: Date parts and their values ........................................................................................4-21
Table 4-8: Arguments used in mathematical functions............................................................4-24
Table 4-9: Mathematical functions ..............................................................................................4-25
Table 4-10: Row aggregate functions ............................................................................................4-29
Table 4-11: Arguments used in string functions .........................................................................4-33
Table 4-12: Function names, arguments, and results..................................................................4-34
Table 4-13: Arguments used in system functions .......................................................................4-40
Table 4-14: System functions, arguments, and results ...............................................................4-41
Table 4-15: text and image functions, arguments, and results ..................................................4-48
Table 5-1: Transact-SQL topics.......................................................................................................5-1
Table 5-2: System procedures used to manage auditing options .............................................5-4
Table 5-3: Control-of-flow keywords ..........................................................................................5-12
Table 5-4: @@sqlstatus values ......................................................................................................5-22
Table 5-5: Arithmetic operators ...................................................................................................5-33
Table 5-6: Truth tables for bitwise operations............................................................................5-34
Table 5-7: Examples of bitwise operations.................................................................................5-34
Table 5-8: Comparison operators ................................................................................................5-35
Table 5-9: Wildcard characters used with like...........................................................................5-37
Table 5-10: Truth tables for logical expressions...........................................................................5-38
Table 5-11: Comparison operators ................................................................................................5-62
Table 5-12: System procedures for login account management................................................5-67
Table 5-13: Conversion of fixed-length to variable-length datatypes ......................................5-71
Table 5-14: Column definition and null defaults ........................................................................5-75
xiv List of Tables
15. Sybase SQL Server Release 11.0.x
Table 5-15: Roles required for SQL commands ...........................................................................5-84
Table 5-16: Roles required for system procedures ......................................................................5-85
Table 5-17: Wildcard characters used in match strings ..............................................................5-88
Table 5-18: Comparison operators ................................................................................................5-94
Table 5-19: @@transtate values ....................................................................................................5-103
Table 5-20: DDL commands allowed in transactions ...............................................................5-106
Table 5-21: DDL commands not allowed in transactions ........................................................5-107
Table 5-22: How rollbacks affect processing..............................................................................5-115
Table 5-23: How rollbacks from errors affect processing.........................................................5-119
Table 5-24: Rollbacks caused by duplicate key errors or rules violations .............................5-120
Table 5-25: Global variables .........................................................................................................5-124
Table 5-26: Using square brackets to search for wildcard characters.....................................5-133
Table 5-27: Using the escape Clause ...........................................................................................5-134
SQL Server Reference Manual xv
17. Preface
The SQL Server Reference Manual is a two-volume guide to Sybase
SQL Server™ and the Transact-SQL® language. This volume,
Volume 1, includes information about datatypes, Transact-SQL
commands, built-in functions, and topics of general interest to
Transact-SQL users. Volume 2 contains information about system
procedures and catalog stored procedures.
Audience
This manual is intended as a reference tool for Transact-SQL users of
all levels. It provides basic syntax and usage information for every
command, function, system procedure, and catalog stored
procedure.
How to Use This Book
This manual consists of the following chapters:
• Chapter 1, “SQL Server Roadmap,” contains lists of tasks you can
do with SQL Server and tells you which commands, system
procedures, catalog stored procedures, built-in functions, and
global variables you can use to accomplish them and which
sections of this manual to read to get more information.
• Chapter 2, “System and User-Defined Datatypes,” describes the
system and user-defined datatypes that are supplied with SQL
Server and indicates how to use them to create user-defined
datatypes.
• Chapter 3, “Transact-SQL Commands,” contains reference
information for every Transact-SQL command. Particularly
complex commands, such as select, are divided into subsections.
For example, there are reference pages on the compute clause and
on the group by and having clauses of the select command.
• Chapter 4, “Transact-SQL Functions,” contains reference
information for the SQL Server aggregate functions, datatype
conversion functions, date functions, mathematical functions,
row aggregate functions, string functions, system functions, and
text and image functions.
SQL Server Reference Manual xvii
18. Related Documents Sybase SQL Server Release 11.0.x
• Chapter 5, “Transact-SQL Topics,” contains information about
topics of general interest. Each topic describes the commands,
system procedures, and functions that provide a particular type
of functionality in Transact-SQL.
• The Index contains entries for both volumes of the SQL Server
Reference Manual.
Related Documents
Other manuals that you may find useful are:
• SQL Server installation and configuration guide, which describes
the installation procedures for SQL Server and documents
operating system-specific system administration, security
administration, and tuning tasks.
• SQL Server Performance and Tuning Guide, which explains how to
tune SQL Server for maximum performance. The book includes
information about database design issues that affect
performance, query optimization, how to tune SQL Server for
very large databases, disk and cache issues, and the effects of
locking and cursors on performance.
• SQL Server Reference Supplement, which contains a list of Transact-
SQL reserved words, definitions of system tables, a description of
the pubs2 sample database, a list of SQL Server error messages,
and other reference information that is common to all the SQL
Server manuals.
• SQL Server Security Administration Guide, which explains how to
use the security features provided by SQL Server to control user
access to data. The manual includes information about how to
add users to the server, give them controlled access to database
objects and procedures, and manage remote servers.
• SQL Server Security Features User’s Guide, which explains how to
use the security features of SQL Server.
• SQL Server System Administration Guide, which provides in-depth
information about administering servers and databases. The
manual includes instructions and guidelines for managing
physical resources and user and system databases, and
specifying character conversion, international language, and sort
order settings.
xviii
19. Sybase SQL Server Release 11.0.x Conventions Used in This Manual
• SQL Server utility programs manual, which documents the
Sybase utility programs, such as isql and bcp that are executed at
the operating system level.
• Transact-SQL User’s Guide, which documents Transact-SQL,
Sybase’s enhanced version of the relational database language. It
serves as a textbook for beginning users of the database
management system.
• What’s New in Sybase SQL Server Release 11.0?, which describes the
new features in SQL Server release 11.0.
Conventions Used in This Manual
Formatting SQL Statements
SQL is a free-form language: there are no rules about the number of
words you can put on a line or where you must break a line.
However, for readability, all examples and syntax statements in this
manual are formatted so that each clause of a statement begins on a
new line. Clauses that have more than one part extend to additional
lines, which are indented.
SQL Syntax Conventions
The conventions for syntax statements in this manual are as follows:
Table 1: Syntax statement conventions
Key Definition
command Command names, command option names, utility names,
utility flags, and other keywords are in bold Courier in
syntax statements, and in bold Helvetica in paragraph text.
variable Variables, or words that stand for values that you fill in, are in
italics.
{ } Curly braces indicate that you choose at least one of the
enclosed options. Do not include braces in your option.
[ ] Brackets mean choosing one or more of the enclosed options is
optional. Do not include brackets in your option.
( ) Parentheses are to be typed as part of the command.
SQL Server Reference Manual xix
20. Conventions Used in This Manual Sybase SQL Server Release 11.0.x
Table 1: Syntax statement conventions (continued)
Key Definition
| The vertical bar means you may select only one of the options
shown.
, The comma means you may choose as many of the options
shown as you like, separating your choices with commas to be
typed as part of the command.
• Syntax statements (displaying the syntax and all options for a
command) are printed like this:
sp_dropdevice [device_name]
or, for a command with more options:
select column_name
from table_name
where search_conditions
In syntax statements, keywords (commands) are in normal font
and identifiers are in lowercase: normal font for keywords,
italics for user-supplied words.
• Examples showing the use of Transact-SQL commands are
printed like this:
select * from publishers
• Examples of output from the computer are printed like this:
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)
Case
You can disregard case when you type keywords:
SELECT is the same as Select is the same as select
SQL Server’s sensitivity to the case (upper or lower) of database
objects, such as table names, and data depends on the sort order
installed on your SQL Server. Case sensitivity can be changed for
single-byte character sets by reconfiguring SQL Server’s sort order.
(See the System Administration Guide for more information.)
xx
21. Sybase SQL Server Release 11.0.x Conventions Used in This Manual
Obligatory Options {You Must Choose At Least One}
• Curly Braces and Vertical Bars: Choose one and only one option.
{die_on_your_feet | live_on_your_knees |
live_on_your_feet}
• Curly Braces and Commas: Choose one or more options. If you
choose more than one, separate your choices with commas.
{cash, check, credit}
Optional Options [You Don’t Have to Choose Any]
• One Item in Square Brackets: You don’t have to choose it.
[anchovies]
• Square Brackets and Vertical Bars: Choose none or only one.
[beans | rice | sweet_potatoes]
• Square Brackets and Commas: Choose none, one, or more than
one option. If you choose more than one, separate your choices
with commas.
[extra_cheese, avocados, sour_cream]
Ellipsis: Do It Again (and Again)...
An ellipsis (...) means that you can repeat the last unit as many times
as you like. In this syntax statement, buy is a required keyword:
buy thing = price [cash | check | credit]
[, thing = price [cash | check | credit]]...
You must buy at least one thing and give its price. You may choose a
method of payment: one of the items enclosed in square brackets.
You may also choose to buy additional things: as many of them as
you like. For each thing you buy, give its name, its price, and
(optionally) a method of payment.
SQL Server Reference Manual xxi
22. If You Need Help Sybase SQL Server Release 11.0.x
Expressions
Several different types of expressions are used in SQL Server syntax
statements.
Table 2: Types of expressions used in syntax statements
Usage Definition
expression Can include constants, literals, functions,
column identifiers, variables or parameters
logical expression An expression that returns TRUE, FALSE, or
UNKNOWN
constant expression An expression that always returns the same
value, such as “5+3” or “ABCDE”
float_expr Any floating-point expression or expression
that implicitly converts to a floating value
integer_expr Any integer expression, or an expression that
implicitly converts to an integer value
numeric_expr Any numeric expression that returns a single
value
char_expr Any expression that returns a single
character-type value
binary_expression An expression that returns a single binary or
varbinary value
If You Need Help
Help with your Sybase software is available in the form of
documentation and Sybase Technical Support.
Each Sybase installation has a designated person who may contact
Technical Support. If you cannot resolve your problem using the
manuals, ask the designated person at your site to contact Sybase
Technical Support.
xxii
25. 1 SQL Server Roadmap 1.
This chapter helps you figure out how to use SQL Server to
accomplish particular tasks. It tells you which commands, functions,
global variables, system and catalog stored procedures, utility
programs, and global variables to use and which sections of the
documentation to read.
This chapter contains information about the following topics:
• Starting, Stopping, and Configuring SQL Server 1-3
• Creating and Maintaining Databases 1-9
• Setting Database-Wide Options 1-12
• Backing Up and Restoring Databases 1-14
• Managing Logins, Users, Groups, and Roles 1-17
• Defining and Using Datatypes 1-21
• Creating and Maintaining Tables 1-23
• Auditing Server Activity 1-31
• Retrieving and Manipulating Data 1-33
• Using Defaults and Rules 1-38
• Error Handling and Messages 1-40
• Using Global Variables to Get Information 1-42
• Using System and Catalog Stored Procedures to Get Help 1-45
• Managing Languages, Character Sets, and Sort Orders 1-49
• Managing Database Devices, Segments, and Thresholds 1-52
• Setting Session-Wide Options 1-56
• Using Stored Procedures and Triggers 1-59
• Managing Transactions 1-64
• Creating and Using Views 1-66
Each topic consists of a list of related tasks. For example, the topic
“Starting, Stopping, and Configuring SQL Server” includes such tasks
as “Starting and Stopping SQL Server,” “Displaying Current
Configuration Parameter Values,” and “Configuring Backup and
Recovery.”
SQL Server Reference Manual 1-1
26. Sybase SQL Server Release 11.0.x
Each task lists one or more related activities, plus the name of the
command or other syntactical element used to accomplish each
activity. For detailed information about syntax or usage, click on the
name of the command, function or procedure, or look in the
appropriate section of this manual. For detailed information about
utility commands, refer to your SQL Server utility programs manual.
1-2 SQL Server Roadmap
27. Sybase SQL Server Release 11.0.x Starting, Stopping, and Configuring SQL Server
Starting, Stopping, and Configuring SQL Server
This section contains information about the following tasks:
• Starting and Stopping SQL Server 1-3
• Displaying Current Configuration Parameter Values 1-3
• Configuring Backup and Recovery 1-3
• Configuring Cache Management 1-4
• Configuring Disk I/O 1-4
• Configuring Languages, Character Sets, and Sort Orders 1-4
• Configuring the Lock Manager 1-4
• Configuring Memory Use 1-5
• Configuring Network Communications 1-5
• Configuring Operating System Resources 1-5
• Configuring Physical Memory Resources 1-6
• Configuring SMP Processors 1-6
• Configuring Server Administration 1-6
• Configuring User Environments 1-7
Starting and Stopping SQL Server
Start a SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . dataserver, startserver
Stop a SQL Server after any executing statements complete . . . shutdown
Stop a SQL Server immediately. . . . . . . . . . . . . . . . . . . . . . . . . . . . shutdown with nowait
Displaying Current Configuration Parameter Values
Display current values for configuration parameters . . . . . . . . . sp_configure
Determine which parameters are displayed by sp_configure. . . . sp_displaylevel
Configuring Backup and Recovery
Specify how many days tapes are protected from overwrite . . . sp_configure “tape retention in
days”
Specify recovery speed in minutes . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “recovery interval
in minutes”
SQL Server Reference Manual 1-3
28. Starting, Stopping, and Configuring SQL Server Sybase SQL Server Release 11.0.x
Specify whether verbose recovery messages are displayed . . . . sp_configure “print recovery
information”
Configuring Cache Management
Determine boundary on which data caches are aligned . . . . . . . sp_configure “memory alignment
boundary”
Specify how long to keep index pages in cache . . . . . . . . . . . . . . sp_configure “number of index
trips”
Specify how long to keep OAM pages in cache . . . . . . . . . . . . . . sp_configure “number of oam
trips”
Specify memory allocated to procedure cache . . . . . . . . . . . . . . . sp_configure “procedure cache
size”
Determine memory available for data, index, and log pages . . . sp_configure “total data cache
size”
Configuring Disk I/O
Determine whether SQL Server runs with asynchronous I/O . . sp_configure “allow sql server
async i/o”
Specify number of disk I/O control blocks allocated. . . . . . . . . . sp_configure “disk i/o structures”
Specify maximum number of database devices . . . . . . . . . . . . . . sp_configure “number of
devices”
Determine whether server searches for unused pages . . . . . . . . sp_configure “page utilization
percent”
Configuring Languages, Character Sets, and Sort Orders
Specify the default character set . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “default character
set id”
Specify the default language for system messages. . . . . . . . . . . . sp_configure “default language
id”
Specify the default sort order. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “default sortorder
id”
Specify how many languages can be held in cache . . . . . . . . . . . sp_configure “number of
languages in cache”
Configuring the Lock Manager
Specify how many address locks are protected by a spinlock . . sp_configure “address lock
spinlock ratio”
1-4 SQL Server Roadmap
29. Sybase SQL Server Release 11.0.x Starting, Stopping, and Configuring SQL Server
Specify delay in milliseconds before deadlock checking. . . . . . . sp_configure “deadlock checking
period”
Specify number locks transferred between server and engine . . sp_configure “freelock transfer
block size”
Specify maximum number of locks available in an engine . . . . . sp_configure “max engine
freelocks”
Specify number of locks available for all users and engines. . . . sp_configure “number of locks”
Specify number of page lock structures protected per spinlock. sp_configure “page spinlock
ratio”
Specify number table lock structures protected per spinlock . . . sp_configure “table lock spinlock
ratio”
Configuring Memory Use
Determine size of SQL Server executable . . . . . . . . . . . . . . . . . . . sp_configure “executable code
size”
Configuring Network Communications
Enable connections to remote servers . . . . . . . . . . . . . . . . . . . . . . sp_configure “allow remote
access”
Specify default network packet size, in bytes, for all users . . . . . sp_configure “default network
packet size”
Specify maximum network packet size in bytes. . . . . . . . . . . . . . sp_configure “max network
packet size”
Specify how many network listeners can be open at one time . . sp_configure “max number
network listeners”
Specify the maximum number of remote connections. . . . . . . . . sp_configure “number of remote
connections”
Specify the maximum number of remote logins. . . . . . . . . . . . . . sp_configure “number of remote
logins”
Specify how many remote sites can access server at one time . . sp_configure “number of remote
sites”
Specify the number of pre-read packets. . . . . . . . . . . . . . . . . . . . . sp_configure “remote server pre-
read packets”
Enable/disable TCP packet batching . . . . . . . . . . . . . . . . . . . . . . . sp_configure “tcp no delay”
Configuring Operating System Resources
Limit outstanding asynchronous disk I/O requests per engine. sp_configure “max async i/o’s
per engine”
SQL Server Reference Manual 1-5
30. Starting, Stopping, and Configuring SQL Server Sybase SQL Server Release 11.0.x
Limit outstanding asynchronous disk I/O requests per server . sp_configure “max async i/o’s
per server”
Specify starting address for server’s shared memory region . . . sp_configure “shared memory
starting address”
Configuring Physical Memory Resources
Specify maximum additional memory for large packets. . . . . . . sp_configure “additional network
memory”
Prevent swapping of SQL Server pages to disk . . . . . . . . . . . . . . sp_configure “lock shared
memory”
Specify the memory, in 2K units, allocated for SQL Server. . . . . sp_configure “total memory”
Configuring SMP Processors
Specify the maximum number of online engines . . . . . . . . . . . . . sp_configure “max online
engines”
Specify the minimum number of online engines . . . . . . . . . . . . . sp_configure “min online
engines”
Configuring Server Administration
Allow triggers to fire other triggers . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “allow nested
triggers”
Allow updates to system tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “allow updates to
system tables”
Specify the maximum number of auditing records . . . . . . . . . . . sp_configure “audit queue size”
Specify the number of server clock ticks before flushing . . . . . . sp_configure “cpu accounting
flush interval”
Limit milliseconds a task can run before time slice error . . . . . . sp_configure “cpu grace time”
Specify the default database size. . . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “default database
size”
Specify the initial fullness of index pages . . . . . . . . . . . . . . . . . . . sp_configure “default fill factor
percent”
Limit percent increase in database writes by housekeeper task. sp_configure “housekeeper free
write percent”
Specify percentage of IDENTITY column values held in cache . sp_configure “identity burning
set factor”
Specify number of sequential values reserved per process. . . . . sp_configure “identity grab size”
Specify the number of disk I/Os before flushing . . . . . . . . . . . . . sp_configure “i/o accounting
flush interval”
1-6 SQL Server Roadmap
31. Sybase SQL Server Release 11.0.x Starting, Stopping, and Configuring SQL Server
Limit server tasks run before checking for I/O completions . . . sp_configure “i/o polling process
count”
Specify threshold for number of page locks per command. . . . . sp_configure “lock promotion
hwm”
Limit alarm structures allocated for waitfor commands . . . . . . . sp_configure “number of alarms”
Limit number of extents allocated as create index work buffers . sp_configure “number of extent
i/o buffers”
Limit mailbox structures for intertask communications . . . . . . . sp_configure “number of
mailboxes”
Limit message structures for intertask communications. . . . . . . sp_configure “number of
messages”
Specify the maximum number of open databases . . . . . . . . . . . . sp_configure “number of open
databases”
Specify the maximum number of open objects . . . . . . . . . . . . . . . sp_configure “number of open
objects”
Specify number of extents allocated per trip to page manager . sp_configure “number of pre-
allocated extents”
Specify how many buffers can hold pages from input tables . . . sp_configure “number of sort
buffers”
Include or exclude deadlock information from error log . . . . . . sp_configure “print deadlock
information”
Limit engine loops before relinquishing CPU. . . . . . . . . . . . . . . . sp_configure “runnable process
search count”
Limit number of partition groups allocated . . . . . . . . . . . . . . . . . sp_configure “partition groups”
Specify ratio of spinlocks to internal partition caches . . . . . . . . . sp_configure “partition spinlock
ratio”
Specify size of automatically created IDENTITY columns . . . . . sp_configure “size of auto
identity”
Limit amount of memory available for sort operations. . . . . . . . sp_configure “sort page count”
Specify length of clock tick in microseconds . . . . . . . . . . . . . . . . . sp_configure “sql server clock
tick length”
Specify number of milliseconds a task can run. . . . . . . . . . . . . . . sp_configure “time slice”
Determine the SQL Server version number. . . . . . . . . . . . . . . . . . sp_configure “upgrade version”
Configuring User Environments
Specify the maximum number of local connections. . . . . . . . . . . sp_configure “number of user
connections”
Specify number of cache protectors per task. . . . . . . . . . . . . . . . . sp_configure “permission cache
entries”
Specify size of stack guard area in bytes . . . . . . . . . . . . . . . . . . . . sp_configure “stack guard size”
Specify size of stack in bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_configure “stack size”
SQL Server Reference Manual 1-7
32. Starting, Stopping, and Configuring SQL Server Sybase SQL Server Release 11.0.x
Specify maximum duration of passwords . . . . . . . . . . . . . . . . . . . sp_configure “systemwide
password expiration”
Specify number of bytes in each user’s user log cache . . . . . . . . sp_configure “user log cache
size”
Specify number of user log caches per user log spinlock . . . . . . sp_configure “user log cache
spinlock ratio”
1-8 SQL Server Roadmap
33. Sybase SQL Server Release 11.0.x Creating and Maintaining Databases
Creating and Maintaining Databases
This section contains information about the following tasks:
• Building the System Databases 1-9
• Creating a User Database 1-9
• Adding Space to a Database 1-9
• Specifying the Current Database 1-10
• Changing the Database Owner (“dbo”) 1-10
• Checking Database Consistency 1-10
• Getting Help on Databases 1-10
• Moving the Transaction Log to Its Own Device 1-10
• Renaming a Database 1-10
• Removing a Database from a Server 1-11
Building the System Databases
Build the system databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . buildmaster, installmaster
Creating a User Database
Choose a valid database name
Choose a valid name for the database . . . . . . . . . . . . . . . . . . . . . . Identifiers
Check a potential database name for validity . . . . . . . . . . . . . . . . . valid_name()
Specify default database devices
Specify default database devices for the server . . . . . . . . . . . . . . sp_diskdefault
Create the database
Create a database with a separate log segment. . . . . . . . . . . . . . . create database...log on
Determine the default size for databases in megabytes. . . . . . . . sp_configure “default database
size”
Adding Space to a Database
Allocate additional space to a database . . . . . . . . . . . . . . . . . . . . . alter database, sp_dbremap
Find out how much space is used by database objects . . . . . . . . sp_spaceused
SQL Server Reference Manual 1-9
34. Creating and Maintaining Databases Sybase SQL Server Release 11.0.x
Specifying the Current Database
Identify the current database
Find a database’s ID number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . db_id()
Find the name of the current database . . . . . . . . . . . . . . . . . . . . . . db_name()
Use a different database
Find out whether the database is available for public use . . . . . sp_helpdb
Make the database available for public use . . . . . . . . . . . . . . . . . . online database
Use a different database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . use
Changing the Database Owner (“dbo”)
Find out who owns the database . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpuser dbo
Specify a new database owner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_changedbowner
Checking Database Consistency
Check consistency of indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_indsuspect
Check consistency of page allocations . . . . . . . . . . . . . . . . . . . . . . dbcc checkalloc
Check consistency of system tables . . . . . . . . . . . . . . . . . . . . . . . . dbcc checkcatalog
Check consistency of all tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . dbcc checkdb
Getting Help on Databases
Get help on databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpdb
List the databases on a SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . sp_databases
Moving the Transaction Log to Its Own Device
Move the transaction log to a separate device . . . . . . . . . . . . . . . sp_logdevice
Renaming a Database
Determine which databases need new names
Find out whether a database name is a reserved word . . . . . . . . sp_checkreswords
Choose a valid database name
Choose a valid name for the database . . . . . . . . . . . . . . . . . . . . . . Identifiers
Check a potential database name for validity . . . . . . . . . . . . . . . . . valid_name()
1-10 SQL Server Roadmap
36. Setting Database-Wide Options Sybase SQL Server Release 11.0.x
Setting Database-Wide Options
This section contains information about the following tasks:
• Listing Current Database Option Settings 1-12
• Putting New Settings into Effect 1-12
• Setting Options That Affect Backup and Recovery 1-12
• Setting Options That Affect bcp, select into, and writetext 1-12
• Setting Options That Affect Checkpoints 1-13
• Setting Options That Affect IDENTITY Columns 1-13
• Specifying the Default Null Type for a Database 1-13
• Specifying Whether Users Can Update the Database 1-13
• Setting Options That Affect Thresholds 1-13
• Setting Options That Affect Transaction Management 1-13
Listing Current Database Option Settings
List database options and their current settings . . . . . . . . . . . . . . sp_helpdb
Putting New Settings into Effect
Put new option settings into effect . . . . . . . . . . . . . . . . . . . . . . . . . checkpoint
Setting Options That Affect Backup and Recovery
Abort transactions when the log becomes full . . . . . . . . . . . . . . . sp_dboption “abort tran on log
full”
Checkpoint database automatically after recovery . . . . . . . . . . . sp_dboption “no chkpt on
recovery”, “false”
Truncate the log automatically after checkpoints . . . . . . . . . . . . . sp_dboption “trunc log on chkpt”
Setting Options That Affect bcp, select into, and writetext
Allow fast bcp in a database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “select
into/bulkcopy”
Allow select into on permanent tables. . . . . . . . . . . . . . . . . . . . . . . sp_dboption “select
into/bulkcopy”
1-12 SQL Server Roadmap
37. Sybase SQL Server Release 11.0.x Setting Database-Wide Options
Allow writetext in a database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “select
into/bulkcopy”
Setting Options That Affect Checkpoints
Clear the transaction log after automatic checkpoints. . . . . . . . . sp_dboption “trunc log on chkpt”
Perform automatic checkpoints after recovery . . . . . . . . . . . . . . . sp_dboption “no chkpt on
recovery”
Setting Options That Affect IDENTITY Columns
Automatically create an IDENTITY column in new tables . . . . . sp_dboption “auto identity”
Include IDENTITY columns in indexes for all tables. . . . . . . . . . sp_dboption “identity in
nonunique index”, true
Specifying the Default Null Type for a Database
Set the default null type for columns . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “allow nulls by
default”
Specifying Whether Users Can Update the Database
Lock users out of a database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “dbo use only”
Set single-user mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “single user”
Prohibit updates to a database . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “read only”
Setting Options That Affect Thresholds
Disable nonlog thresholds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_dboption “no free space
acctg”
List database options and their current settings . . . . . . . . . . . . . . sp_helpdb
Setting Options That Affect Transaction Management
Abort transactions when the log is full . . . . . . . . . . . . . . . . . . . . . sp_dboption “abort tran on log
full”
Allow data definition language in transactions . . . . . . . . . . . . . . sp_dboption “ddl in tran”
SQL Server Reference Manual 1-13
38. Backing Up and Restoring Databases Sybase SQL Server Release 11.0.x
Backing Up and Restoring Databases
This section contains information about the following tasks:
• Adding a Backup Server to a SQL Server 1-14
• Getting Help on Backup Servers 1-14
• Starting and Stopping Backup Servers 1-14
• Backing Up a Database After a Device Failure 1-14
• Backing Up a Database When Its Transaction Log Is Full 1-15
• Performing Routine Backups of User Databases 1-15
• Restoring User Databases from Backups 1-15
• Restoring Backups of Release 10.x Databases 1-16
• Trimming a Database’s Transaction Log 1-16
Adding a Backup Server to a SQL Server
Choose a valid name for the Backup Server . . . . . . . . . . . . . . . . . Identifiers
Add or change a Backup Server . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_addserver
Getting Help on Backup Servers
Get help on Backup Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpserver
List the Backup Servers running on the local machine . . . . . . . . . showserver
Starting and Stopping Backup Servers
Start a Backup Server
Start a Backup Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . backupserver, startserver
Stop a Backup Server
Find out the name of the Backup Server . . . . . . . . . . . . . . . . . . . . sp_helpserver
Stop a Backup Server after active dumps and loads complete . . shutdown
Stop a Backup Server immediately . . . . . . . . . . . . . . . . . . . . . . . . . shutdown with nowait
Backing Up a Database After a Device Failure
Back up a database after its database device fails. . . . . . . . . . . . . dump transaction with
no_truncate
1-14 SQL Server Roadmap
39. Sybase SQL Server Release 11.0.x Backing Up and Restoring Databases
Backing Up a Database When Its Transaction Log Is Full
Copy and trim log without recording transaction . . . . . . . . . . . . dump transaction with no_log
Make backup after trimming log . . . . . . . . . . . . . . . . . . . . . . . . . . dump database
Performing Routine Backups of User Databases
Create a device to be used for backup and recovery
Add a dump device to a SQL Server . . . . . . . . . . . . . . . . . . . . . . . sp_addumpdevice
Allow users other than the owner to back up a database
Allow a user to back up and restore the database . . . . . . . . . . . . sp_role “grant” oper_role
Make regular backups of the database
Copy the entire database, including transaction log . . . . . . . . . . dump database
Back up the transaction log in between full database backups
Copy the transaction log then trim it . . . . . . . . . . . . . . . . . . . . . . . . . dump transaction
Reply to Backup Server prompts while backing up the database
Reply to Backup Server prompts . . . . . . . . . . . . . . . . . . . . . . . . . . sp_volchanged
Restoring User Databases from Backups
Create an empty database into which you will load the backup
Create an empty database to receive the backup . . . . . . . . . . . . . create database for load, alter
database for load
Make sure you have the right tape
Find out which backup files are on the tape . . . . . . . . . . . . . . . . . load database with listonly, load
transaction with listonly
Restore the most recent backup of the database
Restore the database from the most recent backup . . . . . . . . . . . load database
Reply to Backup Server prompts while restoring the database
Reply to Backup Server prompts . . . . . . . . . . . . . . . . . . . . . . . . . . sp_volchanged
Restore the transaction logs in the order made
Restore transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . load transaction
Make the restored database available for use
Find out whether the database is available for public use . . . . . sp_helpdb
Make the database available for public use . . . . . . . . . . . . . . . . . . online database
SQL Server Reference Manual 1-15
40. Backing Up and Restoring Databases Sybase SQL Server Release 11.0.x
Restoring Backups of Release 10.x Databases
Create a database to load the backup into
Create an empty database to receive the backup . . . . . . . . . . . . . create database for load
Add additional space to the new database . . . . . . . . . . . . . . . . . . . . alter database for load
Load the release 10.x database
Load the release 10.x database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . load database
Upgrade the database
Upgrade the database to current SQL Server version . . . . . . . . . online database
Back up the database
Back up the newly upgraded database . . . . . . . . . . . . . . . . . . . . . dump database
Determine which object names are currently reserved words
Identify object names that are reserved words . . . . . . . . . . . . . . . sp_checkreswords
Find procedures, triggers, and views that depend on these objects
Identify dependent procedures, views, triggers . . . . . . . . . . . . . . sp_depends
Store definitions of dependent objects
Copy definitions of dependent objects to file . . . . . . . . . . . . . . . . . . defncopy
Print definitions of dependent objects . . . . . . . . . . . . . . . . . . . . . . sp_helptext
Drop the dependent objects
Remove dependent objects from database . . . . . . . . . . . . . . . . . . drop procedure, drop trigger,
drop view
Choose new, valid names for the objects
Change object names that are reserved words . . . . . . . . . . . . . . . sp_rename
Re-create the dependent objects
Re-create dependent objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . create procedure, create trigger,
create view
Back up the database
Back up the database after re-creating dependent objects. . . . . . dump database
Trimming a Database’s Transaction Log
Move the transaction log to its own device
Move the transaction log to a separate device . . . . . . . . . . . . . . . sp_logdevice
Trim the transaction log
Trim the transaction log without making a copy . . . . . . . . . . . . . dump transaction with
truncate_only
Trim a transaction log after with truncate_only option fails . . . . . . dump transaction with no_log
Back up the database after trimming the transaction log . . . . . . dump database
1-16 SQL Server Roadmap
41. Sybase SQL Server Release 11.0.x Managing Logins, Users, Groups, and Roles
Managing Logins, Users, Groups, and Roles
This section contains informtion about the following tasks:
• Creating New Users 1-17
• Getting Help on Users 1-17
• Managing Passwords 1-17
• Using Groups 1-18
• Using Roles 1-18
• Using Aliases 1-19
• Changing the Characteristics of a Login 1-19
• Impersonating Another User 1-19
• Managing User Permissions 1-19
• Managing Remote Users 1-19
• Monitoring User Activity 1-19
• Preventing a User from Accessing the Server 1-20
Creating New Users
Read about SQL Server logins . . . . . . . . . . . . . . . . . . . . . . . . . . Login Management
Create a SQL Server login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_addlogin
Add a SQL Server login as a user in the current database . . . . . sp_adduser
Getting Help on Users
Get help on a database user or all users . . . . . . . . . . . . . . . . . . . . . sp_helpuser
Confirm that a login is a database user or alias. . . . . . . . . . . . . . . valid_user()
Get help on local users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_displaylogin, sp_who
Find out a database user’s ID number . . . . . . . . . . . . . . . . . . . . . . user_id()
Find out the current user’s name . . . . . . . . . . . . . . . . . . . . . . . . . . user, user_name()
Find out the name of a SQL Server login . . . . . . . . . . . . . . . . . . . . suser_name()
Find out the server user ID of a SQL Server login . . . . . . . . . . . . suser_id()
Managing Passwords
Add a password for a SQL Server login. . . . . . . . . . . . . . . . . . . . . sp_password
SQL Server Reference Manual 1-17
42. Managing Logins, Users, Groups, and Roles Sybase SQL Server Release 11.0.x
Change a password for a SQL Server login . . . . . . . . . . . . . . . . . . sp_password
Using Groups
Manage permissions through groups
Find out what permissions are assigned to a group. . . . . . . . . . . sp_helprotect
Remove permissions from a group. . . . . . . . . . . . . . . . . . . . . . . . . revoke
Grant permissions to a group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grant
Create a group
Create a group in the current database . . . . . . . . . . . . . . . . . . . . . sp_addgroup
List the groups in the current database
List the groups in the current database . . . . . . . . . . . . . . . . . . . . . sp_helpgroup
List the members of a group
List the members of a group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpgroup
Remove a user from a group or change a user’s group
Change a user’s group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_changegroup
Remove a group from a database
List the members of the group. . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpgroup
Remove each member from the group . . . . . . . . . . . . . . . . . . . . . . sp_changegroup
Remove the group from the current database. . . . . . . . . . . . . . . . sp_dropgroup
Using Roles
Get general information about roles
Read about roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Roles
Manage permissions through roles
Confer permissions on a role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grant
Find out what permissions are granted to a role . . . . . . . . . . . . . sp_helprotect
Get help on permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helprotect
Revoke permissions from a role . . . . . . . . . . . . . . . . . . . . . . . . . . . revoke
Verify that a user has a particular role
Verify that a user has a required role . . . . . . . . . . . . . . . . . . . . . . . proc_role()
Assign a role to a user
Assign a role to a SQL Server login. . . . . . . . . . . . . . . . . . . . . . . . . sp_role
Turn a role on or off for a session
Activate or deactivate a role for a session . . . . . . . . . . . . . . . . . . . set role
Display a user’s currently active roles . . . . . . . . . . . . . . . . . . . . . . show_role()
1-18 SQL Server Roadmap
43. Sybase SQL Server Release 11.0.x Managing Logins, Users, Groups, and Roles
Revoke a role from a user
Revoke a role from a SQL Server login. . . . . . . . . . . . . . . . . . . . . . sp_role
Using Aliases
Create an alias in the current database for a server login . . . . . . sp_addalias
List the SQL Server logins mapped to an alias . . . . . . . . . . . . . . . sp_helpuser
Remove an alias from the current database. . . . . . . . . . . . . . . . . . sp_dropalias
Changing the Characteristics of a Login
Change a login’s default database or language . . . . . . . . . . . . . . sp_modifylogin
Rename a login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_modifylogin
Impersonating Another User
Temporarily impersonate another database user . . . . . . . . . . . . . setuser
Managing User Permissions
Grant permissions to a user, group, or role . . . . . . . . . . . . . . . . . . grant
Get help on permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helprotect
Revoke permissions from a user, group, or role . . . . . . . . . . . . . . revoke
Managing Remote Users
Allow a remote login to execute local stored procedures . . . . . . sp_addremotelogin
Display or change remote server option settings . . . . . . . . . . . . . sp_remoteoption
Get help on remote server logins . . . . . . . . . . . . . . . . . . . . . . . . . . sp_helpremotelogin
Remove a remote login from the local server . . . . . . . . . . . . . . . . sp_dropremotelogin
Require password verification from remote logins . . . . . . . . . . . sp_remoteoption “trusted”
Remove a remote server and its logins. . . . . . . . . . . . . . . . . . . . . . sp_dropserver...droplogin
Monitoring User Activity
Audit a user
Audit a login’s object access and command batches . . . . . . . . . . sp_auditlogin
SQL Server Reference Manual 1-19