Docsity

Introduction to Database, Summaries of Introduction to Database Management Systems

Toggle sidebar
bg1
Añade encabezados (Formato > Estilos de párrafo) y aparecerán en el índice.
1/14/26
Database: a system that holds data
● Why?
● To keep track of information
○ Hotel – guest information
○ Financial records – Account #’s, routing #’s, balances
○ Ads – Targeted Advertising
○ Sales forecast
■ Number of sales
■ Inventory
■ Input cost
■ Profit margin
■ Account
● Databases are really efficient and relatively safe
● A database is software
● Database software
○ Create a database file
○ DBMS (database management system)
■ Allows us to do the administrative aspects
■ Access database
● Client software
○ Specifically to access the database
○ Microsoft email
● PostGreSQL – Database software
● pgAdmin – DBMS/Client
● Port numbers identify what application is going to be used
1/21/26
Database Overview – Guided Notes
● What is a database?
○ Database: a software system that stores, retrieves, and updates data to keep
track of valuable organizational information.
● What is data?
○ Data = facts and figures (Ex: Oscar or 9.99)
○ Information = knowledge derived from data
○ Ex: Brad | office | phone | 478 | 445 8521
● Database vs File System
○ Data redundancy
○ Data isolation
○ Data concurrency
● Database vs Spreadsheet
○ Data redundancy is why databases shine over spreadsheets
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Introduction to Database and more Summaries Introduction to Database Management Systems in PDF only on Docsity!

Añade encabezados (Formato > Estilos de párrafo) y aparecerán en el índice. 1/14/ Database : a system that holds data ● Why? ● To keep track of information ○ Hotel – guest information ○ Financial records – Account #’s, routing #’s, balances ○ Ads – Targeted Advertising ○ Sales forecast ■ Number of sales ■ Inventory ■ Input cost ■ Profit margin ■ Account ● Databases are really efficient and relatively safe ● A database is software ● Database software ○ Create a database file ○ DBMS (database management system) ■ Allows us to do the administrative aspects ■ Access database ● Client software ○ Specifically to access the database ○ Microsoft email ● PostGreSQL – Database software ● pgAdmin – DBMS/Client ● Port numbers identify what application is going to be used

1/21/ Database Overview – Guided Notes ● What is a database? ○ Database : a software system that stores, retrieves, and updates data to keep track of valuable organizational information. ● What is data? ○ Data = facts and figures (Ex: Oscar or 9.99) ○ Information = knowledge derived from data ○ Ex: Brad | office | phone | 478 | 445 8521 ● Database vs File System ○ Data redundancy ○ Data isolation ○ Data concurrency ● Database vs Spreadsheet ○ Data redundancy is why databases shine over spreadsheets

○ Deletion anomaly ■ Things get deleted that should be in the records ● Relational database : ○ Tables → Correspond to a tangible or intangible entity (owner, pet, appointment, vet, specialty, medicine) ■ Relationships → some connection between tables (pet and owner) ■ Attributes (column) → define the entity – aspects of the entity (breed, weight) ■ Records (row) → instance of an entity ■ Keys : ● Primary Key – attribute value that uniquely identifies each record ○ Surrogate Keys – sequenced value that has no meaning outside the database ● Foreign Key – attribute value that references a record from another table using that record’s primary key value ○ Ex: DepartmentID (Primary Key) from Department table in Employee table ● Database Software ● Database Architecture ● Database Interfaces

1/28/

--Create Venue Table CREATE TABLE Venue ( VenueID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, VenueName VARCHAR(150) NOT NULL, Address VARCHAR(50) NOT NULL, City VARCHAR(100) NOT NULL, State VARCHAR(2) NOT NULL, Zipcode VARCHAR(5), Capacity INTEGER, VenueType VARCHAR(20), ContactName VARCHAR(50), ContactNumber VARCHAR(20) );

