Download Today`s Agenda What is a Database? Relational Database

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Serializability wikipedia , lookup

SQL wikipedia , lookup

Microsoft Access wikipedia , lookup

IMDb wikipedia , lookup

Oracle Database wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Ingres (database) wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Functional Database Model wikipedia , lookup

Database wikipedia , lookup

Relational model wikipedia , lookup

Clusterpoint wikipedia , lookup

ContactPoint wikipedia , lookup

Database model wikipedia , lookup

Transcript
Today’s Agenda

Topics





Reading:

COMPSCI 280 S2 2016
Enterprise Software Development


Introduction
What is a Database?
Data Concepts and Characteristics
Data Integrity and Security
Database Models
How to use LinqPad
How to use HeidiSQL
Understanding Computers

Chapter 14 Databases and Database Management Systems
2
What is a Database?


A collection of related data stored in a manner so it can be
retrieved as needed

Data from several tables is tied together (related) using a field
that the tables have in common
A Simple Relational Database Example
Used to create, maintain, and access databases
A database typically consists of:

Tables

Fields (columns)



Collection of related records
Single category of data to be stored in a database (name, telephone
number, etc.)
Records (rows)

3

Database Management System (DBMS)


Relational Database
Database

01
Collection of related fields in a database (all the fields for one customer, for
example)
01
4
01
Primary Key


DBMS
Specific field that uniquely identifies the records in a table
Used in a relational database to relate tables together
–
PC DBMSs
–
More comprehensive enterprise databases
•
•

5
01
Microsoft Access, Corel Paradox
Oracle Database, IBM DB2, Microsoft SQL Server
Perhaps the best known RDBMS are those that use SQL, the
Structured Query Language, to manage their data
6
01
Database servers vs. clients


Individuals Involved
What if more than one application needs access to the same
data? Then we cannot make the DBMS part of the application
itself.
What if the applications are on different computers?


Individuals Involved with a Database Management System

Database Designers

Database Developers

Database Programmers


Answer: the database needs to be on a server, and the applications
that need to access the database act as clients.

8
Write the programs needed to access the database or tie the database to other
programs
Database Administrators

Users

01
Create the database


7
Design the database
Responsible for managing the databases within an organization
Individuals who enter data, update data, and retrieve information out of the database
01
Data Concepts and Characteristics




Data Hierarchy
Data Hierarchy
Entities and Entity Relationships
Data Definition
The Data Dictionary

Fields/columns


Records/rows


01
01




One entity is related to only one other entity of a particular type




Not a common type of relationship
Most common type of relationship
One entity can be related to more than one other entity


One entity can be related to more than one other entity, and those
entities can be related to multiple entities of the same type as the original
entity

11
01
12
A supplier supplies more than one product to a company
Many to Many (M:M) Entity Relationships

An association between two or more entities
Each store has a single manager
One to Many (O:M) Entity Relationship

Characteristics of an entity
Typically become fields in the entity’s database table
Relationship

One to One (1:1) Entity Relationships

A person, object, or event of importance to the organization
Entities that the organization wants to store data about typically
becomes a database table
Attributes


Relationships
Entity

Contains a group of related tables
10
Entities and Entity Relationships

Collection of related records
Database

9
Groups of related fields
Tables


Hold single pieces of data
An order can contain multiple products and a product can appear on multiple
orders
01
Data Definition


The process of describing the properties of data to be
included in a database table
During data definition, each field is assigned:





Data Concepts and Characteristics
Name (must be unique within the table)
Data type (such as Text, Number, Currency, Date/Time)
Description (optional description of the field)
Properties (field size, format of the field, allowable range, if field is
required, etc.)
Finished specifications for a table become the table structure
13
01
14
01
The Data Dictionary

Contains all data definitions in a database








Table structures

15
Data Integrity
Accuracy of Data

Names, types, and properties of each field
Security information (passwords, etc.)
Relationships between the tables in the database
Current information about each table, such as the current number
of records
Does not contain any of the data in the tables
Does contain metadata, which is information about the database
tables
Ensures that data being entered into the database does not violate
any specified criteria

Quality of data entered determines the quality of generated
information
Data Validation


Process of ensuring that data entered into the database is valid
Record validation rules



16
Can be enforced on a per transaction basis so the entire
transaction will fail if one part is invalid
Database Locking

01
Checks all fields before changes to a record are saved
Prevents two individuals from changing the same data at the same
time
01
Data Integrity
Data Security




Protects data against destruction and misuse
Protects against unauthorized access to and unauthorized use
of a database
Database activity monitoring programs can be used to detect
possible intrusions
Should include strict backup and disaster-recovery
procedures (disaster-recovery plan)

17
01
Display alerts for
vulnerabilities and
attacks
18
Database Models



The Relational Database Model (RDBMS)

Store data in a tree structure
Typically a one-to-many relationship between data entities


Network Databases



Hierarchical Databases

Data is organized in tables related by common fields
Most widely used database model today
Designing a Relational Database

Show the relationship between data elements usually as either one-tomany or many-to-many


Most databases today are neither hierarchical or network models

19
01
Database Models
The Hierarchical and Network Database Models

Protects against data loss
01
20
Identify the purpose of the database
Determine the tables and fields
Assign the fields to a table and reorganize as needed to minimize
redundancy (normalization)
Finalize the structure (primary keys, field properties, etc.)
01
Creating a Relational Database

Creating the Table


In Access, this can be done in Design view or Datasheet view


Existing data can be migrated to the new database
New data can be added via a form or in Datasheet view


Relating Tables


Once all tables have been created, they can be related to one
another using their primary keys
21
Retrieving Information from a Relational Database

Entering and Editing Data



Each table is created using the table structure developed during the
database design process


Query
01
22
01
Reports





23
Maintaining a Relational Database
Reports

A request to see information from a database that matches specific
criteria
Specifies which records should be retrieved by specifying criteria
Can specify the fields to be displayed
Many programs have wizards or other tools to make it easy to
create a query
Must be designed to extract information as efficiently as possible
Queries are saved so they can be retrieved again when needed;
proper results are displayed each time the query is run

Formatted means of looking at a database table or the results of a
query
Reports can pull data from more than one table
Many programs have wizards or other tools to make it easy to
create a report
Can be modified and customized using the Design view
Reports are saved so they can be retrieved again when needed;
proper results are displayed each time the query is run
Maintaining a Relational Database



Data in tables can be edited as needed
Table structures can be modified when needed
Other possible modifications:





01
24
Adding new indexes to speed up queries
Deleting obsolete data
Upgrading database software, installing patches
Repairing/restoring data that has become corrupt
Continuing to evaluate and improve security
01
Try it Yourself!: Choose your database

Choose your database
SQL Server Compact (local: sample.sdf):




Microsoft SQL Server Compact (SQL CE) is a compact relational
database produced by Microsoft for applications that run on mobile
devices and desktops.
Sample.sdf (Download it from Canvas)
Use LinqPad to connect to the database file and execute SQL
statements.
MySql Server:


You should have received an e‐mail before this lecture giving you
the access data to your own database on the server
studdb‐mysql.fos.auckland.ac.nz
Use LinqPad/HeidiSQL to connect to the database file and execute
SQL statements. (Or use SSH client PuTTY on the lab machines,
connect to our server and use mysql to execute commands.




25
01
Choose your database

MS SQL server 2008

Use LinqPad/HeidiSQL to connect to the database file and execute
SQL statements.




27
Enter Server: studdb-mssql08.sfac.auckland.ac.nz
Enter Database: stu_YOURUPI_COMPSCI_280_C_S2_2016 (Replace
YOURUPI with your own UPI)
Enter your User Name with your UPI
Enter Password
01
26
Enter Server: studdb-mysql-fos.auckland.ac.nz
Enter Database: stu_YOURUPI_COMPSCI_280_C_S2_2016 (Replace
YOURUPI with your own UPI)
Enter your User Name with your UPI
Enter Password.
01