2

For example, I have a table named movies. It has the fields/columns title VARCHAR(100) and runtime INT(5). It's loaded with 10,000 rows of data.

I want to create another table, let's call it movies_custom, that has all of the same columns, but with none of the data.

Is there a quick SQL statement to do this?

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

3 Answers3

1

EDIT: Sorry, I noticed the SQL Server tag on this and assumed that was the technology you were using until I saw MySQL in the question title.

You can use the syntax CREATE movies_custom LIKE movies in MySQL


Sure!

In SQL Server you can do this query:

select top 0 * into movies_custom from movies

That creates the table structure without inserting any rows.

Derek
  • 21,828
  • 7
  • 53
  • 61
1

Very easy in MySQL:

CREATE newtable LIKE oldtable;
0

The other answers led me in the right direction, but I had to add the keyword TABLE in order to make it work with MySQL Workbench 6.

CREATE TABLE movies_custom LIKE movies;
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194