We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byErick Cubit
Modified over 4 years ago
Designing a Database An Introduction for beginning VB Developers Copyright ©2003, Tore Bostrup
6/23/2003Copyright ©2003, Tore Bostrup2 What is a Database There are different types of databases –Relational Databases –Object Databases –Hierarchical Databases –Network Databases –Etc. But usually, we talk about Relational Databases
6/23/2003Copyright ©2003, Tore Bostrup3 What is a Relational Database A Relational Database is briefly described as a collection of Tables Each Table is made up of Rows of data that is organized in Columns –Think of an Excel Spreadsheet where the first row contains the column names, only the columns that are named are used, and each column only contains one type of data.
6/23/2003Copyright ©2003, Tore Bostrup4 What makes it Relational Relational comes from the way that different tables relate to each other. –A column that exists in two tables can be used to relate the two tables by storing the same value in both tables:
6/23/2003Copyright ©2003, Tore Bostrup5 Relationship between two Tables OrderIDCustID(Info) 3001101… 3002126… CustIDCust Name Cust Addr 1B&H… 101PPCC… 126ACME Comp …
6/23/2003Copyright ©2003, Tore Bostrup6 Relationship Types One-to-One –This is not very common, and mostly used for optimization. Usually, only one table is needed. One-to-Many –This is the most common relationship. For instance a Customer may have MANY Orders, but each Order is only for ONE Customer. Many-to-Many –Also relatively common. For example, an Order may contain MANY Products, and a Product may be part of MANY Orders.
6/23/2003Copyright ©2003, Tore Bostrup7 Some Other Concepts Primary Key –A Primary Key is one or more columns that together are sufficient to identify a single row in a table. –It is Unique within the table –It always has a value
6/23/2003Copyright ©2003, Tore Bostrup8 Some Other Concepts Foreign Key –A Foreign Key is a column in a table that contains a copy of a value from another table in order to establish a relationship to that table. –The Foreign Key usually refers to the Primary Key in the other table (to make sure it only points to one row).
6/23/2003Copyright ©2003, Tore Bostrup9 Designing the Database We often design the database using Diagrams called Entity-Relationship or ER Diagrams. Tables are shown as boxes, and Relationships are shown as lines. Orders Customers Products Customers place Orders Orders contain Products
6/23/2003Copyright ©2003, Tore Bostrup10 What Tables Do I Need? Step 1: –What kinds of Things are you keeping information about? For starters, each kind of thing tends to be a Table: –In an order system, wed probably at least keep information about Orders and Customers. –We may also want a catalog of Products that can be ordered
6/23/2003Copyright ©2003, Tore Bostrup11 What Tables Do I Need Step 2: –Determine the data items that you need for each kind of thing, watch out for information that can be repeated Multi-valued columns should be avoided Repeated columns should be avoided No horizontal repetitions should be included Vertical repetitions (multiple rows with same value in a column) should only represent a relationship to another table.
6/23/2003Copyright ©2003, Tore Bostrup12 Repeated Values A value is considered repeated only if it represents the same measurement. The fact that two people are the same height does not mean that the data is repeated in this sense. A repeated value that is part of the Primary Key is allowed if the Primary Key consists of multiple columns.
6/23/2003Copyright ©2003, Tore Bostrup13 Repeated Values Examples of repeated values: OrderNoLine1ItemLine1QtyLine1PriceLine2ItemLine2QtyLine2Price 245PN7681$35PN6563$15 OrderNoItemNoCustomerItemQtyPrice 2451SteelCoPN7681$35 2452SteelCoPN6563$15 2461Acme CorpPN3711$2.99 2462Acme CorpPN0157$5
6/23/2003Copyright ©2003, Tore Bostrup14 What Tables Do I Need Step 3: –Once you have completed defining your kinds of things and fixed any repeating data for those things, draw your relationships. Step 4: –Resolve Many-to-Many relationships (we will get back to this).
6/23/2003Copyright ©2003, Tore Bostrup15 The Relationships Draw the tables Draw the Relationships Define the Relationship Types CustomersOrders CustomersOrdersProducts CustomersOrdersProducts 1NNM
6/23/2003Copyright ©2003, Tore Bostrup16 The Many-to-Many Relationship Consider the Products table – the products that can be ordered. Assume it is simply a catalog with a list of the products available. –Each Order may contain MANY Products, and each Product can be a part of MANY Orders. –But how do we represent this?
6/23/2003Copyright ©2003, Tore Bostrup17 Representing Many-to-Many Remember, a Relationship is defined by keeping a copy of the value of a column from the other table, usually that other tables Primary Key. –So each row in a table can only reference a single row in the related table –And we arent supposed to repeat the data so we shouldnt have multiple rows for the same item.
6/23/2003Copyright ©2003, Tore Bostrup18 OOPS – We Need Another Table The solution is really pretty simple (as long as you know what to do): –Introduce an intermediate table between Orders and Products. –Relate it as Many-to-One to EACH of the two tables (Orders & Products) –This table only needs the Primary Key from the two tables, and their combinations become the representation of a Many-to-Many relationship between Orders and Products
6/23/2003Copyright ©2003, Tore Bostrup19 The Magic Intermediary Table And voila – we have a Many-to-Many relationship between the Orders and the Products table. –It is common to name the table with the name of both of the tables it connects. But in an order system, you will typically see this table named OrderDetail. And it will typically contain additional data such as UnitPrice and Quantity. Orders OrderID CustomerID Other… Products ProductID ProductName Other… ProductOrders OrderID ProductID 1 MN1
6/23/2003Copyright ©2003, Tore Bostrup20 Microsoft Access MS Access actually has many different personalities: –A Database Manager –A Database Design Tool –An Application Development Tool (like VB6) –An ad hoc Query Designer –A Report Designer –…
6/23/2003Copyright ©2003, Tore Bostrup21 Our Main Interests As VB6 Developers, our main interests in MS Access are –As a Database Design Tool –As a Database Manager for small database applications – typically for a departmental, workgroup or single user application.
6/23/2003Copyright ©2003, Tore Bostrup22 Getting Started with Access The Database Wizard lets you create a starter database AND application (developed in the MS Access Application Development Environment) without any prior knowledge. This can be good – it gives you a head start on your design if one of the databases are appropriate for your needs.
6/23/2003Copyright ©2003, Tore Bostrup23 Getting Started The Wizards also can keep you from learning how to design your own database, and you may decide to use the Access Development Environment. –The development environment is easy to use for simple and standard things, but it gets difficult to make it do things the way you want it to (you cant quite get control over it). –PS: That is MY opinion…
6/23/2003Copyright ©2003, Tore Bostrup24 MS Access Database Wizards Access contains several database Wizards: Asset Tracking Contact Management Event Management Expenses Inventory Control Ledger Order Entry Resource Scheduling Service Call Management Time and Billing
6/23/2003Copyright ©2003, Tore Bostrup25 To use the Database Wizard Open MS Access –Specify Access database wizards, pages, and projects and Click OK –Select the Databases tab –Select the database type you want and click OK –Give it a file name and click Create –Click on Next –Additional screens let you select which tables and what data elements you want in the database.
6/23/2003Copyright ©2003, Tore Bostrup26 The MS Access Order Entry DB
6/23/2003Copyright ©2003, Tore Bostrup27 Creating a Table in MS Access Open an existing database, or create a blank Database. You have three choices –Create table in Design view –Create table by using wizard –Create table by entering data
6/23/2003Copyright ©2003, Tore Bostrup28 Create table by entering data This allows you to simply start entering data as if you were typing into an Excel spreadsheet. However: –No column names are defined (they will be called Field1, Field2, etc.) –Access makes a guess as to their data type based on the data entered.
6/23/2003Copyright ©2003, Tore Bostrup29 Create table by using wizard Starting in the middle, this is similar to the Database Wizard, but it only applies to a single table – and doesnt create any application code. –Think of it as creating a new table from predefined table templates.
6/23/2003Copyright ©2003, Tore Bostrup30 Create table in Design view The Table Designer lets you define the column names, their data types, and other information about the columns.
6/23/2003Copyright ©2003, Tore Bostrup31 If You Only have VB6 Ever since VB3 or 4, VB has included a sample application called VISBAS. –In VB6, this application is on the MSDN Library CD, in the Samples\VB98\visbas folder. –An executable VISBAS.EXE is installed in the same folder as VB6, and available under the VB6 menu Add-Ins > Visual Data Manager –The executable is fine for Access 97 databases, but not for Access 2000 databases.
6/23/2003Copyright ©2003, Tore Bostrup32 Making VISBAS Work If you need to work with Access 2000 (or newer) databases, you need to recompile it with reference to Microsoft DAO 3.6 Object Library –Copy the visbas folder to you HD –Remove the Read Only setting from the visbas folder and the files in it. –Open visbas.vbp
6/23/2003Copyright ©2003, Tore Bostrup33 VISBAS for Access 2000 Contd… –Select menu Project > References… –Unselect Microsoft DAO 3.5 Object Library –Select Microsoft DAO 3.6 Object Library –Move the new reference up above the Microsoft ActiveX Data Objects 2.5 Library (and possibly above the Microsoft Visual Basic 6.0 Extensibility) –OK, Save Project, and Make Visdata.EXE…
6/23/2003Copyright ©2003, Tore Bostrup34 Using VISBAS Either run VISBAS.EXE or in the VB IDE, select Add-Ins > Visual Data Manager… –Create a New Database: Select File > New… > Microsoft Access > Version 7.0 MDB… and give the new database a name. –Open an Existing Database: File > Open Database… > Microsoft Access… –In either case, you will get two windows – a Database Window and a SQL Statement window.
6/23/2003Copyright ©2003, Tore Bostrup35 Create a Table using VISBAS Right-Click in the Database Window Select New Table –Type in the table name in the dialog box –Click the Add Field button Type in the (Column) Name Select the (data) type and size (length) of the column, and select other settings as appropriate The OrdinalPosition, ValidationText, ValidationRule, and DefaultValue are optional
6/23/2003Copyright ©2003, Tore Bostrup36 Create a Table using VISBAS Click OK for each field that you add Click Close when you dont want to add any more fields (columns) to the table You can also add Indexes. It is always good to have at least a Primary Key defined. When you are done, click Build the Table.
BASIC SKILLS AND TOOLS USING ACCESS
Microsoft® Access® 2010 Training
Microsoft ® Office Access ® 2007 Training Build a database II: Create tables for a new Access database GPC presents:
Intro to Access 2007 Lindsey Brewer CSSCR September 18, 2009.
Introduction to Microsoft Access
AS ICT Building a complex multi-table form. Introduction In addition to the single table form and sub-form design wizard available in earlier versions,
MS Access 2003 Tutorial By: Juan GUANTENG!!! Y7. Step 1 Launch the Microsoft Access 2003 program. This can be done by clicking an icon on the desktop.
Microsoft Access A Hands-On Introduction Chapter 4.
BA271 Week 6 Lecture Database Overview Dave Sullivan.
Automating Tasks With Macros
Microsoft Access 2003 Introduction To Microsoft Access 2003.
Access Tutorial 1 Creating a Database
Office 2003 Introductory Concepts and Techniques M i c r o s o f t Access Project 1 Creating and Using a Database.
Microsoft Access 2007 Microsoft Access 2007 Introduction to Database Programs.
Tables. Any database must contain one or more tables, because that’s where the data is stored. For any table there are two views provided: Datasheet view.
Access Tutorial 10 Automating Tasks with Macros
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
Tutorial 1 Creating a Database. Objectives Learn basic database concepts and terms Learn basic database concepts and terms Explore the Microsoft Access.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
© 2018 SlidePlayer.com Inc. All rights reserved.