Creating a table by copying the structure of an existing table

I am trying to create a new table by copying an existing table in SQL Server 2008 using Management Studio. There is no data in the existing table. I use the following code, but I get an error message for the wrong syntax next to AS. I'm not sure what is wrong here. I am SQL newb and any help would be greatly appreciated. Thanks.

CREATE TABLE Drop_Centers_Detail AS (Select * From Centers_Detail) 
+4
source share
3 answers

like this however it will not lead to the creation of indexes and restrictions

 select * into Drop_Centers_Detail from Centers_Detail where 1 = 0 
+7
source

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

+3
source

1) I would suggest creating a script from the table that you want to copy and then run it in your target database.

2) Write an Insert statement in another SQL Query window to import this data

Insert into database1.Table1 (Field1, Field2) Select Field1, Field2 from Database2.Table

0
source

Source: https://habr.com/ru/post/1310277/


All Articles