alter database

Description

Increases the amount of space allocated to a database, as well as to the modified pages section of an archive database.

Syntax

alter database database_name 
	[on {default | database_device} [= size]
		[, database_device [= size]]...] 
	[log on {default | database_device} [= size]
		[, database_device [= size]]...] 
	set { [durability = { no_recovery | at_shutdown | full}]
      		 [[,] dml_logging = {full | minimal} ]
    		 [[,] template = { database_name | NULL}]}
	[with override]
	[for load]
	[for proxy_update]

Parameters

database_name

is the name of the database. The database name can be a literal, a variable, or a stored procedure parameter.

on

indicates a size and location for the database extension. If you have your log and data on separate device fragments, use this clause for the data device and the log on clause for the log device.

default

indicates that alter database can put the database extension on any default database devices (as shown by the sp_helpdevice stored procedure in Chapter 1, “System Procedures,” in Reference Manual: Procedures). To specify a size for the database extension without specifying the exact location, use:

on default = size

To change a database device’s status to default, use sp_diskdefault.

database_device

is the name of the database device on which to locate the database extension. A database can occupy more than one database device with different amounts of space on each. Add database devices to Adaptive Server with disk init.

size

is the amount of space to allocate to the database extension. The following are example unit specifiers, using uppercase, lowecase, single and double quotes interchangeably: ‘k’ or “K” (kilobytes), “m” or ‘M’ (megabytes), “g” or “G” (gigabytes), and ‘t’ or ‘T’ (terabytes). Sybase recommends that you always include a unit specifier. Quotes are optional if you do not include a unit specifier. However, you must use quotes if you include a unit specifier. If you do not provide a unit specifier, the value provided is presumed to be in megabytes.

If you do not specify a value, alter database extends a database by 1MB or 4 allocation unit, whichever is larger. The following table describes the minimum amounts:

Server’s logical page size

Database extended by

2K

1MB

4K

1MB

8K

2MB

16K

4MB

log on

indicates that you want to specify additional space for the database’s transaction logs. The log on clause uses the same defaults as the on clause.

durability

determines the durability level of the database, and is one of:

  • full – all transactions are written to disk. This is the default if you do not specify a durability level when you create the database, and ensures full recovery from a server failure. All system databases except tempdb use this durability level (the traditional durability level for disk-resident databases). tempdb uses a durability level of no_recovery.

  • no_recovery – transactions are durable only while the server is running. All durability is lost if the server fails or is shut down politely. For disk-residents databases with durability set to no_recovery, Adaptive Server periodically writes data at runtime to the disk devices, but in an uncontrolled manner. After any shutdown (polite, impolite, or server failure and restart) a database created with no_recovery is not recovered, but is re-created from the model or, if defined, the template database.

  • at_shutdown – transactions are durable while the server is running and after a polite shutdown. All durability is lost if the server fails.

dml_logging

indicates the level of logging for insert, update, and delete commands. full (the default) records all changes to the log for a complete record of all transactions. If the database uses minimal logging, Adaptive Server attempts to not log row or page changes to syslogs. However, Adaptive Server may generate some in-memory logging activity to support run-time operations such as rolling back transactions.

set template

determines the template the database uses. One of:

  • database_name – user database that is disk-resident at full durability, and in a usable state.

  • NULL – removes the binding to the current template database. The database uses model as its template database during subsequent server restarts.

with override

forces Adaptive Server to accept your device specifications, even if they mix data and transaction logs on the same device, thereby endangering up-to-the-minute recoverability for your database. If you attempt to mix log and data on the same device without using this clause, the alter database command fails. If you mix log and data, and use with override, you are warned, but the command succeeds.

for load

is used only after create database for load, when you must re-create the space allocations and segment usage of the database being loaded from a dump.

for proxy_update

forces the resynchronization of proxy tables within the proxy database.

Examples

Example 1

Adds 3MB (1536 pages) to a user database configured for 2K logical pages on a default database device:

alter database mydb

Example 2

Adds 3MB to the space allocated for the pubs2 database on the database device named newdata:

alter database pubs2 on newdata = 3

Example 3

Adds 10MB of space for data on userdata1 and 2MB for the log on logdev for a server configured for 2K logical pages:

alter database production 
on userdata1 = "10M"
log on logdev = '2.5m'

Example 4

Changes the durability level of pubs5_rddb, a relaxed-durability database to change it to a regular database with full durability:

alter database pubs5_rddb
set durability = full

Example 5

Alters the template for the pubs3 database:

alter database pubs3
set template = new_pubs_template_db

Example 6

Changes the durability level of a disk-resident database with relaxed durability:

alter database pubs7 set durability=at_shutdown

Example 7

Changes the DML logging level for the model database, which is set to a durability level of full. Any databases created from model after this change inherit the minimal logging level property:

alter database model set dml_logging = minimal

Usage


Using alter database for archive databases

You can use alter database to add space to the modified pages section of the archive database at any time, not only when space runs out. Increasing the space in the modified pages section allows a suspended command to resume operation. The syntax is:

alter database database_name 
	[ on database_device [= size]
		[, database_device [= size]]...] 

Restrictions


Altering in-memory and relaxed durability databases


Backing up master after allocating more space


Placing the log on a separate device


Getting help on space usage


The system and default segments


Using alter database to awaken sleeping processes


Using for proxy_update

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

alter database permission defaults to the database owner. System administrators can also alter databases. Only the database owner or a login with sa_role can use alter database to change the database-wide logging setting.

Auditing

Values in event and extrainfo columns of sysaudits are:

Event

Audit option

Command or access audited

Information in extrainfo

2

alter

alter database

  • Roles – Current active roles

  • Keywords or optionsalter size

  • Previous value – NULL

  • Current value – NULL

  • Other information – NULL

  • Proxy information – Original login name, if a set proxy is in effect

See also

Commands create database, disk init, drop database, load database

System procedures sp_addsegment, sp_dropsegment, sp_helpdb, sp_helpsegment, sp_logdevice, sp_renamedb, sp_spaceused