Copy an existing MySQL table to a new table

Записки веб разработчика

Вторник, 2 Январь. 2007

Copy an existing MySQL table to a new table


This is a great set of two commands that allow the creation and population of a new table with the structure and data of an existing table. This provides a quick means of making a point-in-time copy of a table and is a safe, easy way to make a quick copy of a table for testing an application in development on live data without risking a production environment.
To make a copy of the table recipes which is in a different database called production into a new table called recipes_new in the currently selected database, use these two commands:



CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;


The first command creates the new table recipes_new by duplicating the structure of the existing table. The second command copies the data from old to new.

The nomenclature production.recipes is a means of specifying the database and table in the same way that a file can be specified by its directory path. It is optional. If production was left off, MySQL would assume that the recipes table was also in the currently selected database.


http://www.tech-recipes.com/mysql_tips1487.html
Defined tags for this entry: 1
Twitter Bookmark Copy an existing MySQL table to a new table  at del.icio.us Facebook Google Bookmarks FriendFeed Digg Copy an existing MySQL table to a new table Mixx Copy an existing MySQL table to a new table Bloglines Copy an existing MySQL table to a new table Technorati Copy an existing MySQL table to a new table Fark this: Copy an existing MySQL table to a new table Bookmark Copy an existing MySQL table to a new table  at YahooMyWeb Bookmark Copy an existing MySQL table to a new table  at Furl.net Bookmark Copy an existing MySQL table to a new table  at reddit.com Bookmark Copy an existing MySQL table to a new table  at blinklist.com Bookmark Copy an existing MySQL table to a new table  at Spurl.net Bookmark Copy an existing MySQL table to a new table  at NewsVine Bookmark Copy an existing MySQL table to a new table  at Simpy.com Bookmark Copy an existing MySQL table to a new table  at blogmarks Bookmark Copy an existing MySQL table to a new table  with wists Bookmark Copy an existing MySQL table to a new table  at Ma.gnolia.com wong it! Bookmark using any bookmark manager! Stumble It! Print this article! E-mail this story to a friend!

Обратные ссылки

Нет обратных ссылок

Комментарии
Показывать комментарии (Как список | Древовидной структурой)

Нет комментариев.


Добавить комментарий

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA