Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Query Create a new Table

Tags:

sql

Can anyone offered syntax for a sql query that takes an already created table and inserts some of the data into a new table with a new id(primary key)? So far I tried this

SELECT ((ID INT IDENTITY(1,1) PRIMARY KEY), column1, column2, column3)
INTO table_name
FROM table_name 

I keep coming up with a syntax error.

like image 920
developthestars Avatar asked Aug 14 '26 09:08

developthestars


2 Answers

SELECT column1, column2, column3
INTO table_name_new
FROM table_name_old

use like this

like image 145
Darshana Avatar answered Aug 16 '26 23:08

Darshana


INSERT INTO newtable (column1, column2, column3)
SELECT (column1, column2, column3) 
FROM table_name  
like image 22
Mitch Wheat Avatar answered Aug 17 '26 01:08

Mitch Wheat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!