I'm learning SQL and Snowflake and I'd like to change some metadata of a table. I'm trying to understand what is a good practice in the following case.
I want to change properties for 4 columns (but not all in the Table):
1. COLUMN_DEFAULT for 2 columns
2. IS_NULLABLE for 2 columns
Additionally, the table already is filled with values. I need to preserve data in the table. Only those 4 columns that need to have properties changed will have different values.
What would be the best approach?
Is that the correct way of doing it?
Or maybe:
Or maybe somet other way is better? I'd appreciate your suggestions.
Default Column: Unfortunately, we can't add a default for an existing column or modify it unless the default value is the sequence. The feature to add a default value for a column using an alter statement is not supported in Snowflake as documented here. The workaround is to recreate the table with the default value and reload the data.
Reference: https://docs.snowflake.com/en/sql-reference/sql/alter-table-column.html
Not Null:
alter table t1 alter column c1 set not null;
When setting a column to NOT NULL, if the column contains NULL values, an error is returned and no changes are applied to the column.