● Always put foreign key declaration at the end of statement ● FOREIGN KEY (AlbumID) REFERENCES Album(AlbumID) ON DELETE SET NULL Data Types : ● Number (numbers) ○ INTEGER – only whole numbers ○ DECIMAL – non-whole numbers

Result set → The table output from a query

We have to find the common attribute and will always be primary key from one table and foreign key from the other SELECT EventName, EventDate, VenueName, State, VenueType FROM Event JOIN Venue ON Event.VenueID = Venue.VenueID WHERE State = 'CA';

Table.Attribute → Ex: Event.VenueID

WHERE → Comparison Operators ● = → equal to ● <> → not equal to ● > → greater than ● >= → greater than or equal to ● < → less than ● <= → less than or equal to ● ><

WHERE Clause AND Operator ● Makes query conditions more specific OR Operator ● Makes query conditions more broad

SELECT * FROM Event JOIN Venue ON Event.VenueID = Venue.VenueID WHERE State = 'CA' AND ExpectedAttendance > 600;

SELECT * FROM Event JOIN Venue ON Event.VenueID = Venue.VenueID ← Made query more broad WHERE State = 'CA' OR ExpectedAttendance > 600;

SELECT *

FROM Customer JOIN Sale ON Customer.CustomerID = Sale.CustomerID

SELCET * FROM Sale JOIN Sale_Detail ON Sale.SaleID = Sale_Detail.SaleID

SELECT * FROM Sale_Detail JOIN Product ON Sale_Detail.ProductID = Product.ProductID

SELECT * FROM Product JOIN Supplier ON Product.SupplierID = Supplier.SupplierID

Table Prefix Aliases (All optional) You can shorten a table prefix to an abbreviation

SELCET * FROM Sale S JOIN Sale_Detail SD ON S.SaleID = SD.SaleID

Once we change the name to abbreviation we have to use that abbreviation from here on out

Multiple Table Joins SELECT * FROM Customer JOIN Sale ON Customer.CustomerID = Sale.CustomerID JOIN Sale_Detail ON Sale.SaleID = Sale_Detail.SaleID JOIN Product ON Sale_Detail.ProductID = Product.ProductID JOIN Supplier ON Product.SupplierID = Supplier.SupplierID ;

Find all products that are red and less than $ SELECT * FROM Product WHERE Color = 'Red' AND UnitPrice < 40 ;

List all customers who live in zip code 62701 or 62702

SELECT

FROM

JOIN

WHERE

ORDER BY → Sort the data for a given attribute alphabetically or numerically

SELECT LastName, FirstName, City, State FROM Customer WHERE State = 'GA' ORDER BY LastName, FirstName

List all small-sized tops SELECT * FROM Product WHERE Category = 'Tops' AND Size = 'S'

Need to see all credit card sales from January 15-31 2024 SELECT PaymentMethod, SaleDate FROM Sale WHERE SaleDate BETWEEN '2024-01-15' AND '2024-01-31' AND PaymentMethod = 'Credit Card'

2/23/ Data Modeling ● Data Modeling → high level description of a database ○ Will the database work? ○ Can you ensure integrity? ■ Enforce integrity ○ Find problems with structure ● Conceptual Data Models ○ Identify Entities ○ Identify Relationships ○ Declare Keys (Primary + Foreign) ○ Associate business rules ■ Customer → Sale ○ Constraints ○ Valid data ● Model Types ○ Database Conceptual Model ○ Entity Relationship Diagram (ERD) Objects

■ Business Specific

