How create in SQL Server empty table based on existing table filled data ?

In this topic I show You how create table of the same structure as table in your database but empty.

It is very simple. You of course may use CREATE TABLE statement, but it take You a lot of time, especially as You have a lot of columns. You may in this situation pay attention for datatypes and names columns.

My the way to resolve this problem is use SELECT INTO statement and TOP clause with 0 value.

For example the table of Person name from AdventureWorks2012 database has 19 972 rows.
AAA2
In the example below I create empty table of the same structure as Person table from AdventureWorks2012 database.

SELECT TOP 0 * INTO [AdventureWorks2012].[Person].[NewPerson] 
FROM [AdventureWorks2012].[Person].[Person];

If You use SELECT query You see empty new table.

 SELECT * FROM [AdventureWorks2012].[Person].[NewPerson]

AAA1

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.