开发者

Create Table by Copying Structure of Existing Table

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 开发者_JS百科appreciated. Thanks.

CREATE TABLE Drop_Centers_Detail
    AS (Select * From Centers_Detail)


like this, however this will not create indexes and constraints

select * into Drop_Centers_Detail
from Centers_Detail
where 1 = 0


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