○ Unified language Model ■ Universal ● Computer ● Entity → A thing that we want to track (Person, Place, Thing) – Tangible/Intangible ○ Strong Entities → Existing on their own – Don't need any other entity to exist in the database ■ Ex: Building ○ Weak Entities → Depend on another entity (table) to exist ■ Ex: Rooms ○ Attributes → Property or characteristic of an entity ■ Simple → Atomic → A given record would only have one value for a given attribute ● Ex : First name, email, etc. ■ Composite → Multiple values (act as a single value) ● Ex : First name – John Luke ■ X Multi-Valued → More than one value expected for an attribute in a given record !!! ● Ex : Size and Color ● DON'T WANT MULTI-VALUED ATTRIBUTES ○ Records → Instance of an entity ● Primary Keys → Unique identifier for a record ○ Surrogate Keys ○ Candidate keys → Potential primary ■ Data storage was scarce and expensive ○ Composite Keys → Combine two or more attribute values together to make a primary key ■ Ex: SaleDetail ● SaleID 10850 ● ProductID ● Integrity Constraints ○ Domain Integrity ○ Entity Integrity ○ Referential Integrity ● Cardinality

February 25th (rodrigo´s notes in case you need them) Unique identifier: field that makes each record different from all others. → Candidate key ● Composite key ● External Identifiers: ○ Phone

○ Do not work in Relational Database ■ Sale – Product Examples: M:M – Bridge Table is solution to avoid M:M

Bridge Table Sale SaleDetail Product SaleID SaleDetailID ProductID FK SaleID FK ProductID

Student CourseDetail Course StudentID CourseDetailID CourseID FK StudentID FK CourseID Grade Crow's Foot

Minimum Cardinality → 1 or 0

Patient -||----|<-- Appointment

Product —>|—|-- Supplier

Employee —>|—||—Manager ← Maximum Cardinality outside – Minimum inside

The basic cardinality (1 or many) tells you the maximum, The 0 or 1 tells you the minimum You ALWAYS need both for a complete ERD.

Ask TWO questions for each side:

  1. Minimum: “Can it be zero?” → yes = 0, no = 1
  2. Maximum: “Can it be many?” → yes = *, no = 1

Database Anomalies ● Insertion Anomaly → Data cannot be added to the database without other data included ● Update Anomaly ● Deletion Anomaly

March 4th (Rod´s notes)

Study Guide

  1. Entity Integrity makes sure that every record in a table is unique and identifiable. It makes sure that every table has a primary key that cannot be NULL.

  2. Referential Integrity makes sure that relationships between tables remain consistent. It makes sure that foreign keys match primary keys from another table.

  3. Business Rules are specific rules that determine how data can be used in a database based on the needs of an organization.

  4. Insertion Anomaly is when data cannot be added to the database without other unrelated data being included.

  5. Update Anomaly occurs when the same piece of data is stored in many places within a table. Updating it in one place but not the others can create inconsistent data.

  6. Deletion Anomaly occurs when a record gets deleted and other data is also unintentionally lost.

  7. Functional Dependency is when the attribute value of one attribute determines the attribute value of another attribute.

  8. First Normal Form - all attributes must be simple attributes (no multi-value attributes).

  9. Second Normal Form - No attribute can be functionally dependent on only one part of a composite key.

  10. Third Normal Form is when there are no transitive dependencies. Transitive Dependency is an attribute in a table that is functionally determined by a non-primary key attribute.

SELECT ArtistName, AlbumTitle, ReleaseYear FROM Album JOIN Artist ON Artist.ArtistID = Album.ArtistID WHERE Format = 'CD';

SELECT ArtistName, AlbumTitle, TrackTitle FROM Track JOIN Album on Album.AlbumID = Track.AlbumID JOIN Artist ON Artist.ArtistID = Album.ArtistID WHERE ReleaseYear = 1965 AND Country = 'US';

In Class Example : Patient (PatientID, PatientName, DOB, BloodType)

Doctor (DoctorID, DoctorName, Specialization)

Room (RoomID, RoomNumber, RoomType, DailyRate)

Admission (AdmissionID, PatientID, DoctorID, RoomID, AdmissionDate, DischargeDate, Diagnosis) FK: PatientID references Patient FK: DoctorID references Doctor FK: RoomID references Room

Medication (MedicationID, MedicationName)

Prescription (PrescriptionID, AdmissionID, MedicationID, Dosage, Frequency) FK: AdmissionID references Admission FK: MedicationID references Medication