CREATE DATABASE

statementpartialDatabases & schemas

docs.snowflake.com ↗

Object: DATABASE

Creates a new database in the system. This command supports the following variants: - CREATE OR ALTER DATABASE: Creates a database if it doesn’t exist or alters an existing database. - DEFINE DATABASE: Declarative definition of a database’s target state inside a DCM project. - CREATE DATABASE … CLONE: Creates a clone of an existing database, either in its current state or at a specific time or point in the past (using Time Travel). For more information about cloning a database, see Cloning considerations. - CREATE DATABASE … FROM BACKUP SET (restores a database from a backup under a new name) In addition, this command can be used to: - Create a database from a specified listing. See About sharing with listings. - Create a database from a share provided by another Snowflake account. For more information about shares, see About Secure Data Sharing. - Create a replica of an existing primary database (for example, a secondary database). For more information about database replication, see Introduction to database replication across multiple accounts.

Syntax

supportedpartialnot supportednot scored

Standard Database

CREATE [ OR REPLACE ] [ TRANSIENT ] DATABASE [ IF NOT EXISTS ] <name>
    [ CLONE <source_schema>
        [ { AT | BEFORE } ( { TIMESTAMP => <timestamp> | OFFSET => <time_difference> | STATEMENT => <id> } ) ]
        [ IGNORE TABLES WITH INSUFFICIENT DATA RETENTION ]
        [ IGNORE HYBRID TABLES ] ]
    [ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
    [ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
    [ STAGE_UNDROP_RETENTION_TIME_IN_DAYS = <integer> ]
    [ EXTERNAL_VOLUME = <external_volume_name> ]
    [ CATALOG = <catalog_integration_name> ]
    [ ICEBERG_DEFAULT_DDL_COLLATION = '<collation_specification>' ]
    [ ICEBERG_VERSION_DEFAULT = <integer> ]
    [ ICEBERG_MERGE_ON_READ_BEHAVIOR = { 'AUTO' | 'ENABLED' | 'DISABLED' } ]
    [ ENABLE_ICEBERG_MERGE_ON_READ = { TRUE | FALSE } ]
    [ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
    [ DEFAULT_DDL_COLLATION = '<collation_specification>' ]
    [ STORAGE_SERIALIZATION_POLICY = { COMPATIBLE | OPTIMIZED } ]
    [ COMMENT = '<string_literal>' ]
    [ CATALOG_SYNC = '<snowflake_open_catalog_integration_name>' ]
    [ CATALOG_SYNC_NAMESPACE_MODE = { NEST | FLATTEN } ]
    [ CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '<string_literal>' ]
    [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
    [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]
    [ OBJECT_VISIBILITY = { <object_visibility_spec> | PRIVILEGED } ]
    [ ENABLE_DATA_COMPACTION = { TRUE | FALSE } ]
    [ OAUTH_AUTHORIZATION_SERVER = <integration_name> ]
    [ OAUTH_SCOPES_SUPPORTED = '<comma_separated_scopes>' ]

Restored database (from a backup)

CREATE DATABASE <name> FROM BACKUP SET <backup_set> IDENTIFIER '<backup_id>'

Standard Database (from a listing)

CREATE DATABASE <name> FROM LISTING '<listing_global_name>'

Shared Database (from a Share)

CREATE [ OR REPLACE ] DATABASE <name>
    FROM SHARE <provider_account>.<share_name>

Secondary Database (Database Replication)

CREATE DATABASE <name>
    AS REPLICA OF <account_identifier>.<primary_db_name>
    [ DATA_RETENTION_TIME_IN_DAYS = <integer> ]

For more information, see CREATE OR ALTER DATABASE usage notes and CREATE OR ALTER <object>.

CREATE OR ALTER [ TRANSIENT ] DATABASE <name>
    [ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
    [ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
    [ EXTERNAL_VOLUME = <external_volume_name> ]
    [ CATALOG = <catalog_integration_name> ]
    [ ICEBERG_DEFAULT_DDL_COLLATION = '<collation_specification>' ]
    [ ICEBERG_VERSION_DEFAULT = <integer> ]
    [ ICEBERG_MERGE_ON_READ_BEHAVIOR = { 'AUTO' | 'ENABLED' | 'DISABLED' } ]
    [ ENABLE_ICEBERG_MERGE_ON_READ = { TRUE | FALSE } ]
    [ REPLACE_INVALID_CHARACTERS = { TRUE | FALSE } ]
    [ DEFAULT_DDL_COLLATION = '<collation_specification>' ]
    [ LOG_LEVEL = '<log_level>' ]
    [ METRIC_LEVEL = '<metric_level>' ]
    [ TRACE_LEVEL = '<trace_level>' ]
    [ STORAGE_SERIALIZATION_POLICY = { COMPATIBLE | OPTIMIZED } ]
    [ COMMENT = '<string_literal>' ]
    [ OBJECT_VISIBILITY = { <object_visibility_spec> | PRIVILEGED } ]

Creates a new database with the same parameter values

CREATE [ OR REPLACE ] DATABASE [ IF NOT EXISTS ] <name> CLONE <source_database>
  [ ... ]

Parameters

NameRequiredDescription
namerequiredSpecifies the identifier for the database; must be unique for your account. In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (e.g. "My object"). Identifiers enclosed in double quotes are also case-sensitive. For more details, see Identifier requirements. Important As a best practice for Database Replication and Failover, we recommend giving each secondary database the same name as its primary database. This practice supports referencing fully qualified objects (i.e. '<db>.<schema>.<object>') by other objects in the same database, such as querying a fully qualified table name in a view. If a secondary database has a different name from the primary database, then these object references would break in the secondary database.
provider_account.share_namerequiredSpecifies the identifier of the share from which to create the database. As documented, the name of the share must be fully qualified with the name of the account providing the share.
AS REPLICA OF account_identifier.primary_db_namerequiredSpecifies the identifier for a primary database from which to create a replica (i.e. a secondary database). If the identifier contains spaces, special characters, or mixed-case characters, the entire string must be enclosed in double quotes. Requires the account identifier and name of the primary database. Note As a best practice for Database Replication and Failover, we recommend setting the optional parameter DATA_RETENTION_TIME_IN_DAYS to the same value on the secondary database as on the primary database.
  • account_identifier — Unique identifier of the account that stores the primary database. The preferred identifier is organization_name.account_name. To view the list of accounts enabled for replication in your organization, query SHOW REPLICATION ACCOUNTS. Though the legacy account locator can also be used as the account identifier, its use is discouraged as it may not work in the future. For more details about using the account locator as an account identifier, see Database Replication Usage Notes.
  • primary_db_name — Name of the primary database. As a best practice, we recommend giving each secondary database the same name as its primary database.
backup_setrequiredSpecifies the name of a backup set created for a specific database. You can use the SHOW BACKUP SETS command to locate the right backup set.
backup_idrequiredSpecifies the identifier of a specific backup within that backup set. You can use the SHOW BACKUPS IN BACKUP SET command to locate the right identifier within the backup set, based on the creation date and time for the backup.
'listing_global_name'requiredSpecifies the global name of the listing from which to create the database, which must meet the following requirements: Can’t be a paid listing. Listing terms, if not of type OFFLINE, must have been accepted using Snowsight. Listing data products must be available locally in the current region. Whether a listing is available in the local region can be determined by viewing the is_ready_for_import column of DESCRIBE AVAILABLE LISTING.
TRANSIENToptionalSpecifies a database as transient. Transient databases do not have a Fail-safe period so they do not incur additional storage costs once they leave Time Travel; however, this means they are also not protected by Fail-safe in the event of a data loss. For more information, see Understanding and viewing Fail-safe. In addition, by definition, all schemas (and consequently all tables) created in a transient database are transient. For more information about transient tables, see CREATE TABLE. Default: No value (i.e. database is permanent)
CLONE source_dboptionalSpecifies to create a clone of the specified source database. For more details about cloning a database, see CREATE <object> … CLONE.
AT | BEFORE ( TIMESTAMP => timestamp | OFFSET => time_difference | STATEMENT => id )optionalWhen cloning a database, the AT | BEFORE clause specifies to use Time Travel to clone the database at or before a specific point in the past. If the specified Time Travel time is at or before the point in time when the database was created, the cloning operation fails with an error.
IGNORE HYBRID TABLESoptionalIgnore hybrid tables, which will not be cloned. The cloned database includes other objects but skips hybrid tables. If you omit this option, hybrid tables in the source database are cloned with the database. Cloning those tables copies their data and is not a metadata-only operation. For requirements, cost, and limitations, see Clone databases that contain hybrid tables.
DATA_RETENTION_TIME_IN_DAYS = integeroptionalSpecifies the number of days for which Time Travel actions (CLONE and UNDROP) can be performed on the database, as well as specifying the default Time Travel retention time for all schemas created in the database. For more details, see Understanding & using Time Travel. For a detailed description of this object-level parameter, as well as more information about object parameters, see Parameters. Values: Standard Edition: 0 or 1 Enterprise Edition: 0 to 90 for permanent databases 0 or 1 for transient databases Default: Standard Edition: 1 Enterprise Edition (or higher): 1 (unless a different default value was specified at the account level) Note A value of 0 effectively disables Time Travel for the database.
MAX_DATA_EXTENSION_TIME_IN_DAYS = integeroptionalObject parameter that specifies the maximum number of days for which Snowflake can extend the data retention period for tables in the database to prevent streams on the tables from becoming stale. For a detailed description of this parameter, see MAX_DATA_EXTENSION_TIME_IN_DAYS.
STAGE_UNDROP_RETENTION_TIME_IN_DAYS = integeroptionalObject parameter that specifies the number of days for which a dropped named internal stage in the database remains available to restore with UNDROP STAGE. Schemas and stages in the database inherit this value unless they override it. For a detailed description of this parameter, see STAGE_UNDROP_RETENTION_TIME_IN_DAYS.
EXTERNAL_VOLUME = external_volume_nameoptionalObject parameter that specifies the default external volume to use for Apache Iceberg™ tables. For more information about this parameter, see EXTERNAL_VOLUME.
CATALOG = catalog_integration_nameoptionalObject parameter that specifies the default catalog integration to use for Apache Iceberg™ tables. For more information about this parameter, see CATALOG.
ICEBERG_DEFAULT_DDL_COLLATION = 'collation_specification'optionalSpecifies a default collation specification for new string columns on Snowflake-managed Iceberg tables. For more information about the parameter, see ICEBERG_DEFAULT_DDL_COLLATION.
ICEBERG_VERSION_DEFAULT = integeroptionalSpecifies the version of the Apache Iceberg™ table specification that Iceberg tables conform to. Values: 2: New tables conform with Iceberg version 2. 3: New tables conform with Iceberg version 3. Caution Before you use other engines to upgrade an Iceberg tables format-version in table properties to v3, ensure that the table isn’t used by engines or applications that don’t yet support v3. Downgrading format versions isn’t supported in the Apache Iceberg specification. Therefore, all readers and writers must support v3. The default version for Iceberg tables in Snowflake is v2, which can be configured to v3 if needed. To upgrade a table in place by using Snowflake, see Upgrade an Apache Iceberg™ table from version 2 to version 3. Default: 2 For more information about this parameter, see ICEBERG_VERSION_DEFAULT.
DEFAULT_METADATA_WRITE_FORMAT = { SNOWFLAKE | ICEBERG }optionalSpecifies the default metadata write format for new tables created with CREATE TABLE and ALTER TABLE in this scope. Values: SNOWFLAKE: New tables use the standard Snowflake table format. ICEBERG: New tables are created as Apache Iceberg™ tables when CATALOG = 'SNOWFLAKE' is set at the database level. Default: SNOWFLAKE For a detailed description of this parameter, see DEFAULT_METADATA_WRITE_FORMAT.
ICEBERG_MERGE_ON_READ_BEHAVIOR = { 'AUTO' | 'ENABLED' | 'DISABLED' }optionalSpecifies how Snowflake performs row-level updates (UPDATE, DELETE, MERGE) on Apache Iceberg™ tables. Selects between merge-on-read (which writes Iceberg delete files alongside the data) and copy-on-write (which rewrites entire data files). Snowflake can publish a table-level value of this parameter as write.delete.mode, write.update.mode, and write.merge.mode on Snowflake-managed and externally managed tables. On a Snowflake-managed table, writes from an external engine through Snowflake Horizon Catalog can update this parameter by setting those properties. On an externally managed table, a refresh can adopt those properties into this parameter. For details, see Write-mode property synchronization. The parameter values are case-insensitive. Values: 'AUTO': Snowflake selects merge-on-read or copy-on-write based on the table’s Iceberg format version and management mode. For details, see ICEBERG_MERGE_ON_READ_BEHAVIOR parameter. 'ENABLED': Merge-on-read is enabled for all Apache Iceberg™ tables to which this parameter applies, regardless of format version or management mode. 'DISABLED': Merge-on-read is disabled for all Apache Iceberg™ tables to which this parameter applies. All DML uses copy-on-write. Default: 'AUTO' For a detailed description of this parameter, see ICEBERG_MERGE_ON_READ_BEHAVIOR parameter. For more information about merge-on-read and copy-on-write behavior in Snowflake, see Use row-level deletes.
ENABLE_ICEBERG_MERGE_ON_READ = { TRUE | FALSE }optionalWarning This parameter is deprecated. Use ICEBERG_MERGE_ON_READ_BEHAVIOR instead. The legacy parameter is still honored when ICEBERG_MERGE_ON_READ_BEHAVIOR is at its default ('AUTO'), but it will return an error in a future release. Specifies whether to enable merge-on-read behavior for Apache Iceberg™ tables. Values: TRUE: New tables use merge-on-read behavior. For v2 tables, Snowflake uses positional delete files for row-level deletes. For v3 tables, Snowflake uses deletion vectors when conditions are met. Note: Setting this parameter to TRUE does not enable merge-on-read for Snowflake-managed v2 Iceberg tables. When ICEBERG_MERGE_ON_READ_BEHAVIOR is at its default ('AUTO'), this setting routes through the auto matrix, which keeps Snowflake-managed v2 tables on copy-on-write. To enable merge-on-read for Snowflake-managed v2 tables, set ICEBERG_MERGE_ON_READ_BEHAVIOR = 'ENABLED' explicitly. FALSE: New tables use copy-on-write behavior. Default: TRUE For a detailed description of this parameter, see Deprecated: ENABLE_ICEBERG_MERGE_ON_READ. For more information about merge-on-read and copy-on-write behavior in Snowflake, see Use row-level deletes.
REPLACE_INVALID_CHARACTERS = { TRUE | FALSE }optionalSpecifies whether to replace invalid UTF-8 characters with the Unicode replacement character (�) in query results for an Iceberg table. You can only set this parameter for tables that use an external Iceberg catalog. TRUE replaces invalid UTF-8 characters with the Unicode replacement character. FALSE leaves invalid UTF-8 characters unchanged. Snowflake returns a user error message when it encounters invalid UTF-8 characters in a Parquet data file. Default: FALSE
DEFAULT_DDL_COLLATION = 'collation_specification'optionalSpecifies a default collation specification for all schemas and tables added to the database. The default can be overridden at the schema and individual table level. For more details about the parameter, see DEFAULT_DDL_COLLATION.
LOG_LEVEL = 'log_level'optionalSpecifies the severity level of messages that should be ingested and made available in the active event table. Messages at the specified level (and at more severe levels) are ingested. For more information about levels, see LOG_LEVEL. For information about setting the log level, see Setting levels for logging, metrics, and tracing.
METRIC_LEVEL = 'metric_level'optionalSpecifies whether metrics data should be ingested and made available in the active event table. For more information, see METRIC_LEVEL and Setting levels for logging, metrics, and tracing.
TRACE_LEVEL = 'trace_level'optionalControls how trace events are ingested into the event table. For information about levels, see TRACE_LEVEL. For information about setting trace level, see Setting levels for logging, metrics, and tracing.
STORAGE_SERIALIZATION_POLICY = { COMPATIBLE | OPTIMIZED }optionalSpecifies the storage serialization policy for Apache Iceberg™ tables that use Snowflake as the catalog. COMPATIBLE: Snowflake performs encoding and compression of data files that ensures interoperability with third-party compute engines. OPTIMIZED: Snowflake performs encoding and compression of data files that ensures the best table performance within Snowflake. Default: OPTIMIZED
COMMENT = 'string_literal'optionalSpecifies a comment for the database. Default: No value
CATALOG_SYNC = 'snowflake_open_catalog_integration_name'optionalSpecifies the name of a catalog integration configured for Snowflake Open Catalog. If specified, Snowflake syncs Snowflake-managed Apache Iceberg™ tables in the database with an external catalog in your Snowflake Open Catalog account. For more information about syncing Snowflake-managed Iceberg tables with Open Catalog, see Sync a Snowflake-managed table with Snowflake Open Catalog. For more information about this parameter, see CATALOG_SYNC. Default: No value
CATALOG_SYNC_NAMESPACE_MODE = { NEST | FLATTEN }optionalSpecifies the catalog sync namespace mode for Snowflake-managed Iceberg tables in the database that you sync with Snowflake Open Catalog. This property specifies whether Snowflake syncs the table to Open Catalog with one or two parent namespaces. It only applies if you’re setting the CATALOG_SYNC parameter. After you create the database, you can’t alter this property. NEST: Snowflake syncs two parent namespaces with the table. For example, suppose you have a db2.public.table1 Iceberg table registered in Snowflake. You want to sync this table, along with its two parent namespaces, to the catalog2 external catalog in Open Catalog. To sync the table with its two parent namespaces, use the default for CATALOG_SYNC_NAMESPACE_MODE (NEST). If you don’t specify the CATALOG_SYNC_NAMESPACE_MODE property, the default for this property is applied, which is NEST. Because you’re using the default for CATALOG_SYNC_NAMESPACE_MODE, you don’t need to specify CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER. As a result, Snowflake syncs the table to Open Catalog with the following fully qualified name: catalog2.db2.public.table1. FLATTEN: Snowflake syncs one parent namespace with the table, which contains the delimiter you set by using the CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER property. Important If your third-party query engine can only query tables located up to the second namespace level in a catalog, you must set the CATALOG_SYNC_NAMESPACE_MODE property to FLATTEN. Otherwise, Snowflake will sync Snowflake-managed Iceberg tables to the third namespace level in Open Catalog and you can’t query the table. For example, suppose that you have a db1.public.table1 Iceberg table registered in Snowflake. You want to sync this table and one parent namespace named db1-public with the catalog1 external catalog in Open Catalog, so that the table is located at the second namespace level in Open Catalog. To sync the table with the db1-public parent namespace, set CATALOG_SYNC_NAMESPACE_MODE to FLATTEN and specify a hyphen (-) as the value for CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER. As a result, Snowflake syncs this table to Open Catalog with the following fully qualified name: catalog1.db1-public.table1. Default: NEST
CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = 'string_literal'optionalSpecifies a delimiter, which Snowflake inserts in the flattened namespace that results when Snowflake syncs a Snowflake-managed Iceberg table to Snowflake Open Catalog with one parent namespace. This delimiter property only applies when you set the CATALOG_SYNC_NAMESPACE_MODE property to FLATTEN. Snowflake inserts this delimiter to avoid conflicts that could arise from flattening parent namespaces for different tables. After you create the database, you can’t alter this property. For example, suppose you want to sync the customer.data.table1 and custom.erdata.table1 Snowflake-managed Iceberg tables to the catalog1 external catalog in Open Catalog. By setting the CATALOG_SYNC_NAMESPACE_MODE property to FLATTEN and specifying a hyphen (-) for the delimiter, Snowflake syncs these tables with Open Catalog with the following fully qualified names: catalog1.customer-data.table1 catalog1.custom-erdata.table1 If you set the CATALOG_SYNC_NAMESPACE_MODE property to FLATTEN, a non-empty delimiter value is required. However, if you set the CATALOG_SYNC_NAMESPACE_MODE property to NEST, this delimiter property doesn’t apply and the configured value will be ignored. Valid characters: 0-9, A-Z, a-z, _, $, -
TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )optionalSpecifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.
WITH CONTACT ( purpose = contact [ , purpose = contact ...] )optionalAssociate the new object with one or more contacts. Specify the WITH CONTACT clause after all other clauses except the AS clause (if that clause is supported by this command).
ENABLE_DATA_COMPACTION = { TRUE | FALSE }optionalSpecifies whether Snowflake should enable data compaction on Snowflake-managed Apache Iceberg™ tables. TRUE: Snowflake performs data compaction on the tables. FALSE: Snowflake doesn’t perform data compaction on the tables. Default: TRUE For more information, see ENABLE_DATA_COMPACTION and Set data compaction.
OAUTH_AUTHORIZATION_SERVER = integration_nameoptionalObject parameter that specifies an External OAuth security integration as the authorization server for MCP servers in this database. For a detailed description of this parameter, see OAUTH_AUTHORIZATION_SERVER.
OAUTH_SCOPES_SUPPORTED = 'comma_separated_scopes'optionalObject parameter that specifies the OAuth scopes to advertise for MCP servers in this database. For a detailed description of this parameter, see OAUTH_SCOPES_SUPPORTED.

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE DATABASE | Account | Required to create a new database. Only the SYSADMIN role, or a higher role, has this privilege by default. The privilege can be granted to additional roles as needed. USAGE | External volume, catalog integration | Required if setting the EXTERNAL_VOLUME or CATALOG object parameters, respectively. IMPORT LISTING | Account | Required to create a database from a listing. IMPORT SHARE | Account | Required to create a database from a share. MANAGE VISIBILITY | Account | Required to set the OBJECT_VISIBILITY property. Only the SECURITYADMIN role has this privilege by default. The privilege can be granted to additional roles as needed. MODIFY LOG LEVEL | Account | Required to set the LOG_LEVEL for a database. MODIFY TRACE LEVEL | Account | Required to set the TRACE_LEVEL for a database. OWNERSHIP | Database | Required when executing an ALTER DATABASE or ALTER SCHEMA statement to set object visibility, or when executing a CREATE OR ALTER DATABASE statement for an existing database. OWNERSHIP is a special privilege on an object that is automatically granted to the role that created the object, but can also be transferred using the GRANT OWNERSHIP command to a different role by the owning role (or any role with the MANAGE GRANTS privilege). For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

General usage notes

- Creating a database automatically sets it as the active/current database for the current session (equivalent to using the USE DATABASE command for the database). - If a database with the same name already exists, an error is returned and the database is not created, unless the optional OR REPLACE keyword is specified in the command. Important Using OR REPLACE is the equivalent of using DROP DATABASE on the existing database and then creating a new database with the same name; however, the dropped database is not permanently removed from the system. Instead, it is retained in Time Travel. This is important because dropped databases in Time Travel contribute to data storage for your account. For more information, see Storage costs for Time Travel and Fail-safe. - The OR REPLACE and IF NOT EXISTS clauses are mutually exclusive. They can’t both be used in the same statement. - CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction. - Creating a new database automatically creates two schemas in the database: PUBLIC: Default schema for the database. - INFORMATION_SCHEMA: Schema which contains views and table functions that can be used for querying metadata about the objects in the database, as well as across all objects in the account. - Databases created from shares differ from standard databases in the following ways: They do not have the PUBLIC schema unless it was explicitly granted to the share. They do include the INFORMATION_SCHEMA schema automatically. - They cannot be cloned. - Properties, such as TRANSIENT and DATA_RETENTION_TIME_IN_DAYS, do not apply. - When a database is active/current, the PUBLIC schema is also active/current by default unless a different schema is used or the PUBLIC schema has been dropped. - Regarding metadata: Attention Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

CREATE OR ALTER DATABASE usage notes

- All limitations of the ALTER DATABASE command apply. - This command supports the properties and syntax that overlap between the CREATE DATABASE and ALTER DATABASE commands. For this reason, the following are not supported: Swapping databases using the SWAP WITH parameter. - Renaming a database using the RENAME TO parameter. - Creating a clone of a database using the CLONE parameter. - Adding or changing tags and policies. Any existing tags and policies are preserved. - Converting a TRANSIENT database into a non-TRANSIENT database, or vice versa. - Creating a database from a share using CREATE OR ALTER DATABASE … FROM SHARE. - Creating a secondary (replica) database using CREATE OR ALTER DATABASE … AS REPLICA OF.

Database replication usage notes

Important This section describes a limited database replication feature that is different from the account replication feature. Snowflake strongly recommends using the account replication feature to replicate and failover databases. - Database replication uses Snowflake-provided compute resources instead of your own virtual warehouse to copy objects and data. However, the STATEMENT_TIMEOUT_IN_SECONDS session/object parameter still controls how long a statement runs before it is canceled. The default value is 172800 (2 days). Because the initial replication of a primary database can take longer than 2 days to complete (depending on the amount of metadata in the database as well as the amount of data in database objects), we recommend increasing the STATEMENT_TIMEOUT_IN_SECONDS value to 604800 (7 days, the maximum value) for the session in which you run the replication operation. Run the following ALTER SESSION statement prior to executing the ALTER DATABASE secondary_db_name REFRESH statement in the same session: Copy code ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = 604800; Note that the STATEMENT_TIMEOUT_IN_SECONDS parameter also applies to the active warehouse in a session. The parameter honors the lower value set at the session or warehouse level. If you have an active warehouse in the current session, also set STATEMENT_TIMEOUT_IN_SECONDS to 604800 for this warehouse (using ALTER WAREHOUSE). For example: Copy code -- determine the active warehouse in the current session (if any) SELECT CURRENT_WAREHOUSE(); +---------------------+ | CURRENT_WAREHOUSE() | |---------------------| | MY_WH | +---------------------+ -- change the STATEMENT_TIMEOUT_IN_SECONDS value for the active warehouse ALTER WAREHOUSE my_wh SET STATEMENT_TIMEOUT_IN_SECONDS = 604800; You can reset the parameter value to the default after the replication operation is completed: Copy code ALTER WAREHOUSE my_wh UNSET STATEMENT_TIMEOUT_IN_SECONDS; - The preferred method of identifying the account that stores the primary database uses the organization name and account name as the account identifier. If you decide to use the legacy account locator instead, see Account identifiers for replication and failover. - The CREATE DATABASE … AS REPLICA command does not support the WITH TAG clause. This clause is not supported because the secondary database is read only. If your primary database specifies the WITH TAG clause, remove the clause prior to creating the secondary database. To verify whether your database has the WITH TAG clause, call the GET_DDL function in your Snowflake account and specify the primary database in the function argument. If a tag is set on the database, the function output will include an ALTER DATABASE … SET TAG statement. For more information, see Replication and tags.

Database replication examples

Important This section describes a limited database replication feature that is different from the account replication feature. Snowflake strongly recommends using the account replication feature to replicate and failover databases. For an example of creating a replication group to replicate a single database to a target account, see Examples.

CREATE OR ALTER DATABASE examples

Create a database named db1: Alter database db1 to set the DATA_RETENTION_TIME_IN_DAYS and DEFAULT_DDL_COLLATION parameters: The absence of a previously set parameter in the modified database definition results in unsetting it. In the following example, unset the DATA_RETENTION_TIME_IN_DAYS parameter for the database db1 created in the previous example:

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by