I would like to create a table using a select statement and add a column with row numbers
So I'd like to write something like:
create table schema.table_w_rownumbers as 
select 
    identity(1, 1) as nrum,
    foo.*
from schema.initial_table as foo;
I would like to create a table using a select statement and add a column with row numbers
So I'd like to write something like:
create table schema.table_w_rownumbers as 
select 
    identity(1, 1) as nrum,
    foo.*
from schema.initial_table as foo;
 
    
    This worked for me!
create table schema.table_w_rownumbers as 
select 
  row_number() over (partition by 1) as nrum,
  foo.*
from schema.initial_table as foo;
 
    
    Try this code. Make sure you change order by id to whatever it needs to be ordered by.
Create Table schema.table_w_rownumbers
AS
(
select row_number() over (order by id) as nrum, * schema.initial_table
);
