CTAS syntax for creating tables in SQL Server

Create structure, duplicate & backup of the table in SQL Server

Use of CTAS for creating the Duplicate table with data or only structure (by using where 1 = 0) in the database as follows:

Use CTAS syntax to create a table with same structure:

-- Create only structure of table
select * into backup_table from employees where 1=0;

Copy the table or take backup of table with data in SQL:

-- Create structure with completed data
Select * into backup_employee from employees;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.