Question

I have a SQL Server table with several columns, an index starting from 1 as primary key.

Now I need to clone this table but without the data and with a different index, let's say starting from 100 000. I have never done this before so I am quite unsure about how to do it. I know how to create a new table,

CREATE TABLE new_table
AS (SELECT * FROM old_table);

but I do not know how to start the index from 100 000 and clone it without the data from the original table keeping the structure and the datatype exactly the same. Some help will be appreciated.

I am using SQL Server 2012 Express that came with Visual Studio 2012.

Était-ce utile?

La solution

SQL Server does not support CREATE TABLE AS SELECT.

Use this

SELECT  *
INTO    new_table
FROM    old_table

or

SELECT TOP 0 * INTO new_table FROM old_table

Autres conseils

Try this

CREATE TABLE new_table AS SELECT TOP 0 * FROM old_table 

try this SELECT TOP 0 * INTO newTable FROM OldTable

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top