SQL: How to copy just table structure or create a table from another table without copying any values from the old table?


Here’s how it can be done:

CREATE TABLE new_table
AS (SELECT * FROM old_table WHERE 1=2);

Eg:

CREATE TABLE student
AS (SELECT * FROM person WHERE 1=2);

This would create a new table called student that includes all columns from the person table, but no data from the person table.

About these ads

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.

Join 27 other followers

%d bloggers like this: