COLUMN DEFINITION

ALTER TABLE ADD column_name

Some parts in the output code are omitted for clarity reasons.

Description

Specifies the properties of a column that are added to a table by using ALTER TABLE.

Adding a column definition in Snowflake does have some differences compared to SQL Server.

For instance, several parts of the SQL Server grammar are not required or entirely not supported by Snowflake. These include:

Additionally, a couple other parts are partially supported, and require additional work to be implemented in order to properly emulate the original functionality. Specifically, we're talking about the MASKED WITH property, which will be covered in the patterns section of this page.

Syntax in SQL Server

column_name <data_type>  
[ FILESTREAM ]  
[ COLLATE collation_name ]   
[ NULL | NOT NULL ]  
[
    [ CONSTRAINT constraint_name ] DEFAULT constant_expression [ WITH VALUES ]   
    | IDENTITY [ ( seed , increment ) ] [ NOT FOR REPLICATION ]   
]
[ ROWGUIDCOL ]   
[ SPARSE ]   
[ ENCRYPTED WITH  
  ( COLUMN_ENCRYPTION_KEY = key_name ,  
      ENCRYPTION_TYPE = { DETERMINISTIC | RANDOMIZED } ,   
      ALGORITHM =  'AEAD_AES_256_CBC_HMAC_SHA_256'   
  ) ]  
[ MASKED WITH ( FUNCTION = ' mask_function ') ]  
[ <column_constraint> [ ...n ] ]  

Snowflake

Sample Source Patterns

Basic pattern

This pattern showcases the removal of elements from the original ALTER TABLE.

SQL Server

Snowflake

COLLATE

Collation allows you to specify broader rules when talking about string comparison.

SQL Server

Since the collation rule nomenclature varies from SQL Server to Snowflake, it is necessary to make adjustments.

Snowflake

MASKED WITH

This pattern showcases the translation for MASKED WITH property. CREATE OR REPLACE MASKING POLICY is inserted somewhere before the first usage, and then referenced by a SET MASKING POLICY clause. The name of the new MASKING POLICY will be the concatenation of the name and arguments of the original MASKED WITH FUNCTION, as seen below:

SQL Server

Snowflake

DEFAULT

This pattern showcases some of the basic translation scenarios for DEFAULT property.

SQL Server

Snowflake

ENCRYPTED WITH

This pattern showcases the translation for ENCRYPTED WITH property, which is commented out in the output code.

SQL Server

Snowflake

NOT NULL

The SQL Server NOT NULL clause has the same pattern and functionality as the Snowflake NOT NULL clause

SQL Server

Snowflake

IDENTITY

This pattern showcases the translation for IDENTITY. The NOT FOR REPLICATION portion is removed in Snowflake.

SQL Server

Snowflake

Unsupported clauses

FILESTREAM

The original behavior of FILESTREAM is not replicable in Snowflake, and merits commenting out the entire ALTER TABLE statement.

SQL Server

Snowflake

SPARSE

In SQL Server, SPARSE is used to define columns that are optimized for NULL storage. However, when we're using Snowflake, we are not required to use this clause.

Snowflake performs optimizations over tables automatically, which mitigates the need for manual user-made optimizations.

SQL Server

Snowflake

ROWGUIDCOL

SQL Server

Snowflake

Known Issues

1. Roles and users have to be previously set up for masking policies

Snowflake's Masking Policies can be applied to columns only after the policies were created. This requires the user to create the policies and assign them to roles, and these roles to users, in order to work properly. Masking Policies can behave differently depending on which user is querying.

2. Masking policies require a Snowflake Enterprise account or higher.

higher-rankThe Snowflake documentation states that masking policies are available on Entreprise or higher rank accounts.

3. DEFAULT only supports constant values

SQL Server's DEFAULT property is partially supported by Snowflake, as long as its associated value is a constant.

4. FILESTREAM clause is not supported in Snowflake.

The entire FILESTSTREAM clause is commented out, since it is not supported in Snowflake.

5. SPARSE clause is not supported in Snowflake.

The entire SPARSE clause is commented out, since it is not supported in Snowflake. When it is added within an ALTER COLUMN statement, and it's the only modification being made to the column, the entire statement is removed since it's no longer adding anything.

Last updated