-2

I made a select statement from different tables. Now i need to make out of it an actual table. But i need to add unique Id to all the records. What should i add to my code?

select
...Some Select statement...

into NewTable
from Customer
  • Your original query: `SELECT col1, col2 FROM sometable WHERE somecondition`. Your new query: `SELECT col1, col2 INTO newtable FROM sometable WHERE somecondition` No need for extra selects, just drop your INTO clause before the `FROM` clause and run. – JNevill Oct 28 '22 at 13:53
  • You can 1) Create an empty table with the unique constraint and then populate with the insert, or 2) Create the table with the insert, and later add the unique constraint. – The Impaler Oct 28 '22 at 14:14

1 Answers1

0

You can create the identity when you select into

select identity(int, 1, ,1) as ID, other columns...
into NewTable
from Customer
Robert Sievers
  • 1,277
  • 10
  • 15
  • Thanks! It was helpful! Other question - how do i make this ID unique? Like this https://stackoverflow.com/questions/20674282/how-to-automatically-generate-unique-id-in-sql-like-uid12345678 – artem keller Oct 31 '22 at 07:24
  • You would have to be more specific as to what exactly you want the column to look like. – Robert Sievers Oct 31 '22 at 14:00