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
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.
SnowConvert does not perform this setup automatically.
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.
For further details visit CREATE MASKING POLICY — Snowflake Documentation.
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.
Related EWIs
SSC-EWI-0040: Statement Not Supported.
SSC-EWI-TS0061: ALTER COLUMN not supported.
SSC-EWI-TS0078: Default value not allowed in Snowflake.
SSC-FDM-TS0009: Encrypted with not supported in Snowflake.
SSC-FDM-TS0021: A MASKING POLICY was created as a substitute for MASKED WITH.
SSC-FDM-TS0022: The user must previously define the masking role.
SSC-PRF-0002: Case-insensitive columns can decrease the performance of queries.
Last updated