Copy table schema only

Need to duplicate a table’s schema?  Use a SELECT…INTO…FROM  statement:

SELECT * INTO new_tbl
FROM old_tbl

This will create a copy of the table, data and all.  What if you don’t want the data copied with the schema?  My friend Alessandro Basso uses this method:

SELECT * INTO new_tbl
FROM old_tbl
WHERE 1=2

Genius!
About these ads

Posted on June 29, 2011, in SQL Server. Bookmark the permalink. Leave a comment.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: