Solved

inserting values into mysql table

Posted on 2006-10-28
8
301 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
8 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 43 total points
Comment Utility
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 31

Assisted Solution

by:awking00
awking00 earned 41 total points
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Steve_Newbie
Comment Utility
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
Comment Utility
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 41 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now