Presentation on theme: "Designing MS-Access Tables"— Presentation transcript:
1 Designing MS-Access Tables Relational Database ConceptsPaul A. Harris, Ph.D.General Clinical Research Center
2 IntroductionDatabase design (data modeling) is crucial for long-term management of informationFor many users, the first experience using MS-Access (or any RDBS) is confusingA major cause of confusion is the design and use of tables
4 OverviewMS-Access is a relational database engine and a set of integrated development toolsTables = DataQueries = combine tables + ask questionsForms/reports UIMacros/Code add functionalityTablesCodeQueryReportFormsMacro
5 Relational Database Concepts - Keys Keys are pieces of data that help to identify a row of information in a tablePrimary key uniquely identifies an entire row of data – 1) must have a value (cannot be null); 2) can never change(?); and 3) must have a unique value for each record in table. - Look for a logical field meeting criteria - If no logical field exists, invent one (auto-number)Foreign keys are fields in one table that relate back to another table’s primary keys - Make sure foreign key “type” is same as related PK.
6 Relational Database Concepts - Relationships In a RDBS, tables are related through relationships. Relationships may be one-to-one, one-to-many, many-to-many. One-to-many should be the most common.One-to-One: One item in Table A applies to one item in Table B (demographics table – dna table)One-to-Many: One item in Table A applies to many items in Table B (gender table – demographics table)Many-to-Many: Many records in table A relates to many records in Table B (avoid these)Strive for one-to-many relationships – PK/FK
7 Relational Database Concepts - Normalization Series of rules developed by E.F. Codd (IBM) in 1970s – integral to relational database modelFirst Normal Form: each column must contain only one value (atomic, discrete data storage)Second Normal Form: 1N + any column in a table that is not a key has to relate only to the primary keyThird Normal Form: 2N + every non-key column is independent of every other non-key column
8 Relational Database Concepts - Normalization – First Normal Form Each column (field) must contain only one value:Identify any field that contains multiple pieces of information (ex address)Break up problem fields into separate fields (address1, city, state, zip)
9 Relational Database Concepts - Normalization – Second Normal Form 1N + any non-key column independent of every other non-keyIdentify any fields that do not relate directly to the primary key.Create new tables accordinglyAssign or create new primary keysCreate requisite foreign keys indicating relationships
10 Relational Database Concepts - Normalization – Third Normal Form 2N + any non-key column independent of every other non-keyWithin a table, test to see whether any non-key field determines the value of another non-key field
11 Relational Database Concepts - Table Design and Normalization Strategy Eliminate redundancyThink about units – this will help with 1NF atomicityStrive for one field primary key – use autonumbers if neededThink first about the most important data table (most important measurements), then work out from there to normalizeThink about questions you’ll be asking from your data – then think about how your table structure may be combined to answerAvoid many to many relationships – one to many relationships are cleaner and avoid problems in long runDon’t be afraid to break a normalization rule if it is silly for your applicationWork out on paper first, then mock-up with MS-Access and test answering business questions with query-builds linking tables
12 Fields – Common TypesText - Text or combinations of text and numbers, as well as numbers that don't require calculations, such as phone numbers. – Up to 255 charactersMemo - Lengthy text or combinations of text and numbers - Up to 65,535 characters.Number - Numeric data used in mathematical calculations.Date/Time - Date and time values for the years 100 through 9999AutoNumber - A unique sequential (incremented by 1) number or random number assigned by Microsoft Access whenever a new record is added to a table. AutoNumber fields can't be updated.Yes/No - Yes and No values and fields that contain only one of two values (Yes/No, True/False, or On/Off).OLE Object - An object (such as a Microsoft Excel spreadsheet, a Microsoft Word document, graphics, sounds, or other binary data) linked to or embedded in a Microsoft Access table.Demo?
13 Referential Integrity Referential integrity is a system of rules that Microsoft Access uses to ensure that relationships between records in related tables are valid, and that you don't accidentally delete or change related data. (from MS-Help)Ensures data validity between tables is upheldCascade UpdateCascade Delete
14 Summary – Paul’s LawsThink about the entire project and design tables (1st Cut) before touching keyboardFormulate data questions to determine best table scheme (How many people took drug A and gender = F and …). Leave wiggle room.Spend time normalizing, but don’t turn a 2-day project into a 2-month project. You’re not E-Bay – you can get by with less than perfect performance as long as you can answer your questions and the application is flexible for growth.Think about central table and questions first - then work outwards to define adjunct tables.Design enough tables to make things work, but don’t go overboard. I usually try to get by with as few as possible while remaining true to the spirit of normalization.Strive to store data once – don’t store calculations.
15 Where to Get More Information Most database books have one chapter on table design and normalization -- I like the Visual QuickPro Guide series of technical help booksGoogle search for ‘database normalization tutorial’