Increases the amount of space allocated to a database, as well as to the modified pages section of an archived database. Alters one or more database-wide properties such as data manipulation language (DML) logging level, defaults for compression, in-row large object (LOB) storage, and so on.
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}] [, [no] async_init] [, compression = {none | row | page}] [, lob_compression = {compression_level | off}] [,] inrow_lob_length = value [log off database_device [= size | [from logical_page_number] [to logical_page_number]] [, database_device [= size | [from logical_page_number] [to logical_page_number]] [with override] [for load] [for proxy_update]
alter database database_name {[encrypt with key_name | decrypt [with key_name]] [parallel degree_of_parallelism] | resume [encryption | decryption [parallel degree_of_parallelism]] | suspend [encryption | decryption] }
alter database database_name off database_device {=size | [from page_number] [to page_number]} [, database_device...] [with time='time'] [with check_only]
on default = size
To change a database device’s status to default, use sp_diskdefault.
If you do not specify a value, alter database extends a database by 1MB or 4 allocation unit, whichever is larger. Minimum amounts are:
Server’s Logical Page Size |
Database Extended By |
---|---|
2K |
1MB |
4K |
1MB |
8K |
2MB |
16K |
4MB |
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, the SAP ASE 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.
none – the data is not compressed.
row – compresses one or more data items in an individual row. The SAP ASE server stores data in a row-compressed form only if the compressed form saves space compared to an uncompressed form.
page – when the page fills, existing data rows that are row-compressed are then compressed using page-level compression to create page-level dictionary, index, and character-encoding entries.
The SAP ASE server compresses data at the page level only after it has compressed data at the row level, so setting the compression to page implies both page and row compression.
0 – the lob column is not compressed.
1 through 9 – the SAP ASE server uses ZLib compression. Generally, the higher the compression number, the more the SAP ASE server compresses the LOB data, and the greater the ratio between compressed and uncompressed data (that is the greater the amount of space savings, in bytes, for the compressed data versus the size of the uncompressed data).
However, the amount of compression depends on the LOB content, and the higher the compression level , the more CPU-intensive the process. That is, level 9 provides the highest compression ratio but also the heaviest CPU usage.
100 – the SAP ASE server uses FastLZ compression. The compression ratio that uses the least CPU usage; generally used for shorter data.
101 – the SAP ASE server uses FastLZ compression. A value of 101 uses slightly more CPU than a value of 100, but uses a better compression ratio than a value of 100.
You cannot use log off with any other alter database parameter, including log on, for load, or with override.
alter database sales_db log off mylogdev
Size specifications round up to fit an exact number of allocation units. In an installation using a 16KB logical page size, you remove 52MB, not 50, because each allocation unit on that server is 4MB. The only time the SAP ASE server removes less space than specified is when the database’s log segment uses less than that much space on that device.
The default to location is the highest-numbered logical page on the device.
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.
Specifically, the command retrieves the corresponding key ID from the sysencryptkeys system table in the master database and set the encrkeyid column in its related sysdatabases row.
key_name is the database encryption key you used to encrypt the database. If you do specify a different key name, the command fails and SAP ASE displays an error message.
Create a thread for each database storage virtual device, as long as the number is equal to or fewer than "number of worker processes" configuration. The degree_of_parallelism number should be no larger than the number of database devices because additional worker threads do not improve encryption performance. If you do not specify degree_of_parallelism, SAP ASE internally defines the value based on the number of online engines, as well as how the database is distributed across various devices.
You can use parallel degree_of_parallelism with resume encrypt. If you do not specify parallel degree_of_parallelism, SAP ASE determines the value based on how the database is distributed across various engines.
database_device includes either the =size parameter or the from or to parameters (not both). The default from page is 0 (zero). If you do not specify any modifiers with the from clause, SAP ASE releases all storage for this database on the indicated device.
SAP ASE releases the highest-numbered logical pages of this database associated with the indicated device. SAP ASE rounds the value for size up, if needed, to indicate an even number of allocation units.
If you specify more space than is currently in use by this database on the indicated device, SAP ASE limits the specified size or page IDs to the amount of space available.
However, if the to page is an allocation page itself (which is the starting page of an allocation unit) and is not the same as the from page, the alter database ... off command does not affect the allocation unit containing the specified to page. SAP ASE assumes that a user requesting a precise page range does not intend to affect the specified end page, so it decrements the end page rather than increasing it.
When checking the indexes, if the results indicate that there could be enough duplicate key entries that the command will spend a significant amount of time sorting the index, the index is reported as a problem. The recommendation is that the index should be dropped before shrinking the database and the index be re-created after the database is shrunk.
Results of the checks being done by with check_only can be compromised by any other work being performed on in the database while the checks are running, or by work that was done after the checks are run but before the actual shrink is completed.
If alter database ... off does not finish within the specified period of time, work in progress is abandoned, and the command exits with an error message. Any completed work remains done.
alter database mydb
alter database pubs2 on newdata = 3
alter database production on userdata1 = "10M" log on logdev = '2.5m'
alter database pubs5_rddb set durability = full
alter database pubs3 set template = new_pubs_template_db
alter database pubs7 set durability=at_shutdown
alter database model set dml_logging = minimal
alter database pubs2 set compression = page
alter database pubs2 set lob_compression = 100
alter database pubs set inrow_lob_length = 400
alter database sales_db log off mylogdev='50M'
This example removes the highest-numbered logical pages of sales_db that are on mylogdev, up to a maximum of 50MB.
alter database sales_db log off mylogdev from 7168 to 15360
Because logical page 15360 is an allocation page, this example affects all logical pages on mydev from 7168 through 15359. It does not, however, affect page 15360, nor does it affect any pages in the named range that are not physically located on mylogdev.
alter database existdb encrypt with dbkeyThe example does not specify the parallel degree, leaving it up to SAP ASE to determine how many worker threads should be initiated to encrypt existdb in parallel.
alter database existdb suspend encryption
alter database existdb resume encryption
ANSI SQL – Compliance level: Transact-SQL extension.
The permission checks for alter database differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, for sybsecurity, you must be the database owner or have any of these privileges: own database (on sybsecurity) or manage auditing. For all other databases, you must be database owner or have the own database privilege (on the database). |
Disabled | With granular permissions disabled, you must be the database owner, a user with sa_role, or a user with sso_role (for sybsecurity). |
Values in event and extrainfo columns of sysaudits are:
Information | Values |
---|---|
Event | 2 |
Audit option | alter |
Command or access audited | alter database |
Information in extrainfo |
|