Results 1 to 5 of 5
  1. #1
    lirantha is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    13

    Using queries to create new tables to normalize database

    I've been trying to teach myself Access, so I'm just barely aware of the conventions; please pardon any newbie errors. if presenting the problem in a different format would be better, please let me know!



    So, I've currently got bibliographical information in one big, not-normalized table (tblPublicationEntries) with 515 records. Here are my fields:

    EntryID (primary key)
    HD (foreign key)
    PubID (currently null; needs to be a second foreign key; see below)
    Corpus
    CorpusVolume
    AuthorLast
    AuthorFirst
    PubYear
    CatalogNumber
    PageNumberStart
    PageNumberEnd
    FigNumber

    The problem with this set up is that, really, Corpus, Corpus Volume, AuthorLast, AuthorFirst, and PubYear taken together should be split off into a separate table. I figured out how to do that part by making a new table with a SELECT DISTINCT query (=tblPublication). I then added a new Autonumber field to be the primary key of that table, leaving me with this:

    PubID (primary key)
    Corpus
    CorpusVolume
    AuthorLast
    AuthorFirst
    PubYear

    This results in 158 records, a number of which include null values for various fields. What I'm trying to do now is get my nice new tblPublication.PubID (primary key) numbers to go into the tblPublicationEntries.PubID (foreign key) field in my original table, so that I can set up a one to many relationship between tblPublication and tblPublicationEntries.

    I tried an UPDATE query, but couldn't figure out how to get the WHERE clauses to work since a relationship doesn't currently exist between tblPublicationEntries and tblPublication. The "Enter Parameter Value" dialog box keeps popping up, and what I was trying to do was avoid having to enter all of the information by hand in the first place. Any suggestions?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    what makes your record unique is the collective of Corpus, Corpus Volume, AuthorLast, AuthorFirst, and PubYear. This has been 'summarised' into a single field PubID

    So create an update query with your tblPublicationEntries and tblPublication linking each on the of these five fields and update the pubID in tblPublicationEntries with the pubID in tblPublication

  3. #3
    lirantha is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    13
    *nods* That's what I was trying to do. But I'm getting something wrong in the SQL syntax. (In addition to not knowing Access, I've never worked with SQL before this week.) This is what I had:

    UPDATE tblPublicationEntries
    SET tblPublicationEntries.PubID = tblPublication.PubID
    WHERE tblPublicationEntries.Corpus=tblPublication.Corpus
    AND tblPublicationEntries.CorpusVolume=tblPublication. CorpusVolume
    AND tblPublicationEntries.AuthorLast=tblPublication.Au thorLast
    AND tblPublicationEntries.AuthorFirst=tblPublication.A uthorFirst
    AND tblPublicationEntries.PubYear=tblPublication.PubYe ar
    ;

    But that's the query that kept asking me to enter parameter values.

    I reworked it just now in the query builder after creating inner joins (is that what you meant by linking each of the five fields?) by dragging the matching fields on top of one another. But running the query alters only 34 records rather than all 515 - perhaps because so many of my records have null values in one or more of the joined fields? How would I make it also update records that include null values in one or more of the linked fields, if that's the case?

    EDIT: Okay, so pardon the n00bness; did some reading and found that replacing the inner join with a left join should be altering all 515. But when I run the following query, it warns me that I'm about to change 515 records, but I still don't get any new values in the tblPublicationEntries.PubID column except in rows without any null values in the joined fields. What am I missing now?

    UPDATE tblPublicationEntries LEFT JOIN tblPublication ON (tblPublicationEntries.CorpusVolume = tblPublication.CorpusVolume) AND (tblPublicationEntries.PubYear = tblPublication.PubYear) AND (tblPublicationEntries.AuthorFirst = tblPublication.AuthorFirst) AND (tblPublicationEntries.AuthorLast = tblPublication.AuthorLast) AND (tblPublicationEntries.Corpus = tblPublication.Corpus) SET tblPublicationEntries.PubID = [tblPublication].[PubID];
    Last edited by lirantha; 04-16-2015 at 10:28 PM. Reason: left join epiphany

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    you'll have to negate the nulls by using the nz function

    WHERE nz(tblPublicationEntries.Corpus,"")=nz(tblPublicat ion.Corpus,"") etc

    LEFT Join is immaterial in this situation, it should be an inner join - all a left join will do if there is not a matching entry is supply nulls

    compare the position of the SET and WHERE elements in your original query manually written with the one generated by the query builder, that was causing your error - otherwise the syntax was fine in principle

  5. #5
    lirantha is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    13
    YES! Thank you so much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 17
    Last Post: 06-13-2014, 10:25 AM
  2. Database Design: Normalize daily scheduled time
    By Lorlai in forum Database Design
    Replies: 1
    Last Post: 03-12-2013, 12:26 PM
  3. Replies: 1
    Last Post: 11-20-2012, 01:29 PM
  4. Normalize a flat database
    By worldwidewall in forum Access
    Replies: 5
    Last Post: 03-23-2012, 04:06 AM
  5. Queries with multiple tables to create report
    By Solstice in forum Queries
    Replies: 1
    Last Post: 09-22-2011, 02:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums