Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Fundamentals

Similar presentations


Presentation on theme: "Database Fundamentals"— Presentation transcript:

1 Database Fundamentals
ITE 370 11/19/2018

2 Databases A database is a collection of related data which is organized to meet user needs We assume a relational database model Relational database design objectives: Eliminate redundant data Be able to locate individual records quickly Make enhancements to the database easy to implement Keep the database easy to maintain Theme for this class – Database Programming VISUAL EVENT-DRIVEN OBJECT-ORIENTED CONNECT TO DATABASE We will learn techniques to connect through a visual, OO, event-driven program 11/19/2018

3 Entities An entity is a class of objects, such as people, products, or services, about which we collect data. For example, Students at the university. Employees at a business. Sales transactions in a retail business. Inventory of parts in a warehouse. 11/19/2018

4 Relations and Tables A relation is a set of columns and rows collected in a table-like structure that represents a single entity made up of related data A table is a physical implementation of a relation in a DBMS A relation does not have to be a physical entity – It can be the results from a query. Relations can be NON-normalized 11/19/2018

5 Attributes and Columns
An attribute is a characteristic of an entity Examples of attributes Names, addresses, phone numbers of people. Titles, salaries, job descriptions of employees. Time, date, customer id, sales person id in a sales transaction. Part number, Cost, In-stock-quantity of inventory of parts. A column, or field, is a physical implementation of an attribute 11/19/2018

6 Tuples and Rows A tuple is set of data whose values make up an instance of each attribute defined for that relation A tuple is implemented physically as a row in a table, or a record 11/19/2018

7 Summary of basic terms In relational model, or the logical model
Relations consist of a set of tuples that define a set of specific attributes for one instance of the entity In the physical implementation of a database Relations are implemented as tables Attributes are columns or fields Tuples are rows or records 11/19/2018

8 Keys Keys are the attributes that are used to uniquely identify each instance of an entity, i.e. each row in a table The uniqueness can naturally occur like Social Security numbers or can be created by the database management system. Student Id Employee number Part number Social Security Number The trend is towards making primary keys unique for the entire database, not just within a specific table 11/19/2018

9 Relationships Relationships are established between entities. They provide the link between tables. These relationships are usually connected by keys (sometimes called secondary keys). In both entities, the keys contain the unique data that relates the two tables together. Usually, the (primary) key field in one table is linked to a foreign key in another table. 11/19/2018

10 Relationships Relationships may be one-to-one one-to-many
many-to-many (requires intersection table in physical implementation) 11/19/2018

11 Database Review Question
Athletes at the Olympics play for themselves, but they also compete for their country. An athlete belongs to a country – this is their nationality. A country can have more than one athlete representing it, of course, but an athlete can only compete for one country at the Olympics. If the athlete entity is implemented as a database table, and the country entity is implemented as another, then which table(s) contain(s) the foreign key to represent the relationship between the athletes and countries? Athlete - Both Athlete and Country Country - Either Athlete or Country Cardinality defines the numeric relationships between occurrences of the entities on either end of the relationship line. 11/19/2018

12 Bus Schedule Database from an ITE Project Course
Stop – Physical Location of where the bus stops (stops can be on multiple routes or even multiple times on the same route) StopOnRoute – Bridge Entity between Stop and Route due to M:N relationship Route – Sequence of Stops to Pick Up and Drop Off Passengers for a single Bus and Driver (Foreign Keys are in the Main Table) RouteStart – Allows routes to run multiple times during the day (created through normalization to avoid redundant data in Route table) 11/19/2018

13 Normalization Rules of normalization are established to organize a relational database so that Data integrity is preserved Data redundancy is minimized Practical limitations sometimes require that data in a database be non-normalized 11/19/2018

14 Relation (not a physical table) result from a Query
Non-normalized Redundant Data Can lose data integrity 11/19/2018

15 Brief Introduction to SQL
SQL stands for Structured Query Language, a widely-supported database language that has established standards SQL is a 4GL? Specifies the “what” rather than the “how” In SQL, we will write queries. A query is a formalized instruction to a database to either return a set of records or perform a specific action on a set of records as specified in the query 11/19/2018

16 Types of SQL statements
There are 3 types of SQL statements Data Definition Language (DDL) Data Control Language (DCL) Data Manipulation Language (DML) We will almost exclusively focus on the DML—statements used to view, add, modify, or delete data stored in a relational database We will deal with DML – Data Manipulation Language – Add, Update, Delete (Manipulate) 11/19/2018

17 How are SQL statements executed?
Four ways. We will focus on two: Direct invocation From SQL-Server Query Analyzer From MS-Access in Query Design Call Level Interface (CLI) Applications invoke SQL statements at run-time SQL statements not precompiled Executed directly by RDMBS Where do we put the SQL Statements? In Database In Other Application 11/19/2018

18 Direct Invocation via SQL-Server Query Analyzer
11/19/2018

19 A CLI-style call in Visual Basic
In VB: strSQL = “Select LName, FName From Emp Where Title = ‘Clerk’;” adoEmp.RecordSource = strSQL adoEmp.CommandType = adCmdText adoEmp.Refresh Or, another example adoEmp.Open “SELECT * From Emp “ _ & “Where Title = ‘” & cboTitle.Text & “’” SQL can be assigned as a property of an object Embedded SQL in Visual Basic (or other languages) We do not want users to work directly with the database We need Security We Need “EASY” for User (GUI) Some queries we will write in code, in other cases we will write them in stored procedures that we can call from our application 11/19/2018


Download ppt "Database Fundamentals"

Similar presentations


Ads by Google