Download presentation
Presentation is loading. Please wait.
Published byValentine Bates Modified over 8 years ago
1
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML
2
Database Models The DDL of a given DBMS is too low level to describe an organisations data requirements in a readily available manner. A data model may be defined as; An integrated collection of concepts for describing data (real world objects and events), relationships between data, and constraints on the data in an organization. Provides basic notations and concepts that will allow database designers and end-users to unambiguously and accurately communicate their understanding of the organisational data. 2Database Models
3
3 The process of data modelling allows one to see the options provided by possible representations and to predict the effects of our decisions. If not done well, serious problems may be caused later in the development process. Data Model comprises: A structural part A manipulative part Possibly a set of integrity rules Purpose To represent data in an understandable way.
4
Database Model cont’d There are different database models which include: Relational ERD: mainly used in design Object based: Object oriented and object-relational Semi-structured e.g. XML Network and Hierarchical database models. These fall under one of the following categories of data models: Object-based Record-based Physical 4Database Models
5
Database Models cont’d Object-based Data Models These use concepts based on entities, attributes and relationships. Some examples include; Entity-Relationship Semantic Functional Object-Oriented 5Database Models
6
Database models cont’d Record-based Data Models Database consists of a number of fixed-format records possibly of differing types. Each record type is defined by a fixed number of fields, each with a fixed length These include; Relational, Network and Hierarchical data models. Database Models1.6
7
Database models cont’d Relational Data Model Based on mathematical relations Data and relationships are represented as tables, each having uniquely identified columns Network Data Model Data is represented as a collection of records Relationships are represented as sets The sets are implemented as pointers A graphical representation is used. 7Database Models
8
Database models cont’d Hierarchical Data Model Restricted type of network model A tree-graph representation is used (records/segments as nodes and sets as edges.) A node is allowed to have only one parent Physical Data Models Present how data is stored in a computer e.g. structures of records. 8Database Models
9
Relational Database Concepts1.9 Example of a Relational DB A company needs to store information on departments and employees. Each table contains data that describes exactly one entity - a thing of significance about which information needs to be known.
10
Relational Database Concepts1.10 Relational Database Concepts Relation – a table composed of rows and columns Attribute – a column of a relation. Tuple – a row of a relation. Cell – an intersection of a row and a column of a relation. Domain – a set of allowable values for one or more attributes. Null – a value that is unknown or not applicable in a given cell.
11
Relational Database Concepts1.11 Degree – number of attributes for a given relation. Cardinality – number of tuples for a given relation. Relation schema – a named collection of attributes and any data constraints. Representation of a department relation schema DEPARTMENT (DeptNo, DName, Loc) Data Constraints: A department name value must never be repeated. Relational Database Concepts Cont’d
12
Relational Database Concepts1.12 Instances of Branch and Staff (part) Relations
13
Relational Database Concepts1.13 Examples of Attribute Domains
14
Relational Database Concepts1.14 Alternative Terminology for Relational Model
15
Relational Database Concepts1.15 Relational database – a finite set of relational schemas. Representation of a relational database schema for a company that stores information on departments and employees. DEPARTMENT (DeptNo, DName, Loc) EMPLOYEES (EmpNo, EName, Job, Mgr, HireDate, Sal, Comm, DeptNo) Data Constraints: A department name value must never be repeated. No employee should earn a salary that is more than 5000. Relational Database Concepts Cont’d
16
Relational Database Concepts1.16 Primary key – attribute(s) that is selected to identify tuples uniquely within a relation. A primary key value must be unique and cannot be null. Unique key – attribute(s) that contains distinct values but can also accommodate null values. Foreign key – attribute(s) within one relation that matches attribute(s) of another or same relation. A foreign key value must match the primary/unique key value of some tuple in its parent relation or the foreign key value must be wholly null. Relational Database Concepts Cont’d
17
Relational Database Concepts1.17 Properties of Relations: Uniqueness of relation names in a relational database schema. Uniqueness of attributes for a given relation Uniqueness of tuples for a given relation Order of attributes / tuples for a given relation is not significant Values of an attribute are from the same domain. A cell of a relation contains exactly one atomic (single) value. Relational Database Concepts Cont’d
18
Relational Database Concepts1.18 Relational Keys Super key An attribute, or a set of attributes, that uniquely identifies a tuple within a relation. Candidate Key Superkey (K) such that no proper subset is a superkey within the relation. In each tuple of R, values of K uniquely identify that tuple (uniqueness). No proper subset of K has the uniqueness property (irreducibility).
19
Relational Database Concepts1.19 Relational Keys Cont’d Primary Key Candidate key selected to identify tuples uniquely within relation. Alternate Keys Candidate keys that are not selected to be primary key. Foreign Key Attribute, or set of attributes, within one relation that matches candidate key of some (possibly same) relation.
20
Relational Database Concepts1.20 Relational Integrity Null Represents value for an attribute that is currently unknown or not applicable for tuple Deals with incomplete or exceptional data. Represents the absence of a value and is not the same as zero or spaces, which are values. Enterprise Constraints Additional rules specified by users or database administrators.
21
Relational Database Concepts1.21 Relational Integrity Cont’d Entity Integrity In a base relation, no attribute of a primary key can be null. (Please note that this is a correct statement: because a primary key may be formed of more than one attribute.) Referential Integrity If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null.
22
Introduction Database Languages1.2.22 Database Languages Database Languages are known as data Sublanguages. DBMSs have a facility for embedding the sublanguage in a high-level programming language e.g. C, C++, Java Or VB. The high-level language is then known as a host Language. Most data sublanguages also provide interactive commands that can be input directly from a terminal.
23
Introduction Database Languages1.2.23 Database languages Cont’d A data sublanguage consists of two parts: Data definition Language (DDL) Used to specify the database schema. Data Manipulation Language (DML) Used to read and update the database.
24
Data Definition Languages1.2.24 Data Definition Language (DDL) This is a language that allows the DBA or user to describe and name the entities, attributes and relationships required for the application, together with any associated integrity and security constraints (Begg & Connolly, 2002) DDL is not only used to specify new database schemas but also to modify exiting ones. A database schema is a logical grouping of objects that belong to a user. All created objects / structures (such as tables, views, indexes) are stored in a database schema.
25
Data Definition Languages1.2.25 DDL cont’d Relation DB schema objects are created and maintained by using SQL DDL statements (such as CREATE, ALTER, DROP). The result of compiling DDL statements is a set of tables stored in special files collectively called the system catalog. The system catalog may also be referred to as a data dictionary.
26
Data Definition Languages1.2.26 DDL Cont’d The data dictionary integrates the meta-data; definitive information about the structure is recorded in a data dictionary. For example: definitions about the records, data items and other objects of interest to users or required by the DBMS. The DBMS consults the data dictionary before accessing or manipulating the data. Example of DDL SQL statement: CREATE, ALTER, DROP, RENAME, TRUNCATE
27
Data Manupulation lanaguages1.2.27 Data Manipulation Language (DML) This is a language that provides a set of operations to support the basic data manipulation operations on the data held in the database. Some of the operations include: Insertion of new data into the database Modification of data stored in the database Retrieval of data contained in the database (Query language). Deletion of data from the database.
28
Data Manupulation lanaguages1.2.28 DML Cont’d Procedural DML This is a language that allows the user to tell the system what data is needed and exactly how to retrieve the data; allows user to tell system exactly how to manipulate data. Non-Procedural DML allows user to state what data is needed rather than how it is to be retrieved.
29
Data Manupulation lanaguages1.2.29 DML Cont’d Examples of DML SQL statements; INSERT UPDATE DELETE MERGE
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.