Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

inserting values into mysql table

Posted on 2006-10-28
8
Medium Priority
?
362 Views
Last Modified: 2010-08-05
Probably basic, but I am a novice in mysql....just able to manipulate data in phpmyadmin and run rudimentary queries.

I have two tables in two different mysql databases.
Want to move the older table values into the new one.
The new table has more field rows (89) than the old one that is populated with values (72).
Both tables have the same field names, its is just that there are new ones added to the newer version of the dbase.

Is there a way to import by matching the field names or something like that?  Or how do I enter null values or deault values into the old table's data so it matches up with the number of fields in the new table? Or basically what is the best way to match these up so I can import the data to the new table?

Thanks.
0
Comment
Question by:Steve_Newbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 172 total points
ID: 17825098
hi

if the table don't have many rows (that is only couple of thousends)
you can define in one of the databases a connected table (it' s a reference to a table at a remote mysql server)
and then you can just do insert as select from the old table to the new table,
while you perform the select , you can add the default values you wish to enter into the new tables,
if your columns are in the same order , all you will have to do is :

insert into new_table
select *, add_values_here
from old_table

if your table has many rows, you might consider doing this inside a procedure with some commit logic, or try to do it using export from the old table, aNd import to the new one
if you choose the export import approch, then you will have to define default values for all the new columns in the new table (when you create it or by using alter table)

momi
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 164 total points
ID: 17825387
You could create a temporary table with the same structure as the old table, import it, then
insert into new_table
(col1
,col2
...
,col72
,col73
...
,col89)
select
 col1
,col2
...
,col72
,null
...
,null)
0
 

Author Comment

by:Steve_Newbie
ID: 17826233
I'm sort of following both of the answers which seem similar, but need it a little more specific to my field nomenclature and dumbed-down even more......just think of me as Homer Simpson I guess..

This is  member profiles table by the way, and there are about 100 of them.....so basically 100 rows of data.

Specifically I have the old table showing something like this:
ID
Name
Country
ZIP
Date of Birth  etc. etc. etc.

New table has added extra fields like the following
ID
Name
Profile Type
Country
State
Zip
Date of Birth etc. etc. etc.

So, for this abbreviated example, what language or queries do I use to cover the extra fields of "Profile Type" and "State" in the new table?  The current/old profiles table has not have values assigned to "Profile Type" or "State" .

Is there a simple way, using the example above to use the intrinsic functions of "Import" "Export" or "Operations" within phpmyadmin?  If not, do I have to use different software to create tables for export, import etc., again specifically using the abbreviated table fields examples noted above?  I have SQLyog Pro but have not used it much.  


Thanks much!
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:Steve_Newbie
ID: 17826518
I have now purchased SQLyog Eneterprise to be able to do more advanaced synch operations, especially since I need a bonehead easy way to do this....
Anyway, even using that, when I specifically select  ONLY one field to synch data (e.g. ID field which exists in both tables).....it comes back with an error sawing that the field count is not equal between the tables.  What am I missing here?  I selected only ONE field to synch...why should it care about the other fields in the table in this case?

Thanks.
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 17828135
hi

i'm not familiar with SQLyog but maybe when you select sync by field, then the field you choose is the field used to make the comparison (maybe that field defines the primary key for the 2 tables)

momi
0
 
LVL 2

Assisted Solution

by:Tayger
Tayger earned 164 total points
ID: 17829684
Take care of inserting/overriding fields if they

a) have a primary key or foreign key on it
b) have "enum" (automatic) counter on it

To a)
Disable/delete them before inserting

To b)
MySQL will set a ID into those automatically when you do a insert. Ignore those fields on inserting (exclude them from export/import). Just let MySQL do the job on those.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question