Solved

inserting values into mysql table

Posted on 2006-10-28
8
328 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
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 41 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 41 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 113
Working with SharePoint Data 8 54
Oracle Public Synonyms and Privileges 2 66
Input Data Using a unique ID from another sheet in Excel 3 45
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

821 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