Importing data from old Access database to new database

I have a situation where I have created a new database with tables that have relationships.  The tables are empty in the new database.

My goal is to take the data from my old database and place it into the new database.  My problem is that the old database is only one large table, while my newer one is normalized (I split the fields into separate related tables).  Is there a way to import the records into my newer database and specify which of the old fields go to which new tables for that the relationship so each record is kept with the correct data?

Any point in the right direction would be greatly appreciated as I am on a short timeline for this project.

Thank you.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

Actually this isn't difficult given your situation. Since your data is currently in only one table, you link that table to your new database, then run a series of Append queries to move the data into the new tables. Just make sure to include the old PK into the new FKs.
Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you for the quick response!

 

Sorry I am pretty new to Access/databases.  To be more specific on my scenario:

The old database (1 table) has 90 columns in it. Because there are no relationships, it was being used essentially the same way an excel spreadsheet gets used. Its just one big datasheet.

I found some columns that had repeating values in the fields and made separate tables into them to clean up the data for that I can also easily create combo boxes on forms that refer to the list in the related tables.  So all of my relationships in the new database are one-to-many (the one being the related ("list")  tables and the many being the "Main" table.  So I still have one "Main" table which holds many of the columns that the old table had, but I also have 12 FK's in it that relate to the tables I created.  In other words, I still have one fairly large table that also has FK's now.

When I am making my queries, I am confused on what you mean by "just make sure to include the old PK into the new FKs". How am I making my query so that the records don’t lose their related data? Since I still have one main table that just relates to 12 other tables (1:M), do I make an append query for the main table? If so, I get that I am matching the old fields to the new fields, but how am I connecting the FK number in the main table when the value that I am matching it up to is a text value from the original table?

Thank you!

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Ok, lets use an example. Lets say this is a contacts database. You have 2 tables; contacts and actions. Contacts is your list of people, Actions is the engagements you have with those people. So you run an Append query from your old table to Contacts:

INSERT INTO Contacts (ContactID, Firstname, Lastname, etc.)
SELECT ContactID, Firstname, Lastname, etc
FROM oldtable

Now you need to append the actions. so that query would look like this:

INSERT INTO Actions (ContactID, ActionDate, ContactBy, etc.)
SELECT ContactID, ActionDate, ContactBy, etc
FROM oldtable

The other scenario is if you are breaking out the data into lookup tables and your Foreign Keys are in the main table. So in that case, lstill using the Contacts example, you have your contacts table and a category table to indicate the type of contact. So now your Append query would look like this:

INSERT INTO Contacts (ContactID, Firstname, Lastname, CategoryID, etc.)
SELECT Contacts.ContactID, Contacts.Firstname, Contacts.Lastname, Category.CategoryID, etc.
FROM oldtable, Category INNER JOIN on oldtable.Category = Category.Category

You would have to create the Category table first:
INSERT INTO Category (Category) SELECT DISTINCT Category FROM oldtable

This is assuming you are using Autonumber PKs which will be generated during the Append.
Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Because I am not confident in SQL and what your explaining at this point I tried a different approach which sort of worked..

The only solution that I thought of is to change the PK on all the list tables to the actual text since this is essentially a list and there wont be duplicates this would work.  I would then have to change the FK field in the main table from number to text and re-relate the tables.  The biggest problem that I see with doing this is that I would have to enter all the keys in the related "List" tables with all of the possible keys before performing this append query.  I tried to do this already and the append query added only the records that had the keys already in the list table. I was hoping it would add the values that I did not enter yet that are in the old database.

 

If I am going this route it would be easier if I could find a way to find make a query that appends the list of possible values in each table also without adding duplicates. I don’t know if this is possible. I use the QBE instead of SQL because I am not proficient in SQL yet… This is probably also a considerable amount of more work than what your approach is..

 

Thank you for your response.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

First, it doesn't matter whether you use the QBE or enter the SQL directly. I generally use the QBE even though I'm capable of writing SQL statements from scratch. But using queries is the best way to handle this. But the process should be to FIRST populate your lookup tables. This is done by selecting the Text field from your old table. Setting the properties to UNIQUE values. Test by viewing the query results. Then turn it into an Append query and populate your lookup tables.

Once your lookup tables are populated. You can then populate your main table using the second scenario I described.
Hope this helps,
Scott<>
Blog: http://scottgem.wordpress.com
Microsoft Access MVP since 2007

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

I am still confused on this:

When I make my large append query that is moving all the records from the old database to the new database, how am I tying the TEXT field of [OLFACTIVE FAMILY] from the old database to the FK field in the new database which in an AutoNumber datatype? This move does not make sense to me and I don't get how am I keeping this relationship.

Should I make all of the list tables primary key a text value and get rid of the AutoNumber field? Meaning in all these tables I just have a field which is the PK and holds the unique text value that I am listing? This would allow me to tie the [OLFACTIVE FAMILY] text field from the old database to the [OlfFamID_FK] field in the main table of the new database (assuming I change this to a text field as well instead of Long Integer..

Thanks

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Importing the data into a single 'holding' table is the starting point, though in your case, as the source is a single table in another Access database, you can simply link to the source table, and use the linked table in the subsequent 'append' queries.

The insertion of rows into a set of correctly normalized related tables is premised on two main factors:

1.  The data in the source table allows you to identify relevant 'natural' keys.  For example, if you are inserting rows into a referenced Cities table, provided that each city name in the source data is distinct, e.g. you don't have Paris, Texas and Paris, France, or more than one of the many Springfields in the USA, then the City column in the source table can be used as a natural key, enabling you to join other referencing tables you've created to that table.  In the Cities table the City column cannot be its key of course, as city names can legitimately be duplicated.  An autonumber primary key should be used.

2.  The append queries which insert rows into the new tables are executed in a very specific order.  The rule of thumb is that rows are first inserted into a referenced table before any rows can be inserted into a referencing table.  You cannot insert rows into a Cities table until all rows have been inserted into a States table for instance, and if the database is an international one, rows must be inserted into a Countries table before the States table.  Where a table models a many-to-many relationship type data must be inserted into all of the relevant referenced tables first, e.g. all data must be inserted into Orders and Products tables  before rows can be inserted into an OrderDetails table which models the many-to-many relationship type between  Orders and Products.

You might like to take a look at DecomposerDemo.zip in my public databases folder at:

Note that if you are using an earlier version of Access you might find that the colour of some form objects such as buttons shows incorrectly and you will need to  amend the form design accordingly. 

If you have difficulty opening the link copy its text (NB, not the link location) and paste it into your browser's address bar.

This little demo file illustrates the basic methodology outlined above by importing data from an Excel worksheet and decomposing it into a set of normalized related tables.  A brief explanation of each stage is given as the decomposition of the source table proceeds.
________________________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Hi,

I have followed the examples by adding the unique values in my list tables.  One thing that I noticed is that for some reason when I click the datasheet view in my append query to view the append, the total number of records is short.  I have some blank values in the fields in my main table that has foreign keys that I am trying to append and I did the math to figure out that the query is appending only the FK's which hold values but if it is blank, it won't append it to my main table. When I ran the append queries for my list tables it did add a primary key which has a value of blank in the list field so I am unsure of why this is happening. Shouldn't the primary key match up to the foreign key even if the field for the listing of values is blank?

The only fix around this that I could do if there is no solution would be to add a value like "N/A" to the blank fields so that then there would be a key with a value instead of a key with a blank...

Thank you

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

A primary key cannot be NULL.  NULL is the absence of a value, not a value.  The primary key column of a table, or indeed any candidate key, must have a distinct value in each row.  A foreign key can be NULL, but any INNER JOIN on that column will not return a row.  To return all rows from a table regardless of a match in another table a LEFT OUTER JOIN or RIGHT OUTER JOIN as appropriate must be used.

However, in the 'append' queries in my DecomposerDemo this situation would never arise as, if a contact had no employers for instance, rows would be inserted into the Contacts table, but no rows for that contact would be inserted into the ContactEmployers table, which is of course as it should be.  No data loss is incurred.

If you have NULL foreign keys, but are incurring data loss as a result of this it does suggest that there is something amiss either with the model into which data is being decomposed, and/or with the queries being used to do so.
________________________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Yes I am trying to use your demo to help me understand the concept but I must not be grasping something about this process.  I have linked my old table to my new database. So the queries to append unique values to my list tables is easy. They have a primary key and one field that holds the list of different values (each value has its on primary key in other words).  This fills my list tables with only the unique values that will be the old table that I am bringing to the new table.  The area that I run into problems is creating my query that fills the main table (the table that holds all the foreign keys). 

Here is just the beginning of me building this query.  The sheet1 table is the old table where people basically used Access using one table...I am trying to make it better by separating some of the values that get repeating into separate tables. tblApplication is an example of this.  When I turn this query into an append query, I tell it to append to a table named tblFragrance which is basically my new version of sheet1.  The difference, like I said, is that it holds many foreign keys in replacement of just having a "Application" field it now has a field "AppID_FK" which I connected to the AppID in the relationship view as a one to many relationship (there can only be 1 application per fragrance). BTW - I added the autonumber criteria because I am only trying to append the values equal to or greater than this number.

I am using the application to start because I know that none of the records have NULL applications (a blank value in the APPLICATIONS field from the old sheet1 table). When I view this in datasheet view I see that the FK is relating to the correct value. But when I go to run this query, it says it cannot add any of the records due to key violations....

Any help in the right direction would be greatly appreciated. There seems to be little info online that shows how to do this what I would think would be a common action.

Jacob

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

* Please try a lower page number.

* Please enter only numbers.

* Please try a lower page number.

* Please enter only numbers.

 
 

Question Info


Last updated November 21, 2024 Views 825 Applies to: