Question

I am trying to create a new table by copying an existing table in SQL Server 2008 using Management Studio. The existing table contains no data. I am using the following code but am receiving an error for Incorrect Syntax near AS. I am not sure what is wrong here. I am a SQL newb and any help would be appreciated. Thanks.

CREATE TABLE Drop_Centers_Detail
    AS (Select * From Centers_Detail)
Was it helpful?

Solution

like this, however this will not create indexes and constraints

select * into Drop_Centers_Detail
from Centers_Detail
where 1 = 0

OTHER TIPS

In Sql Server Managment Studio, right-click your existing table and select Script Table as > Create to > New Query Editor Window. This will give you a better starting script that you can use as the base for your new schema.

1) I would suggest generating a create script from the table you want to copy, and then run that on your destination database.

2) Write a Insert statement in another SQL Query window to import that data

Insert Into Database1.Table1(Field1, Field2) Select Field1, Field2 From Database2.Table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top