SQL Server How do I resolve this error on the select keyword [duplicate]

sgtfey8w  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(106)

This question already has answers here:

How to create table using select query in SQL Server? (5 answers)
Closed 2 days ago.

I wanted to create a new table from an existing table however, at present, I get an error on the SELECT keyword, I've tried aliasing it but that didn't work.

I've tried aliasing it and checking the columns to see if I had misspelt anything or if I was calling the correct database or not and everything seems to be in order.

SQL:

create table testTable as 
select CompanyName as customer_companyname
, contactname 
from Customers;

Error:

Incorrect syntax near the keyword 'select'.

yyyllmsg

yyyllmsg1#

You can't create a table via create table ... select ... syntax.

You can use select ... into ... to create a table with a similar schema to the source table, containing the selected data; but it won't be identical to the original table (e.g. things like keys will be missing). Select Into Docs

Or you can use a Create Table ... statement with a suitable definition to create the table, followed by Insert Into ... to populate the data in that table.

相关问题