Search code examples
snowflake-cloud-data-platformnullablecreate-table

Snowflake create table like another table but set all columns to nullable


as the subject line says, I would like to automatically create tables based on a list of tables in an excel, but if these are tables ending with _ERR, I want to strip any non-null limitations (a flaw in the old system).

Is there a way to do that? Just the actual statement, the rest of the logic is covered.

So something like :

CREATE TABLE … LIKE ... SET NULLABLE

would be nice.

Thank you!


Solution

  • CREATE [ OR REPLACE ] TABLE <table_name> LIKE <source_table>

    then use alter to remove the NULL.

    ALTER TABLE t1 ALTER COLUMN c1 DROP NOT NULL;