No computed columns in a table created with Create Table As Select

commands:
create table source_tbl (id bigint NOT NULL, id_plus_one as id + 1 PERSISTED bigint);
create table target_tbl (key (id) USING CLUSTERED COLUMNSTORE) as select * from source_tbl;

desired outcome:
column id_plus_one would still be a computed column in target_tbl.

current outcome:
column id_plus_one is not a computed column in target_tbl

I would appreciate any answer, thank you for your time!

CREATE TABLE AS SELECT just takes the column data values (not column schema definitions) that it gets and creates the target table columns with actual values. To do what you want, you’d need to do:

  1. create target table with desired schema, including computed columns
  2. do insert into… select from… of only the non-computed source table columns to populate that target table

mm I see, thank you for your answer :slight_smile: