MySQL > Administration > Syntax > Intra-database exporting and Importing via SQL Editor PDF Print E-mail
User Rating: / 0
PoorBest 
Written by laughzilla   
Sunday, 22 June 2008 21:41
Ever wonder how to do a quick and efficient import of a bunch of records from one table into another table? Well, this article explains how to do this in just one command. And it works with any MySQL 4.x and 5.x database.

Here's how...


# HOW TO DO A MYSQL IMPORT VIA SQL COMMAND LINE EDITOR

This page shows you how to import contents of one table into another table within a MySQL database. You can also use this technique (modified a little) to import contents of one table in one mysql database, into another table on another mysql db.

This works if you are using command line. If you're using a web GUI like phpMyAdmin or some other kind of gui to admin your mysql dbs, go to your application's sql editor field.

ie: in phpmyadmin > db > table > SQL:

ie: in phpmyadmin > rubber_widgets_database > color_choices_table_2008 > SQL:


Here is a template of the syntax to use for this kind of task:

INSERT INTO `color_choices_table_2008` (`catid`, `aid`, `title`, `time`, `column5`, `column6`, `column7`) SELECT `catid`, `aid`, `title`, `time`, `column5`, `column6`, `column7` FROM `color_choices_table_2007`

The line above inserts records from the color_choices_table_2007 table into the color_choices_table_2008 table.

Note: In order for this to work without a hitch, the source and target tables should have the same table structure.

Note: Be sure not to copy your Primary Key Column, so that when you import your data, you will get a unique ID for each new record you imported into the target table, which also avoids any conflicts with existing records.

# # # # #  IMPORTS AND EXPORTS DRIVE MUCH OF ANY ECONOMY  # # # # #

more digital solutions found at:
MySQL.org
xdose.com
ContentAndAds.com
qmailrocks.org
FreeBSDRocks.net
TheSwamp.info
FileCorner.com
Last Updated ( Tuesday, 28 October 2008 21:00 )
 


Banner


Valid XHTML and CSS.