There are two ways of copying the structure of an existing table in SQL Server. Either we can copy the structure aong with existing data or structure of table alone. Please find below the sample for both:
Copying table structure with existing data:
SELECT *INTO new_table_name
FROM old_table_name
This query will create a new table new_table_name
Copying table structure without data:
At times, we may require to create a table with the existing table structure. But, we may not require to copy the existing data into that. We can use the following snippet in that case:
SELECT *INTO new_table_name
FROM old_table_name
WHERE 1>2
This query will create table new_table_name
Gurus, I hope this might be helpful for you. Will try to add more stuffs in future.
Signing off with regards,
- Harikaran.S
No comments:
Post a Comment