Creates a new database.
Syntax for nonclustered environments:
create [inmemory] [temporary] database database_name [use database_name as template] [on {default | database_device} [= size] [, database_device [= size]]...] [log on database_device [= size] [, database_device [= size]]...] [with {dbid = number, default_location = "pathname", override}] | [[,]durability = { no_recovery | at_shutdown | full} ] [, [no] async_init] [ [,] compression = {none | row | page}] [ [,] lob_compression = {compression_level | off}] [ [,] inrow_lob_length = value ] }... [for {load | proxy_update}]
Syntax for cluster environments:
create [ [ global | system ] temporary ] database database_name [ for instance instance_name ] [on {default | database_device} [= size] [, database_device [= size]]...] [log on database_device [= size] [, database_device [= size]]...] [with {override | default_location = "pathname"}] [for {load | proxy_update}]
indicates that you are creating a temporary database.
required for in-memory databases.
is the name of the new database, which must conform to the rules for identifiers, and cannot be a variable.
indicates a location and size for the database.
indicates that create database can put the new database on any default database devices, as shown in sysdevices.status. To specify a size for the database without specifying a location, use:
on default = size
To change a database device’s status to “default,” use sp_diskdefault.
is the logical name of the device on which to locate the database. A database can occupy different amounts of space on each of several database devices. To add database devices to Adaptive Server, use disk init.
is the amount of space to allocate to the database extension. You can use the following unit specifiers, using uppercase, lowercase, 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.
specifies the logical name of the device for the database logs. You can specify more than one device in the log on clause.
can be specified in any order. You must specify at least one of the following options when you use the with clause:
with dbid = number – specifies the dbid for the new database. If you do not explicitly specify the dbid, the server assigns an unused dbid.
with default_location – specifies the storage location of new tables. If you also specify the for proxy_update clause, one proxy table for each remote table or view is automatically created from the specified location.
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 create database command fails. If you mix log and data, and use with override, you are warned, but the command succeeds.
determines the durability level of the database:
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 use this durability level (the traditional durability level for disk-resident databases).
no_recovery – transactions are not durable to disk and all changes are lost if the server fails or is shut down. For disk-based databases, 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 template (if defined) database.
at_shutdown – transactions are durable while the server is running and after a polite shutdown. All durability is lost if the server fails.
enables or disables asynchronous database initialization.
indicates the level of compression to be applied to newly created tables or partitions:
none – data is not compressed.
row – compresses one or more data items in an individual row. Adaptive 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.
Adaptive 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.
Determines the compression level for the newly created table. Selecting off means the table does not use LOB compression.
The compression algorithm ignores rows that do not use LOB data.
Table compression level. The compression levels are:
0 – the row is not compressed.
1 through 9 – Adaptive Server uses ZLib compression. Generally, the higher the compression number, the more Adaptive 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 – Adaptive Server uses FastLZ compression. The compression ratio that uses the least CPU usage; generally used for shorter data.
101 – Adaptive 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.
specifies the number of bytes. The range of valid values for inrow_lob_length is 0 through the logical page size of the database. A value of 0 turns off LOB specification database-wide, and all LOB columns without a specific in row clause are created as off-row LOB columns.
specifies the logging level for DML operations.
specifies either full logging or minimal logging of the DML operations.
invokes a streamlined version of create database that you can use only for loading a database dump. See “Using the for load option”.
automatically gets metadata from the remote location and creates proxy tables. You cannot use for proxy_update unless you also specify with default_location.
indicates that you are creating a global temporary database.
indicates that you are creating a local system temporary database.
indicates that you are creating a temporary database.
specifies the instance that is to own the local system temporary database or local temporary database you are creating. This parameter is not used when creating global temporary databases.
You must create a local user temporary database from the instance that is to own it. You can create a local system temporary database from any instance.
Creates a database named pubs:
create database pubs
Creates a 4MB database named pubs:
create database pubs on default = 4
If you do not provide a unit specifier for size, the value provided for pubs is presumed to be in megabytes.
Creates a database named pubs with 3MB on the datadev device and 2MB on the moredatadev device:
create database pubs on datadev = "3M", moredatadev = '2.0m'
Creates a database named pubs with 3MB of data on the datadev device and a 0.5GB log on the logdev device:
create database pubs on datadev='3m' log on logdev='0.5g'
Creates a proxy database named proxydb but does not automatically create proxy tables:
create database proxydb with default_location "UNITEST.pubs.dbo."
Creates a proxy database named proxydb and automatically creates proxy tables:
create database proxydb on default = "4M" with default_location "UNITEST.pubs2.dbo." for proxy_update
Creates a proxy database named proxydb, and retrieves the metadata for all of the remote tables from a remote database:
create database proxydb on default = 4 with default_location "UNITEST.pubs2.." for proxy_update
Creates a database called pubs with dbid 15:
create database pubs with dbid = 15
Creates a temporary database called mytempdb1, with 3MB of data on the datadev device and 1MB of log on the logdev device:
create temporary database mytempdb1 on datadev = '3m' log on logdev = '1M'
In a cluster environment, creates a local user temporary database on “ase1.” Execute the following command from the owner instance (“ase1”):
create temporary database local_tempdb1 for instance ase1
or:
create temporary database local_tempdb1
In a cluster environment, creates a local system temporary database on “ase1.” Execute this command from any instance in the cluster:
create system temporary database local_systempdb1 for instance ase1
In a cluster environment, creates a global temporary database:
create global temporary database global_tempdb1
Creates an in-memory database on two different in-memory storage devices, imdb_data_dev1 for the data and imdb_logdev for the log:
create inmemory database imdb2 on imdb_data_dev1 = '1.0g' log on imdb_logdev = '0.5g' with durability = no_recovery
Creates an in-memory database on multiple in-memory storage devices. imdb_data_dev1 and imdb_data_dev2 contain all data, and inmem_logdev contains the log:
create inmemory database imdb3 on imdb_data_dev1 = '100m', imdb_data_dev2 = '200m' log on inmem_logdev = '50m' with durability=no_recovery
Creates the pubs5 database using the pubs2 database as the template:
create inmemory database pubs5 use pubs2 as template on imdb_duck1_cach = '5m' log on imdb_duck_log = '5m' with durability = no_recovery
Creates a relaxed-durability database named pubs5_rddb:
create database pubs5_rddb on pubs5_dev = '6M' log on pubs5_log = '2M' with durability = at_shutdown
Creates an in-memory storage cache dedicated to an in-memory temporary database:
Create the in-memory storage cache:
sp_cacheconfig inmem_tempdb_cache, "40m", inmemory_storage, "none", "cache_partition=2"
Create an in-memory device to create temporary database:
DISK INIT name = "inmem_dev" , physname = "inmem_tempdb_cache" , size = "40m" , type='inmemory'
Create the in-memory database:
create inmemory temporary database temp_imdb on inmem_dev = "20m" with durability = no_recovery
Creates a temporary database on an existing disk-device with durability set to no_recovery:
create temporary database tempdb_rddb_norec on datadev = "5m" log on logdev = "5m" with durability = no_recovery
Creates the emaildb database, and configures it for page-level compression:
create database emaildb on email_dev = '50M' with compression = page
Creates the email_lob_db database and configures it for a LOB compression level of 101:
Create database email_lob_db on email_lob_dev = '50M' with lob_compression = 101
Creates a database called pubs that allows in-row LOB data with a length of 300 bytes:
create database pubs with inrow_lob_length = 300
Use create database from the master database.
You can specify the size as a float datatype, however, the size is rounded down to the nearest multiple of the allocation unit.
If you do not explicitly state the size of the database, the size is determined by the size of the model database. The minimum size that you can create a database is four allocation units.
Because Adaptive Server allocates space for databases for create database and alter database in chunks of 256 logical pages, these commands round the specified size down to the nearest multiple of allocation units.
If you do not include a unit specifier, Adaptive Server interprets the size in terms of megabytes of disk space, and this number is converted to the logical page size the server uses.
If you do not specify a location and size for a database, the default location is any default database devices indicated in master..sysdevices. The default size is the larger of the size of the model database or the default database size parameter in sysconfigures.
system administrators can increase the default size by using sp_configure to change the value of default database size and restarting Adaptive Server. The default database size parameter must be at least as large as the model database. If you increase the size of the model database, you must also increase the default size.
If Adaptive Server cannot give you as much space as you want where you have requested it, it comes as close as possible, on a per-device basis, and prints a message telling how much space was allocated and where it was allocated. The maximum size of a database is system-dependent.
If you create a proxy database using:
create database mydb on my_device with default_location = "pathname" for proxy_update
The presence of the device name is enough to bypass size calculation, and this command may fail if the default database size (the size of the model database) is not large enough to contain all of the proxy tables.
To allow CIS to estimate database size, do not include any device name or other option with this command:
create database mydb with default_location = "pathname" for proxy_update
Adaptive Server can manage as many as 32,767 databases.
The dbid should always be greater than zero and less than the maximum dbid of 32,767.
Adaptive Server can create only one database at a time. If two database creation requests collide, one user sees this message:
model database in use: cannot create new database
Each time you allocate space on a database device with create database or alter database, that allocation represents a device fragment, and the allocation is entered as a row in sysusages.
The maximum number of named segments for a database is 32. Segments are named subsets of database devices available to a particular Adaptive Server. For more information about segments, see the System Administration Guide.
You cannot use either with default_location or for proxy_update parameters with the create temporary database command. Doing so generates an error, such as the following two examples:
1> create temporary database tb1 with default_location "remSERVER.mydb.."
Msg 102, Level 15, State 7: Server 'ebi_SUS_AS125x_SUN32', Line 1: Incorrect syntax near 'create temporary database'.
1> create temporary database tb1 with default_location "remSERVER.mydb.." for proxy_update
Msg 102, Level 15, State 7: Server 'ebi_SUS_AS125x_SUN32', Line 1: Incorrect syntax near 'create temporary database'.
The temporary status of a database, which is set during the creation of the temporary database, is indicated by value 0x00000100 (256 decimal) of the status3 field of a sysdatabases entry.
In addition to all options inherited from model, a temporary database, like the system tempdb, has the following database options set:
select into/bulkcopy
trunc log on chkpt
As with system tempdb, the guest user is added to the temporary database, and create table permission is granted to PUBLIC.
Unused pages are not cleared during creation of the temporary database, since a temporary database is re-created every time the server is restarted.
The compression setting for create table . . .with compression overrides the create database compression setting.
Temporary tables created with select into do not inherit the compression level from the database.
The default setting for compression in the model database is none (data compression is off for all databases based on model).
When you enable data compression in tempdb or other temporary databases, temporary tables created in a session or inside stored procedures do not inherit tempdb’s compression level.
The database to which a task is bound determines the compression level of the temporary tables it creates.
The in-row size can be as large as the maximum row size allowed in the database. Adaptive Server lowers the limit on the size of individual column’s in-row LOB storage during inserts and updates, based on the space available for storage in a single page, minus any page or row overheads.
When you create a table in a database where you have specified a valid in-row LOB length database-wide, all LOB columns in the table are created as in-row unless you specify off row in the syntax for the column’s definition. The column’s in-row length, in bytes, is specified by this database-wide setting.
The default value for inrow_lob_length setting is 0 bytes, which causes no changes in behavior to existing databases when you upgrade to Adaptive Server version 15.7. Changing this default allows applications with different requirements on in-row storage to control how much LOB data is stored in-row.
The database-wide setting applies only to newly created tables or LOB columns added to existing tables after the database-wide setting is applied or changed. The in-row LOB length inherited by each LOB column when the table was initially created remains unchanged, even when the database-wide setting is altered. To change an individual LOB column’s in-row length or in-row property, use alter table modify column.
To change the default length, use the inrow_lob_length parameter of alter database.
The database_device you list for the in-memory database must be an in-memory storage device.
The for load parameter indicates that the database is created initially in a state waiting to be loaded using a load database command.
You cannot:
Create an in-memory database on a default device.
Use in-memory databases for system databases (other than tempdb).
Use an in-memory database as an archive database. Sybase recommends that you do not use an in-memory database as a scratch database.
Use the same name for the database you are creating and its template database.
Specify system databases, including model, as the template database.
Mix disk-based and cache-based storage devices. Adaptive Server treats databases created entirely on in-memory storage cache as in-memory databases. You cannot use:
In-memory storage devices created on different in-memory storage caches for one in-memory database
In-memory storage devices created on one in-memory storage cache, either in full or in part, for different in-memory databases
Use the use as template parameter with the with default_location = parameter.
Use the for load and for proxy update parameters with the use as template parameter.
You can:
Create in-memory databases on in-memory storage devices residing on named caches as long as all the in-memory storage devices are hosted by in-memory storage cache.
Create mixed log-and-data in-memory databases on the same in-memory storage devices. However, mixed log-and-data in-memory databases must be on a single cache.
The durability = no_recovery parameter is required when you create an an in-memory database. This parameter reinforces the behaviour that in-memory databases are always recreated when you restart the server.
Adaptive Server creates a new database by copying the model database.
You can customize model by adding tables, stored procedures, user-defined datatypes, and other objects, and by changing database option settings. New databases inherit these objects and settings from model.
To guarantee recoverability, create database must clear every page that was not initialized when the model database was copied. This may take several minutes, depending on the size of the database and the speed of your system.
If you are creating a database to load a database dump into it, you can use the for load option to skip the page-clearing step. This makes database creation considerably faster.
Back up the master database each time you create a new database. This makes recovery easier and safer if master is damaged.
If you create a database and fail to back up master, you may be able to recover the changes with disk reinit.
The with override clause allows you to mix log and data segments on a single device. However, for full recoverability, the device or devices specified in log on should be different from the physical device that stores the data. In the event of a hard-disk failure, you can recover the database from database dumps and transaction logs.
You can create a small database on a single device that is used to store both the transaction log and the data, but you must rely on the dump database command for backups.
The size of the device required for the transaction log varies according to the amount of update activity and the frequency of transaction log dumps. As a rule of thumb, allocate to the log device 10 – 25 percent of the space you allocate to the database itself. It is best to start small, since space allocated to a transaction log device cannot be reclaimed and cannot be used for storing data.
You can use the for load option for recovering from media failure or for moving a database from one machine to another, if you have not added to the database with sp_addsegment. Use alter database for load to create a new database in the image of the database from which the database dump to be loaded was made. For a discussion of duplicating space allocation when loading a dump into a new database, see the System Administration Guide.
When you create a database using the for load option, you can run only the following commands in the new database before loading a database dump:
alter database for load
After you load the database dump into the new database, you can also use some dbcc diagnostic commands in the databases. After you issue the online database command, there are no restrictions on the commands you can use.
A database created with the for load option has a status of “don’t recover” in sp_helpdb output.
To get a report on a database, execute sp_helpdb.
For a report on the space used in a database, use sp_spaceused.
Without the for proxy_update clause, the behavior of the with default_location clause is the same as that provided by sp_defaultloc—a default storage location is established for new and existing table creation, but proxy table definitions are not automatically imported during the processing of create database.
If for proxy_update is specified with no default_location, an error is reported.
When a proxy database is created (using the for proxy_update option), CIS is called upon to:
Provide an estimate of the database size required to contain all proxy tables representing the actual tables and views found in the primary server’s database. This estimate is the number of database pages needed to contain all proxy tables and indexes. The estimate is used if no size is specified, and no database devices are specified.
Create all proxy tables representing the actual tables and views found in the companion server’s database.
Grant all permissions on proxy tables to public.
Add the guest user to the proxy database.
The database status is set to indicate that this database “Is_A_Proxy”. This status is contained in master.dbo.sysdatabases.status3.
ANSI SQL – Compliance level: Transact-SQL extension.
The permission checks for create database differ based on your granular permissions settings.
Granular permissions enabled |
With granular permissions enabled, you must have create database privilege. If you are creating the sybsecurity database, you must have the manage auditing privilege. |
Granular permissions disabled |
With granular permissions disabled, you must be system administrator or have create database privilege. If you are creating the sybsecurity database, you must be a system security officer. |
Values in event and extrainfo columns of sysaudits are:
Event |
Audit option |
Command or access audited |
Information in extrainfo |
---|---|---|---|
9 |
create |
create database |
|
Commands alter database, disk init, drop database, dump database, load database, online database
System procedures sp_changedbowner, sp_diskdefault, sp_helpdb, sp_logdevice, sp_renamedb, sp_spaceused