Download presentation
Presentation is loading. Please wait.
Published byDana Patterson Modified over 9 years ago
1
Computer Science & Engineering 2111 Introduction to Database Management Systems Relationships and Database Creation 1 CSE 2111 Introduction to Database Management Systems
2
Steps when setting up a Database 1.Decide what information you will store in the database 2.Create the layout of the database CSE 2111 Introduction to Database Management Systems 2
3
3. Create a relationship diagram to identify the table relationships, primary keys and foreign keys We know the information we want to store, but how do we match a customer’s name to their charges and payments? We need a way to relate these two tables to extract useful information. We can relate these two tables by matching the Client ID Foreign key A field that defines the relationship between 2 tables Relationship Rules Must be a primary key (unique) in at least one of the tables The field names on each table do not have to match as long as the information is the same. The related fields must be the same data type – number, text etc. CSE 2111 Introduction to Database Management Systems 3
4
Table Name: Client Primary Key: ClientID Table Name: Charges Primary Key: None Foreign Key: ClientID On Charges table Foreign Key: ClientID On Payments table Table Name: MethodTypes Primary Key: MethodID Foreign Key: PaymentType On Payments table RELATIONSHIP DIAGRAM FOR RESEARCH PAPERS DATABASE 1 1 1 ∞ ∞ ∞ CSE 2111 Introduction to Database Management Systems 4 Table Name: Payments Primary Key: None
5
4. Create the database using the database software Create tables – Fields – Primary keys – Field Types – Field Properties Create Relationships – “ Join” tables – Enforce Referential Data Integrity A set of rules that specifies what records may exist in each table – A record input with a foreign key must always have a matching record in the primary key table in the relationship Cascade Delete Related Records – Removing any entry in a primary key field will automatically remove all entries in foreign key fields of related tables. Cascade Update Related Records – Updating any entry in a primary key field will automatically update all entries in foreign key fields of related tables. Input the information CSE 2111 Introduction to Database Management Systems 5
6
Once Relationships are established you can gather information from one or more tables to answer questions Create a list of account numbers and owner names and total transactions What are the total deposits made by accounts starting with 5? What is the total balance of all accounts held by Jane Doe ? These requests are known as Queries CSE 2111 Introduction to Database Management Systems 6
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.