ALTER TABLE
statementpartialTables, views, streams, sequencesModifies the properties, columns, or constraints for an existing table.
Syntax
supportedpartialnot supportednot scored
ALTER TABLE [ IF EXISTS ] <name> RENAME TO <new_table_name>
ALTER TABLE [ IF EXISTS ] <name> SWAP WITH <target_table_name>
ALTER TABLE [ IF EXISTS ] <name> { clusteringAction | tableColumnAction | constraintAction }
ALTER TABLE [ IF EXISTS ] <name> dataMetricFunctionAction
ALTER TABLE [ IF EXISTS ] <name> dataGovnPolicyTagAction
ALTER TABLE [ IF EXISTS ] <name> extTableColumnAction
ALTER TABLE [ IF EXISTS ] <name> searchOptimizationAction
ALTER TABLE [ IF EXISTS ] <name> ADD STORAGE LIFECYCLE POLICY <policy_name>
ON ( <col_name> [ , <col_name> ... ] )
ALTER TABLE [ IF EXISTS ] <name> DROP STORAGE LIFECYCLE POLICY
ALTER TABLE [ IF EXISTS ] <name> SET
[ DATA_RETENTION_TIME_IN_DAYS = <integer> ]
[ MAX_DATA_EXTENSION_TIME_IN_DAYS = <integer> ]
[ CHANGE_TRACKING = { TRUE | FALSE } ]
[ DEFAULT_DDL_COLLATION = '<collation_specification>' ]
[ ICEBERG_DEFAULT_DDL_COLLATION = '<collation_specification>' ]
[ ENABLE_SCHEMA_EVOLUTION = { TRUE | FALSE } ]
[ ERROR_LOGGING = { TRUE | FALSE } ]
[ CONTACT <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ]
[ COMMENT = '<string_literal>' ]
[ ROW_TIMESTAMP = { TRUE | FALSE } ]
ALTER TABLE [ IF EXISTS ] <name> UNSET {
DATA_RETENTION_TIME_IN_DAYS |
MAX_DATA_EXTENSION_TIME_IN_DAYS |
CHANGE_TRACKING |
DEFAULT_DDL_COLLATION |
ICEBERG_DEFAULT_DDL_COLLATION |
ENABLE_SCHEMA_EVOLUTION |
ERROR_LOGGING |
CONTACT <purpose> |
COMMENT |
ROW_TIMESTAMP
}
[ , ... ]
Where
clusteringAction ::=
{
CLUSTER BY ( <expr> [ , <expr> , ... ] )
| CLUSTER BY AUTO
/* RECLUSTER is deprecated */
| RECLUSTER [ MAX_SIZE = <budget_in_bytes> ] [ WHERE <condition> ]
/* { SUSPEND | RESUME } RECLUSTER is valid action */
| { SUSPEND | RESUME } RECLUSTER
| DROP CLUSTERING KEY
}
Where
tableColumnAction ::=
{
ADD [ COLUMN ] [ IF NOT EXISTS ] <col_name> <col_type> [ [ GENERATED ALWAYS ] AS ( <expr> ) [ VIRTUAL ] ]
[
{
DEFAULT <default_value>
| { AUTOINCREMENT | IDENTITY }
/* AUTOINCREMENT (or IDENTITY) is supported only for */
/* columns with numeric data types (NUMBER, INT, FLOAT, etc.). */
/* Also, if the table is not empty (that is, if the table contains */
/* any rows), only DEFAULT can be altered. */
[
{
( <start_num> , <step_num> )
| START <num> INCREMENT <num>
}
]
[ { ORDER | NOORDER } ]
}
]
[ inlineConstraint ]
[ COLLATE '<collation_specification>' ]
| RENAME COLUMN <col_name> TO <new_col_name>
| ALTER | MODIFY [ ( ]
[ COLUMN ] <col1_name> DROP DEFAULT
, [ COLUMN ] <col1_name> SET DEFAULT <seq_name>.NEXTVAL
, [ COLUMN ] <col1_name> { [ SET ] NOT NULL | DROP NOT NULL }
, [ COLUMN ] <col1_name> [ [ SET DATA ] TYPE ] <type>
, [ COLUMN ] <col1_name> COMMENT '<string>'
, [ COLUMN ] <col1_name> UNSET COMMENT
[ , [ COLUMN ] <col2_name> ... ]
[ , ... ]
[ ) ]
| DROP [ COLUMN ] [ IF EXISTS ] <col1_name> [, <col2_name> ... ]
}
inlineConstraint ::=
[ NOT NULL ]
[ CONSTRAINT <constraint_name> ]
{
UNIQUE
| PRIMARY KEY
| [ FOREIGN KEY ] REFERENCES <ref_table_name> [ ( <ref_col_name> ) ]
| CHECK ( <expr> )
}
[ <constraint_properties> ]
For detailed syntax and examples for creating/altering inline constraints, see CREATE | ALTER TABLE … CONSTRAINT.
dataMetricFunctionAction ::=
SET DATA_METRIC_SCHEDULE = {
'<num> MINUTE'
| 'USING CRON <expr> <time_zone>'
| 'TRIGGER_ON_CHANGES'
}
| UNSET DATA_METRIC_SCHEDULE
| ADD DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
[ WITHIN GROUP ( <group_col1> [ , <group_col2> ... ] )
[ GROUP LIMIT <integer> ] ]
[ FILTER ( <predicate> ) ]
[ EXPECTATION <expectation_name> ( <expression> )
[, <expectation_name> ( <expression> ) [ , ... ] ] ]
[ EXECUTE AS ROLE <role_name> ]
[ ANOMALY_DETECTION = { TRUE | FALSE } ]
[ SENSITIVITY = { 'LOW' | 'MEDIUM' | 'HIGH' } ]
[ ON_VIOLATION_ACTION = { ( TYPE = '<action_type>' [ , TARGET = <target_name> ] ) | ( ( TYPE = '<action_type>' [ , TARGET = <target_name> ] ) [ , ... ] ) } ]
[ , <metric_name_2> ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] ) ]
[ WITHIN GROUP ( <group_col1> [ , <group_col2> ... ] )
[ GROUP LIMIT <integer> ] ]
[ FILTER ( <predicate> ) ]
[ EXPECTATION <expectation_name> ( <expression> )
[, <expectation_name> ( <expression> ) [ , ... ] ] ]
[ EXECUTE AS ROLE <role_name> ]
[ ANOMALY_DETECTION = { TRUE | FALSE } ]
[ SENSITIVITY = { 'LOW' | 'MEDIUM' | 'HIGH' } ]
[ ON_VIOLATION_ACTION = { ( TYPE = '<action_type>' [ , TARGET = <target_name> ] ) | ( ( TYPE = '<action_type>' [ , TARGET = <target_name> ] ) [ , ... ] ) } ]
| DROP DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
[ , <metric_name_2> ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] ) ]
| MODIFY DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
{ SUSPEND | RESUME }
[ , <metric_name_2> ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
{ SUSPEND | RESUME } ]
| MODIFY DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
{ ADD | MODIFY } EXPECTATION <expectation_name> ( <expression> )
[, <expectation_name> ( <expression> ) [ , ... ] ]
| MODIFY DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
DROP EXPECTATION <expectation_name> [ , <expectation_name> [ , ... ] ]
| MODIFY DATA METRIC FUNCTION <metric_name>
ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
FILTER ( [ <predicate> ] )
[ , <metric_name_2> ON ( <col_name> [ , ... ] [ , TABLE <table_name>( <col_name> [ , ... ] ) ] )
FILTER ( [ <predicate> ] ) ]
| MODIFY DATA METRIC FUNCTION <metric_name>
SET <list_of_properties>
For detailed syntax and examples for creating/altering inline constraints, see CREATE | ALTER TABLE … CONSTRAINT.
dataGovnPolicyTagAction ::=
{
SET TAG <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]
| UNSET TAG <tag_name> [ , <tag_name> ... ]
}
|
{
ADD ROW ACCESS POLICY <policy_name> ON ( <col_name> [ , ... ] )
| DROP ROW ACCESS POLICY <policy_name>
| DROP ROW ACCESS POLICY <policy_name> ,
ADD ROW ACCESS POLICY <policy_name> ON ( <col_name> [ , ... ] )
| DROP ALL ROW ACCESS POLICIES
}
|
{
SET AGGREGATION POLICY <policy_name>
[ ENTITY KEY ( <col_name> [, ... ] ) ]
[ FORCE ]
| UNSET AGGREGATION POLICY
}
|
{
SET JOIN POLICY <policy_name>
[ FORCE ]
| UNSET JOIN POLICY
}
|
ADD [ COLUMN ] [ IF NOT EXISTS ] <col_name> <col_type>
[ [ WITH ] MASKING POLICY <policy_name>
[ USING ( <col1_name> , <cond_col_1> , ... ) ] ]
[ [ WITH ] PROJECTION POLICY <policy_name> ]
[ [ WITH ] TAG ( <tag_name> = '<tag_value>'
[ , <tag_name> = '<tag_value>' , ... ] ) ]
|
{
{ ALTER | MODIFY } [ COLUMN ] <col1_name>
SET MASKING POLICY <policy_name>
[ USING ( <col1_name> , <cond_col_1> , ... ) ] [ FORCE ]
| UNSET MASKING POLICY
}
|
{
{ ALTER | MODIFY } [ COLUMN ] <col1_name>
SET PROJECTION POLICY <policy_name>
[ FORCE ]
| UNSET PROJECTION POLICY
}
|
{ ALTER | MODIFY } [ COLUMN ] <col1_name> SET TAG
<tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]
, [ COLUMN ] <col2_name> SET TAG
<tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' ... ]
|
{ ALTER | MODIFY } [ COLUMN ] <col1_name> UNSET TAG <tag_name> [ , <tag_name> ... ]
, [ COLUMN ] <col2_name> UNSET TAG <tag_name> [ , <tag_name> ... ]
For detailed syntax and examples for creating/altering inline constraints, see CREATE | ALTER TABLE … CONSTRAINT.
privacyPolicyAction ::=
{
ADD PRIVACY POLICY <policy_name> [ ENTITY KEY ( <col_name> [ , ... ] ) ]
| DROP PRIVACY POLICY <policy_name>
}
For detailed syntax and examples for creating/altering inline constraints, see CREATE | ALTER TABLE … CONSTRAINT.
extTableColumnAction ::=
{
ADD [ COLUMN ] [ IF NOT EXISTS ] <col_name> <col_type> AS ( <expr> )
| RENAME COLUMN <col_name> TO <new_col_name>
| DROP [ COLUMN ] [ IF EXISTS ] <col1_name> [, <col2_name> ... ]
}
For detailed syntax and examples for creating/altering inline constraints, see CREATE | ALTER TABLE … CONSTRAINT.
constraintAction ::=
{
ADD outoflineConstraint
| RENAME CONSTRAINT <constraint_name> TO <new_constraint_name>
| { ALTER | MODIFY } { CONSTRAINT <constraint_name>
| PRIMARY KEY
| UNIQUE
| FOREIGN KEY } ( <col_name> [ , ... ] )
}
[ [ NOT ] ENFORCED ] [ VALIDATE | NOVALIDATE ] [ RELY | NORELY ]
| DROP { CONSTRAINT <constraint_name>
| PRIMARY KEY
| UNIQUE | FOREIGN KEY } ( <col_name> [ , ... ] )
[ CASCADE | RESTRICT ]
}
outoflineConstraint ::=
[ CONSTRAINT <constraint_name> ]
{
UNIQUE [ ( <col_name> [ , <col_name> , ... ] ) ]
| PRIMARY KEY [ ( <col_name> [ , <col_name> , ... ] ) ]
| [ FOREIGN KEY ] [ ( <col_name> [ , <col_name> , ... ] ) ]
REFERENCES <ref_table_name> [ ( <ref_col_name> [ , <ref_col_name> , ... ] ) ]
| CHECK ( <expr> )
}
[ <constraint_properties> ]
For detailed syntax and examples for creating/altering out-of-line constraints, see CREATE | ALTER TABLE … CONSTRAINT.
searchOptimizationAction ::=
{
ADD SEARCH OPTIMIZATION [
ON <search_method_with_target> [ , <search_method_with_target> ... ]
]
| DROP SEARCH OPTIMIZATION [
ON { <search_method_with_target> | <column_name> | <expression_id> }
[ , ... ]
]
}
Parameters
| Name | Required | Description |
|---|---|---|
name | Identifier for the table to alter. If the identifier contains spaces or special characters, the entire string must be enclosed in double quotes. Identifiers enclosed in double quotes are also case sensitive. | |
RENAME TO new_table_name | Renames the specified table with a new identifier that is not currently used by any other tables in the schema. For more information about table identifiers, see Identifier requirements. You can move the object to a different database and/or schema while optionally renaming the object. To do so, specify a qualified new_name value that includes the new database and/or schema name in the form db_name.schema_name.object_name or schema_name.object_name, respectively. Note The destination database and/or schema must already exist. In addition, an object with the same name cannot already exist in the new location; otherwise, the statement returns an error. Moving an object to a managed access schema is prohibited unless the object owner (that is, the role that has the OWNERSHIP privilege on the object) also owns the target schema. When an object (table, column, etc.) is renamed, other objects that reference it must be updated with the new name. | |
SWAP WITH target_table_name | Swap renames two tables in a single transaction. Note that swapping a permanent or transient table with a temporary table, which persists only for the duration of the user session in which it was created, is not allowed. This restriction prevents a naming conflict that could occur when a temporary table is swapped with a permanent or transient table, and an existing permanent or transient table has the same name as the temporary table. To swap a permanent or transient table with a temporary table, use three ALTER TABLE ... RENAME TO statements: Rename table a to c, b to a, and then c to b. | |
ADD STORAGE LIFECYCLE POLICY policy_name ON ( col_name [ , col_name ... ] ) | Attaches a storage lifecycle policy to the table. For more information about creating and managing storage lifecycle policies, see Create and manage storage lifecycle policies. Important If you attach an archival storage policy to a table, the table is permanently assigned to the specified archive tier for its lifetime. You can’t change the archive tier by applying a new policy. For example, you can’t specify a policy created with a COOL archive tier in ALTER TABLE…DROP STORAGE LIFECYCLE POLICY and then subsequently alter the table to add a policy created with a COLD archive tier. To alter the archive tier for a table, contact Snowflake Support to request deletion of the currently archived data. For additional considerations, see Archival storage policies. | |
DROP STORAGE LIFECYCLE POLICY | Removes the storage lifecycle policy from the table. For more information, see Remove a policy from a table. | |
SET ... | Specifies one or more properties/parameters to set for the table (separated by blank spaces, commas, or new lines): | |
DATA_RETENTION_TIME_IN_DAYS = integer | Object-level parameter that modifies the retention period for the table for Time Travel. For more information, see Understanding & using Time Travel and Working with Temporary and Transient Tables. For a detailed description of this parameter, as well as more information about object parameters, see Parameters. Values: Standard Edition: 0 or 1 Enterprise Edition: 0 to 90 for permanent tables 0 or 1 for temporary and transient tables Note A value of 0 effectively disables Time Travel for the table. | |
MAX_DATA_EXTENSION_TIME_IN_DAYS = integer | Object parameter that specifies the maximum number of days for which Snowflake can extend the data retention period for the table to prevent streams on the table from becoming stale. For a detailed description of this parameter, see MAX_DATA_EXTENSION_TIME_IN_DAYS. | |
CHANGE_TRACKING = { TRUE | FALSE } | Specifies to enable or disable change tracking on the table. TRUE enables change tracking on the table. This option adds several hidden columns to the source table and begins storing change tracking metadata in the columns. These columns consume a small amount of storage. The change tracking metadata can be queried using the CHANGES clause for SELECT statements, or by creating and querying one or more streams on the table. FALSE disables change tracking on the table. Associated hidden columns are dropped from the table. | |
DEFAULT_DDL_COLLATION = 'collation_specification' | Specifies a default collation specification for any new columns added to the table. Setting the parameter does not change the collation specification for any existing columns. For more information about the parameter, see DEFAULT_DDL_COLLATION. | |
ICEBERG_DEFAULT_DDL_COLLATION = 'collation_specification' | Specifies a default collation specification for new string columns on Snowflake-managed Iceberg tables. For more information about the parameter, see ICEBERG_DEFAULT_DDL_COLLATION. | |
ENABLE_SCHEMA_EVOLUTION = { TRUE | FALSE } | Enables or disables automatic changes to the table schema from data loaded into the table from source files, including: Added columns. By default, schema evolution is limited to a maximum of 100 added columns per load operation. To request more than 100 added columns per load operation, contact Snowflake Support. The NOT NULL constraint can be dropped from any number of columns missing in new data files. Setting it to TRUE enables automatic table schema evolution. The default FALSE disables automatic table schema evolution. Note Loading data from files evolves the table columns when all of the following are true: The COPY INTO <table> statement includes the MATCH_BY_COLUMN_NAME option. The role used to load the data has the EVOLVE SCHEMA or OWNERSHIP privilege on the table. For Snowpipe, the role that owns the pipe loads the data. Additionally, for schema evolution with CSV, when used with MATCH_BY_COLUMN_NAME and PARSE_HEADER, ERROR_ON_COLUMN_COUNT_MISMATCH must be set to false. To add nested columns as structured columns, also set the INFER_NESTED_TYPES copy option to TRUE. For more information, see Detect and evolve structured columns. | |
ERROR_LOGGING = { TRUE | FALSE } | Specifies whether to turn on error logging for the table. When error logging is turned on, DML statements and supported data loading methods record errors in the table’s error table. TRUE turns on error logging for the table. An INSERT, UPDATE, or MERGE statement on the table that encounters a supported error no longer fails. Instead, it writes the other rows and records the error. For COPY INTO and Snowpipe, the ON_ERROR copy option still determines how a load handles errors and which errors are recorded. To set this property for an existing table, use a role that owns the table. FALSE turns off error logging for the table. If the table has an error table, turning off error logging drops the error table and the errors in it. The error table stores the source data of each error. Before you turn on error logging for a table that stores sensitive data, review which roles can query the error table, as described in Access control requirements for error tables. For more information, see Introduction to error logging. For DML statements, see Error logging for DML statements. For the errors that error logging records when you load files with COPY INTO or Snowpipe, see Error logging for COPY INTO and Snowpipe. Note If the OPT_OUT_ERROR_LOGGING parameter is set to TRUE for a session, DML statements, CREATE TABLE ... AS SELECT statements, and COPY INTO statements in the session don’t record errors, regardless of whether error logging is turned on for specific tables. For Snowpipe, only the value that’s set for the account applies. For more information, see Prevent or limit error logging. | |
CONTACT purpose = contact [ , purpose = contact ... ] | Associate the existing object with one or more contacts. For a list of valid purposes, see Associate a contact with an object. You cannot set the CONTACT property with other properties in the same statement. | |
COMMENT = 'string_literal' | Adds a comment or overwrites the existing comment for the table. | |
ROW_TIMESTAMP = { TRUE | FALSE } | Adds or removes row timestamps on the table. TRUE adds row timestamps on the table. FALSE removes row timestamps on the table. This parameter setting permanently deletes all stored METADATA$ROW_LAST_COMMIT_TIME values. Reenabling it will not restore these values and Time Travel queries will return nothing. | |
UNSET ... | Specifies one or more properties/parameters to unset for the table, which resets them back to their defaults: DATA_RETENTION_TIME_IN_DAYS MAX_DATA_EXTENSION_TIME_IN_DAYS CHANGE_TRACKING DEFAULT_DDL_COLLATION ICEBERG_DEFAULT_DDL_COLLATION ENABLE_SCHEMA_EVOLUTION CONTACT purpose COMMENT ROW_TIMESTAMP You cannot unset the CONTACT property with other properties in the same statement. | |
CLUSTER BY ( expr [ , expr , ... ] ) | Specifies (or modifies) one or more table columns or column expressions as the clustering key for the table. These are the columns/expressions for which clustering is maintained by Automatic Clustering. Important Clustering keys are not intended or recommended for all tables; they typically benefit very large (that is, multi-terabyte) tables. Before you specify a clustering key for a table, please see Understanding Snowflake Table Structures. | |
CLUSTER BY AUTO | Enables automatic clustering key selection for the table. Snowflake chooses and applies the clustering key for you, and it can adjust the key over time. The table uses Optima Clustering. You can’t change an existing clustering key to AUTO. If the table already has a clustering key, use DROP CLUSTERING KEY first. For more information, see Automatic clustering key selection. | |
RECLUSTER ... | Deprecated Performs manual, incremental reclustering of a table that has a clustering key defined: Note Only roles with the OWNERSHIP or INSERT privilege on a table can recluster the table. | |
MAX_SIZE = budget_in_bytes | Deprecated — use a larger warehouse to achieve more effective manual reclustering Specifies the upper-limit on the amount of data (in bytes) in the table to recluster. | |
WHERE condition | Specifies a condition or range on which to recluster data in the table. | |
SUSPEND | RESUME RECLUSTER | Enables or disables Automatic Clustering for the table. | |
DROP CLUSTERING KEY | Drops the clustering key for the table. | |
ADD [ COLUMN ] [ IF NOT EXISTS ] col_name col_data_type [ AS ( expr ) ] [ DEFAULT default_value | AUTOINCREMENT ... ] [ inlineConstraint ] [ COLLATE 'collation_specification' ] [ [ WITH ] MASKING POLICY policy_name ] [ [ WITH ] PROJECTION POLICY policy_name ] [ [ WITH ] TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] ) ] [ , ...] | Adds a new column. You can specify a default value, an inline constraint, a collation specification, a masking policy, and/or one or more tags. You can’t add a column with an inline CHECK constraint to a table that a pipe loads, even if the pipe is paused. For more information, see Change the CHECK constraints on a table that a pipe loads. To add a virtual column whose values are computed from an expression, include AS ( <expr> ). For ANSI SQL compatibility, you can also use the equivalent [ GENERATED ALWAYS ] AS ( <expr> ) [ VIRTUAL ] form. When you specify AS, the DEFAULT clause and the NOT NULL and CHECK constraints can’t be applied to the same column. For the full list of allowed expressions, data type rules, and restrictions, see Virtual Columns. A default value for a column that you are adding must be a literal value; it cannot be an expression or a value returned by a function. For example, the following command returns an expected error:Copy code ALTER TABLE t1 ADD COLUMN c5 VARCHAR DEFAULT 12345::VARCHAR; 002263 (22000): SQL compilation error: Invalid column default expression [CAST(12345 AS VARCHAR(134217728))] When you first create a table, you can use expressions as default values, but not when you add columns. The default value for a column must match the data type of the column. An attempt to set a default value with a non-matching data type fails with an error. For example:Copy code ALTER TABLE t1 ADD COLUMN c6 DATE DEFAULT '20230101'; 002023 (22000): SQL compilation error: Expression type does not match column data type, expecting DATE but got VARCHAR(8) for column C6 For additional details about table column actions, see: CREATE TABLE CREATE | ALTER TABLE … CONSTRAINT CREATE MASKING POLICY CREATE TAG ADD COLUMN operations can be performed on multiple columns in the same command. If you are not sure if the column already exists, you can specify IF NOT EXISTS when adding the column. If the column already exists, ADD COLUMN has no effect on the existing column and does not result in an error. Note You cannot specify IF NOT EXISTS if you are also specifying any of the following for the new column: DEFAULT, AUTOINCREMENT, or IDENTITY UNIQUE, PRIMARY KEY, or FOREIGN KEY | |
RENAME COLUMN col_name to new_col_name | Renames the specified column to a new name that is not currently used for any other columns in the table. You cannot rename a column that is part of a clustering key. When an object (table, column, etc.) is renamed, other objects that reference it must be updated with the new name. | |
DROP COLUMN [ IF EXISTS ] col_name [ CASCADE | RESTRICT ] | Removes the specified column from the table. If you are not sure if the column already exists, you can specify IF EXISTS when dropping the column. If the column does not exist, DROP COLUMN has no effect and does not result in an error. DROP COLUMN is blocked if any virtual column in the table depends on the column being dropped, including chained dependencies between virtual columns. To drop the column, first drop the dependent virtual columns. Dropping a column is a metadata-only operation. It does not immediately re-write the micro-partition(s) and therefore does not immediately free up the space used by the column. Typically, the space within an individual micro-partition is freed the next time that the micro-partition is re-written, which is typically when a write is done either due to DML (INSERT, UPDATE, DELETE) or re-clustering. | |
DATA_METRIC_SCHEDULE ... | Specifies the schedule to run the data metric function periodically.
| |
'num MINUTE' | Specifies an interval (in minutes) of wait time inserted between runs of the data metric function. Accepts positive integers only. Also supports num M syntax. For data metric functions, use one of the following values: 5, 15, 30, 60, 720, or 1440. If you want to suspend all DMFs associated with the object, set the parameter to an empty string. Default: 60 MINUTE | |
'USING CRON expr time_zone' | Specifies a cron expression and time zone for periodically running the data metric function. Supports a subset of standard cron utility syntax. For a list of time zones, see the list of tz database time zones. The cron expression consists of the following fields, and the periodic interval must be at least 5 minutes:Copy code # __________ minute (0-59) # | ________ hour (0-23) # | | ______ day of month (1-31, or L) # | | | ____ month (1-12, JAN-DEC) # | | | | _ day of week (0-6, SUN-SAT, or L) # | | | | | # | | | | | * * * * * The following special characters are supported: Note The cron expression currently evaluates against the specified time zone only. Altering the TIMEZONE parameter value for the account (or setting the value at the user or session level) does not change the time zone for the data metric function. The cron expression defines all valid run times for the data metric function. Snowflake attempts to run a data metric function based on this schedule; however, any valid run time is skipped if a previous run has not completed before the next valid run time starts. When both a specific day of month and day of week are included in the cron expression, then the data metric function is scheduled on days satisfying either the day of month or day of week. For example, DATA_METRIC_SCHEDULE = 'USING CRON 0 0 10-20 * TUE,THU UTC' schedules a data metric function at 0AM on any 10th to 20th day of the month and also on any Tuesday or Thursday outside of those dates. The shortest granularity of time in cron is minutes. If a data metric function is resumed during the minute defined in its cron expression, the first scheduled run of the data metric function is the next occurrence of the instance of the cron expression. For example, if data metric function scheduled to run daily at midnight (USING CRON 0 0 * * *) is resumed at midnight plus 5 seconds (00:00:05), the first data metric function run is scheduled for the following midnight.
| |
* | Wildcard. Specifies any occurrence of the field. | |
UNSET DATA_METRIC_SCHEDULE | Resets the schedule for DMFs associated with the object to the default of 60 MINUTE. If you want to suspend DMFs associated with the object, run a SET DATA_METRIC_SCHEDULE = '' statement instead. | |
{ ADD | DROP } DATA METRIC FUNCTION metric_name | Identifier of the data metric function to add to the table or view or drop from the table or view. ANOMALY_DETECTION = { TRUE | FALSE } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Specifies whether Snowflake uses the DMF to automatically detect anomalies in the table. Default: FALSE SENSITIVITY = { LOW | MEDIUM | HIGH } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Specifies the sensitivity of the anomaly-detecting algorithm. For more information, see Adjust the sensitivity level of anomaly detection. Default: 'MEDIUM' ON_VIOLATION_ACTION = { ( TYPE = 'action_type' [ , TARGET = target_name ] ) | ( ( TYPE = 'action_type' [ , TARGET = target_name ] ) [ , ... ] ) } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Specifies one or more violation actions that run automatically when the DMF detects a data quality issue. To specify more than one action, use a parenthesized list of property blocks; you can specify up to eight actions, and each combination of TYPE and TARGET must be unique. For more information, see Set multiple violation actions. TYPE is one of the following: 'EXECUTE_TASK': Runs a task. Set TARGET to the task. For more information, see Run a task when a data quality check fails. 'SKIP_DOWNSTREAM_DYNAMIC_TABLE_REFRESH': Skips refreshes of downstream dynamic tables. Takes no TARGET. For more information, see Skip downstream dynamic table refreshes when a data quality check fails. Default: No violation action. | |
ON ( col_name [ , ... ] [ , TABLE( table_name( col_name [ , ... ] ) ) ] ) | The table or view columns on which to associate the data metric function. The data types of the columns must match the data types of the columns specified in the data metric function definition. If the data metric function accepts a second table as an argument, specify the fully qualified name of the table and its columns. | |
EXPECTATION expectation_name ( expression ) [, expectation_name ( expression ) [ , ... ] ] | Defines one or more expectations for the association between the column and the DMF. | |
[ , metric_name_2 ON ( col_name [ , ... ] [ , TABLE( table_name( col_name [ , ... ] ) ) ] ) ] | Additional data metric functions to add to the table or view. Use a comma to separate each data metric function and its specified columns. If the data metric function accepts a second table as an argument, specify the fully qualified name of the table and its columns. | |
EXECUTE AS ROLE role_name | Specifies which role the DMF runs with. The role must have the SELECT privilege on the table or view. For more information, see Required privilege on the table or view. | |
MODIFY DATA METRIC FUNCTION metric_name | Identifier of the data metric function to modify. | |
ON ( col_name [ , ... ] [ , TABLE( table_name( col_name [ , ... ] ) ) ] ) | Specifies the columns associated with the data metric function. If the data metric function accepts a second table as an argument, specify the fully qualified name of the table and its columns. | |
{ SUSPEND | RESUME } | Suspends or resumes the data metric function on the specified columns. When a data metric function is set for a table or view, the data metric function is automatically included in the schedule. SUSPEND removes the data metric function from the schedule. RESUME brings a suspended date metric function back into the schedule. | |
{ ADD | MODIFY } EXPECTATION expectation_name ( expression ) [, expectation_name ( expression ) [ , ... ] ] | Defines or modifies one or more expectations for the association between the column and the DMF. | |
DROP EXPECTATION expectation_name [ , expectation_name [ , ... ] ] | Removes the specified expectations from the association between the column and the DMF. | |
FILTER ( [ predicate ] ) | Sets, replaces, or clears the row filter on the association. Specify a Boolean expression to evaluate the DMF only on rows that satisfy the condition. Specify empty parentheses (FILTER ()) to remove the filter so the DMF evaluates all rows. You can’t combine FILTER with SUSPEND, RESUME, EXPECTATION, or SET in the same MODIFY statement. FILTER isn’t supported on associations that use WITHIN GROUP. For more information, see Apply data quality checks to a subset of rows. | |
[ , metric_name_2 ON ( col_name [ , ... ] [ , TABLE(col_name [ , ... ] ) ] ) ] | Additional data metric functions to modify. Use a comma to separate each data metric function and its specified columns. If the data metric function accepts a second table as an argument, specify the fully qualified name of the table and its columns. | |
SET list_of_properties | Sets one or more properties of the association between the DMF and the object. You set more than one property by using a space-delimited list. ANOMALY_DETECTION = { TRUE | FALSE } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Controls whether Snowflake uses the DMF to automatically detect anomalies in the table. SENSITIVITY = { 'LOW' | 'MEDIUM' | 'HIGH' } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Sets the sensitivity of the anomaly-detecting algorithm. For more information, see Adjust the sensitivity level of anomaly detection. DATA_QUALITY_NOTIFICATION = { TRUE | FALSE } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Controls whether notifications are sent when the value returned by the DMF is an expectation violation or an anomaly. Notifications are sent if the parameter is set to TRUE and notifications are turned on for the object’s database. Specify FALSE to turn off notifications for this object-DMF association even though notifications are sent for other associations in the database. For more information about configuring notifications, see Sending notifications for data quality issues. Default: TRUE ON_VIOLATION_ACTION = { ( TYPE = 'action_type' [ , TARGET = target_name ] ) | ( ( TYPE = 'action_type' [ , TARGET = target_name ] ) [ , ... ] ) | () } Preview Feature — Open Available to all accounts that are Enterprise Edition (or higher). To inquire about upgrading, please contact Snowflake Support. Sets, replaces, or removes the violation actions for the association. The new value replaces all existing actions. Specify a single property block or a parenthesized list of up to eight property blocks. For the supported action types, see Violation action types. To remove all actions, specify an empty property block: ON_VIOLATION_ACTION = (). | |
ADD [ COLUMN ] [ IF NOT EXISTS ] <col_name> <col_type> AS ( <expr> ) [, ...] | Adds a new column to the external table. If you are not sure if the column already exists, you can specify IF NOT EXISTS when adding the column. If the column already exists, ADD COLUMN has no effect on the existing column and does not result in an error. This operation can be performed on multiple columns in the same command.
| |
RENAME COLUMN col_name to new_col_name | Renames the specified column to a new name that is not currently used for any other columns in the external table. | |
DROP COLUMN [ IF EXISTS ] col_name | Removes the specified column from the external table. If you are not sure if the column already exists, you can specify IF EXISTS when dropping the column. If the column does not exist, DROP COLUMN has no effect and does not result in an error. | |
ADD CONSTRAINT | Adds an out-of-line integrity constraint to one or more columns in the table. To add an inline constraint (for a column), see Column Actions (in this topic). To add a CHECK constraint with this clause, specify ENABLE NOVALIDATE. The default, ENABLE VALIDATE, isn’t supported for CHECK constraints in this clause, so a statement without ENABLE NOVALIDATE fails. The constraint applies to rows that are inserted, updated, or loaded afterward, but not to the rows that the table already contains. You can’t add a CHECK constraint to a table that a pipe loads, even if the pipe is paused. For more information, see CHECK constraints and Change the CHECK constraints on a table that a pipe loads. | |
RENAME CONSTRAINT constraint_name TO new_constraint_name | Renames the specified constraint. | |
{ ALTER | MODIFY } CONSTRAINT ... | Alters the properties for the specified constraint. For CHECK constraints, the constraint_name is required. You can’t change a CHECK constraint on a table that a Snowpipe pipe loads, even if the pipe is paused. For more information, see Change the CHECK constraints on a table that a pipe loads. | |
DROP CONSTRAINT constraint_name | PRIMARY KEY | UNIQUE | FOREIGN KEY ( col_name [ , ... ] ) [ CASCADE | RESTRICT ] | Drops the specified constraint for the specified column or set of columns. For CHECK constraints, the constraint_name is required. You can’t drop a CHECK constraint on a table that a Snowpipe pipe loads, even if the pipe is paused. For more information, see Change the CHECK constraints on a table that a pipe loads. | |
TAG tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] | Specifies 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. | |
policy_name | Identifier for the policy; must be unique for your schema. | |
ADD ROW ACCESS POLICY policy_name ON (col_name [ , ... ]) | Adds a row access policy to the table. At least one column name must be specified. Additional columns can be specified with a comma separating each column name. Use this expression to add a row access policy to both an event table and an external table. | |
DROP ROW ACCESS POLICY policy_name | Drops a row access policy from the table. Use this clause to drop the policy from the table. | |
DROP ROW ACCESS POLICY policy_name, ADD ROW ACCESS POLICY policy_name ON ( col_name [ , ... ] ) | Drops the row access policy that is set on the table and adds a row access policy to the same table in a single SQL statement. | |
DROP ALL ROW ACCESS POLICIES | Drops all row access policy associations from the table. This expression is helpful when a row access policy is dropped from a schema before dropping the policy from an event table. Use this expression to drop row access policy associations from the table. Suppose that a row access policy applied to the table when the backup was created, and the policy was later dropped. After you restore the table from a backup, you can’t query it until you run an ALTER TABLE command with the DROP ALL ROW ACCESS POLICIES clause. | |
SET AGGREGATION POLICY policy_name | ||
[ ENTITY KEY (col_name [ , ... ]) ] [ FORCE ] | Assigns an aggregation policy to the table. Use the optional ENTITY KEY parameter to define which columns uniquely identity an entity within the table. For more information, see Implementing entity-level privacy with aggregation policies. Use the optional FORCE parameter to atomically replace an existing aggregation policy with the new aggregation policy. | |
UNSET AGGREGATION POLICY | Detaches an aggregation policy from the table. | |
SET JOIN POLICY policy_name | ||
[ FORCE ] | Assigns a join policy to the table. Use the optional FORCE parameter to atomically replace an existing join policy with the new join policy. | |
UNSET JOIN POLICY | Detaches a join policy from the table. | |
{ ALTER | MODIFY } [ COLUMN ] ... |
| |
USING ( col_name , cond_col_1 ... ) | Specifies the arguments to pass into the conditional masking policy SQL expression. The first column in the list specifies the column for the policy conditions to mask or tokenize the data and must match the column to which the masking policy is set. The additional columns specify the columns to evaluate to determine whether to mask or tokenize the data in each row of the query result when a query is made on the first column. If the USING clause is omitted, Snowflake treats the conditional masking policy as a normal masking policy. | |
ADD PRIVACY POLICY policy_name [ ENTITY KEY ( col_name [ , ... ] ) ] | Assigns a privacy policy to the table to protect it with differential privacy. Use ENTITY KEY to specify the column or columns that uniquely identify the entity (for example, a person) whose privacy is protected. | |
DROP PRIVACY POLICY policy_name | Removes the privacy policy from the table. | |
ADD SEARCH OPTIMIZATION | Adds search optimization for the entire table or, if you specify the optional ON clause, for specific columns. Note Search optimization can be expensive to maintain, especially if the data in the table changes frequently. For more information, see Search optimization cost estimation and management. If you try to add search optimization on a materialized view, Snowflake returns an error message. | |
ON search_method_with_target [, search_method_with_target ... ] | Specifies that you want to configure search optimization for specific columns or VARIANT fields (instead of the entire table). For search_method_with_target, use an expression with the following syntax:Copy code <search_method>( <target> [ , <target> , ... ] [ , ANALYZER => '<analyzer_name>' ] ) Where: search_method specifies one of the following methods that optimizes queries for a particular type of predicate: Search method Description FULL_TEXT Predicates that use VARCHAR (text), VARIANT, ARRAY, and OBJECT types. EQUALITY Equality and IN predicates. SUBSTRING Predicates that match substrings and regular expressions (for example, [ NOT ] LIKE, [ NOT ] ILIKE, [ NOT ] RLIKE, and REGEXP_LIKE). GEO Predicates that use GEOGRAPHY types.ExpandShow lessSee more target specifies the column, VARIANT field, or an asterisk (*). Depending on the value of search_method, you can specify a column or VARIANT field of one of the following types: Search method Supported targets FULL_TEXT Columns of VARCHAR (text), VARIANT, ARRAY, and OBJECT data types, including paths to fields in VARIANTs. EQUALITY Columns of numerical, string, binary, and VARIANT data types, including paths to fields in VARIANTs. SUBSTRING Columns of string or VARIANT data types, including paths to fields in VARIANTs. Specify paths to fields as described above under EQUALITY; searches on nested fields are improved in the same way. GEO Columns of the GEOGRAPHY data type.ExpandShow lessSee more To specify a VARIANT field, use dot or bracket notation (for example, my_column:my_field_name.my_nested_field_name or my_column['my_field_name']['my_nested_field_name']). You can also use a colon-delimited path to the field (for example, my_column:my_field_name:my_nested_field_name). When you specify a VARIANT field, the configuration applies to all nested fields under that field. For example, if you specify ON EQUALITY(src:a.b): This configuration can improve queries on src:a.b and on any nested fields (for example, src:a.b.c, src:a.b.c.d, etc.). This configuration does not affect queries that do not use the src:a.b prefix (for example, src:a, src:z, etc.). To specify all applicable columns in the table as targets, use an asterisk (*). Note that you cannot specify both an asterisk and specific column names for a given search method. However, you can specify an asterisk in different search methods. For example, you can specify the following expressions: Copy code -- Allowed ON SUBSTRING(*) ON EQUALITY(*), SUBSTRING(*), GEO(*) You cannot specify the following expressions: Copy code -- Not allowed ON EQUALITY(*, c1) ON EQUALITY(c1, *) ON EQUALITY(v1:path, *) ON EQUALITY(c1), EQUALITY(*) ANALYZER => 'analyzer_name' specifies the name of the text analyzer, if search_method is FULL_TEXT. When the FULL_TEXT search method is used and queries are executed with the SEARCH or SEARCH_IP function, the analyzer breaks the search terms (and the text from the column being searched) into tokens. A row matches if any of the tokens extracted from the search string matches a token extracted from any of the columns or fields being searched. The analyzer isn’t relevant when the FULL_TEXT search method isn’t used or for queries that don’t use the SEARCH or SEARCH_IP function. The analyzer tokenizes a string by breaking it where it finds certain delimiters. These delimiters are not included in the resulting tokens, and empty tokens are not extracted. This parameter accepts one of the following values: DEFAULT_ANALYZER: Breaks text into tokens based on the following delimiters: Character Unicode code Description `` U+0020 Space [ U+005B Left square bracket ] U+005D Right square bracket ; U+003B Semicolon < U+003C Less-than sign > U+003E Greater-than sign ( U+0028 Left parenthesis ) U+0029 Right parenthesis { U+007B Left curly bracket } U+007D Right curly bracket | U+007C Vertical bar ! U+0021 Exclamation mark , U+002C Comma ' U+0027 Apostrophe " U+0022 Quotation mark * U+002A Asterisk & U+0026 Ampersand ? U+003F Question mark + U+002B Plus sign / U+002F Slash : U+003A Colon = U+003D Equal sign @ U+0040 At sign . U+002E Period (full stop) - U+002D Hyphen $ U+0024 Dollar sign % U+0025 Percent sign \ U+005C Backslash _ U+005F Underscore (low line) \n U+000A New line (line feed) \r U+000D Carriage return \t U+0009 Horizontal tabExpandShow lessSee more UNICODE_ANALYZER: Tokenizes based on Unicode segmentation rules that treat spaces and certain punctuation characters as delimiters. These internal rules are designed for natural language searches (in many different languages). For example, the default analyzer treats periods in IP addresses and apostrophes in contractions as delimiters, but the Unicode analyzer does not. See Using an analyzer to adjust search behavior. For more information about the Unicode Text Segmentation algorithm, see https://unicode.org/reports/tr29/. NO_OP_ANALYZER: Tokenizes neither the data nor the query string. A search term must exactly match the full text in a column or field, including case sensitivity; otherwise, the SEARCH function returns FALSE. Even if the query string looks like it contains multiple tokens (for example, 'sky blue'), the column or field must equal the entire query string exactly. In this case, only 'sky blue' is a match; 'sky' and 'blue' are not matches. ENTITY_ANALYZER: Tokenizes the data for IP address searches. This analyzer is used only for queries executed with the SEARCH_IP function. To specify more than one search method on a target, use a comma to separate each subsequent method and target:Copy code ALTER TABLE t1 ADD SEARCH OPTIMIZATION ON EQUALITY(c1), EQUALITY(c2, c3); If you run the ALTER TABLE … ADD SEARCH OPTIMIZATION ON … command multiple times on the same table, each subsequent command adds to the existing configuration for the table. For example, suppose that you run the following commands:Copy code ALTER TABLE t1 ADD SEARCH OPTIMIZATION ON EQUALITY(c1, c2); ALTER TABLE t1 ADD SEARCH OPTIMIZATION ON EQUALITY(c3, c4); This adds equality predicates for the columns c1, c2, c3, and c4 to the configuration for the table. This is equivalent to running the command:Copy code ALTER TABLE t1 ADD SEARCH OPTIMIZATION ON EQUALITY(c1, c2, c3, c4); For examples, see Enabling search optimization for specific columns. | |
DROP SEARCH OPTIMIZATION | Removes search optimization for the entire table or, if you specify the optional ON clause, from specific columns. Note If a table has the search optimization property, then dropping the table and undropping it preserves the search optimization property. Removing the search optimization property from a table and then adding it back incurs the same cost as adding it the first time. | |
ON search_method_with_target | column_name | expression_id [ , ... ] | Specifies that you want to drop the search optimization configuration for specific columns or VARIANT fields (instead of dropping search optimization for the entire table). To identify the column configuration to drop, specify one of the following: For search_method_with_target, specify a method for optimizing queries for one or more specific targets, which can be columns or VARIANT fields. Use the syntax described earlier. For column_name, specify the name of the column configured for search optimization. Specifying the column name drops all expressions for that column, including expressions that use VARIANT fields in the column. For expression_id, specify the ID for an expression listed in the output of the DESCRIBE SEARCH OPTIMIZATION command. To specify more than one of these, use a comma between items. You can specify any combination of search methods with targets, column names, and expression IDs. For examples, see Dropping search optimization for specific columns. |
Usage notes: General
- Changes to a table are not automatically propagated to views created on that table. For example, if you drop a column in a table, and a view is defined to include that column, the view becomes invalid; the view is not adjusted to remove the column. - Dropping a column does not immediately free up the column’s storage space. The space in each micro-partition is not reclaimed until that micro-partition is re-written. Write operations (insert, update, delete, etc.) on 1 or more rows in that micro-partition cause the micro-partition to be re-written. If you want to force space to be reclaimed, you can follow these steps: Use a CREATE TABLE AS SELECT (CTAS) statement to create a new table that contains only the columns of the old table you want to keep. - Set the DATA_RETENTION_TIME_IN_DAYS parameter to 0 for the old table (optional). - Drop the old table. - If the table is protected by the Time Travel feature, the space used by the Time Travel storage is not reclaimed until the Time Travel retention period expires. - If a new column with a default value is added to a table with existing rows, all of the existing rows are populated with the default value. - Adding a new column with a default value containing a function is not currently supported. The following error is returned: Invalid column default expression (expr) - To alter a table, you must be using a role that has ownership privilege on the table. - To add clustering to a table, you must also have USAGE or OWNERSHIP privileges on the schema and database that contain the table. - For masking policies: The USING clause and the FORCE keyword are both optional; neither are required to set a masking policy on a column. The USING clause and the FORCE keyword can be used separately or together. For details, see: Apply a conditional masking policy on a column - Replace a masking policy on a column - A single masking policy that uses conditional columns can be applied to multiple tables provided that the column structure of the table matches the columns specified in the policy. - When modifying one or more table columns with a masking policy or the table itself with a row access policy, use the POLICY_CONTEXT function to simulate a query on the column(s) protected by a masking policy and the table protected by a row access policy. - For row access policies: Snowflake supports adding and dropping row access policies in a single SQL statement. For example, to replace a row access policy that is already set on a table with a different policy, drop the row access policy first and then add the new row access policy. - For a given resource (i.e. table or view), to ADD or DROP a row access policy you must have either the APPLY ROW ACCESS POLICY privilege on the schema, or the OWNERSHIP privilege on the resource and the APPLY privilege on the row access policy resource. - A table or view can only be protected by one row access policy at a time. Adding a policy fails if the policy body refers to a table or view column that is protected by a row access policy or the column protected by a masking policy. Similarly, adding a masking policy to a table column fails if the masking policy body refers to a table that is protected by a row access policy or another masking policy. - Row access policies cannot be applied to system views or table functions. - Similar to other DROP <object> operations, Snowflake returns an error if attempting to drop a row access policy from a resource that does not have a row access policy added to it. - If an object has both a row access policy and one or more masking policies, the row access policy is evaluated first. - When you attach a storage lifecycle policy to a table by using the ADD STORAGE LIFECYCLE POLICY option: You must have the necessary privileges to apply the policy. For information about required privileges, see Storage lifecycle policy privileges. - A table can have only one attached storage lifecycle policy. - The number of columns must match the argument count in the policy function signature, and the column data must be compatible with the argument types. - Associated policies aren’t affected if you rename table columns. Snowflake associates policies to tables by using the column IDs. - In order to evaluate and apply storage lifecycle policy expressions, Snowflake internally and temporarily bypasses any governance policies on a table. - If you create a foreign key, the columns in the REFERENCES clause must be listed in the same order as they were listed for the primary key. For example: Copy code CREATE TABLE parent ... CONSTRAINT primary_key_1 PRIMARY KEY (c_1, c_2) ... CREATE TABLE child ... CONSTRAINT foreign_key_1 FOREIGN KEY (...) REFERENCES parent (c_1, c_2) ... In both cases, the order of the columns is c_1, c_2. If the order of the columns in the foreign key had been different (for example, c_2, c_1), the attempt to create the foreign key would have failed. - 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. - ALTER TABLE … CHANGE_TRACKING = TRUE When a table is altered to enable change tracking, the table is locked for the duration of the operation. Locks can cause latency with some associated DDL/DML operations. For more information, refer to Resource locking. - Indexes in hybrid tables: When you use the ALTER TABLE command to add or drop a UNIQUE or FOREIGN KEY constraint in a hybrid table, the corresponding index is also created or dropped. For more information about hybrid table indexes, see CREATE INDEX. - Adding a UNIQUE or FOREIGN KEY constraint to a hybrid table is an online operation. Snowflake builds the index that backs the constraint in the background, and the table remains available for SELECT and DML statements while the build runs. The ALTER TABLE statement returns before the build finishes, so use SHOW INDEXES to check the status column for BUILD IN PROGRESS or ACTIVE. Snowflake builds one index at a time for a given hybrid table. - If rows that are already in the table violate the constraint you’re adding, the ALTER TABLE statement still succeeds, but the background build fails validation and SHOW INDEXES reports a status of BUILD VALIDATION FAILURE. The constraint continues to enforce new writes while it’s in this state. To recover, drop the constraint, correct the offending rows, and add the constraint again. For more information, see When existing data violates the constraint. - FOREIGN KEY constraints are supported only across hybrid tables that are stored in the same database. You cannot move a hybrid table from one database to another. The PRIMARY KEY, UNIQUE, and FOREIGN KEY constraints defined on hybrid tables have their RELY property marked as TRUE. - A column that is used by an index cannot be dropped before the corresponding index is dropped. - For interactive tables, ALTER TABLE supports the following operations: Renaming the table. - Modifying columns to set or unset comments. - Setting or unsetting masking policies on columns. - Adding or unsetting a masking policy, join policy, aggregation policy, or row access policy on the table. - Adding a storage lifecycle policy to the table, or dropping a storage lifecycle policy from the table. - Setting or unsetting tags.
Usage notes: Data metric functions
Add a DMF to a table:: Prior to adding a data metric function to a table, you must: Set the schedule for the data metric function to run. For details, see DATA_METRIC_SCHEDULE. Configure the event table to store the results of calling the data metric function. For details, see View results of a data metric function. Ensure that the table is view is not granted to a share because you cannot set a data metric function on a shared table or view. Additionally: When you specify a column, Snowflake uses the ordinal position. If you rename a column after adding a data metric function to the table or view, the association of the data metric function to the column remains valid. Only one data metric function of its kind can be added to a column. For example, a NULL_COUNT data metric function cannot be added to a single column twice. If you drop a column after adding a data metric function that references the column, Snowflake cannot evaluate the data metric function. Referencing a virtual column is not supported. Schedule a DMF: It takes ten minutes for the schedule to become effective once the schedule is set. Similarly, it takes ten minutes once the DMF is unset for the scheduling changes to take effect. For more information, see Adjust the schedule for DMFs.
Known gaps
- CLUSTER BY AUTO, ON_VIOLATION_ACTION are not exercised by any test