Presentation is loading. Please wait.

Presentation is loading. Please wait.

DCS209: Introduction to Database Management (I) prepared and delivered by Iya Abubakar Computer Centre (IACC)Ahmadu Bello University, Zaria M-Auwal Gene.

Similar presentations


Presentation on theme: "DCS209: Introduction to Database Management (I) prepared and delivered by Iya Abubakar Computer Centre (IACC)Ahmadu Bello University, Zaria M-Auwal Gene."— Presentation transcript:

1 DCS209: Introduction to Database Management (I) prepared and delivered by Iya Abubakar Computer Centre (IACC)Ahmadu Bello University, Zaria M-Auwal Gene mcpn © January, 2012 Abridged Lecture Notes (Part 1)

2 2 Introduction DCS209: Introduction to Database Management (I) IACC, ABU, Zaria DCS209: Introduction to Databases (I). Hello, and welcome to DCS209: Introduction to Databases (I). relational databases. Over the coming weeks, we shall take time to learn about some of the general fundamental concepts of the design theories and development techniques for databases; with particular attention to relational databases. downloaded from

3 3 Introduction DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Concepts to be discussed shall include database models, database manipulation languages and database system implementation. participate actively. Classes shall be highly interactive and you are all expected to participate actively. In the Lab sessions, Microsoft Access 2007 shall be used to demonstrate the practical implementation details of concepts discussed during lectures. (…continued) downloaded from

4 4 Introduction DCS209: Introduction to Database Management (I) IACC, ABU, Zaria There shall be regular assignments, bi-weekly quiz/test sessions, as well as the usual end-of- semester written exams. Before your exams though, we shall take on a simple but comprehensive database design and development project so that you will be exposed to how particular attention must always be paid to details when designing and developing database systems for clients in the real world. (…continued) downloaded from

5 5 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria To make the most out of this course, students need to: Have basic computer literacy: (how to start applications and use common Microsoft Office applications). Participate regularly, fully and actively in class and in the labs. Always complete all hands-on lab tasks and follow-up tasks faithfully. Have a willingness/readiness for independent learning. Requirements/Assumptions downloaded from

6 6 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria The following grading policy shall apply in this course: 40% Max. points obtainable for continuous assessments (C.A.)40% 60% Max. points obtainable for final exams60% Out of which: C.A. will include: Take-home assignments 05% Written tests (mostly over current topics)15% Hands-on lab sessions (cumulative)20% Total=40% Final exams will include: Final hands-on practical (lab) exam20% Final written exam (comprehensive)40% Total=60% Grading Policy downloaded from

7 7 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria This course is divided into four parts: Part 1: Part 1: General Introduction to Databases. Part 2: Part 2: Relational Database Design and Development Process. Part 3: Part 3: An SQL Primer. Part 4: Part 4: Course Case Study Project. Outline downloaded from

8 8 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction What you shall learn – The basic concepts: Definition and explanation of terms data, database, database management systems relational database management systems – Review of some database models: flat model hierarchical model network model relational model object and object-relational models – The relational data model: properties of relational tables concept of files, tables, records and fields concept of keys, entities and relations types of relationships (among entities) NOTE: NOTE: Many more introductory concepts and theories shall be discussed in class, so be there and be attentive! downloaded from

9 9 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria What is data? – Data is any representations such as characters or analog quantities to which some particular meaning is or might be assigned. The term data refers to the representation of facts, concepts, or instructions in a formalized manner suitable for communication, interpretation, or processing by humans or by automatic means. NOTE: NOTE: Further detailed explanations shall be given in class, so students, be there and be attentive! Part 1: Part 1: General Introduction downloaded from

10 10 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria What is a database? – Some authors prefer to define a database as a collection of related data items, that has a regular structure, and that is organized in such a way that any desired information contained in the collection can be easily found (for viewing, editing or deleting). related data In simple terms, a database is a store of large amounts of related data, especially in a form that can be handled efficiently by a computer. Part 1: Part 1: General Introduction downloaded from

11 11 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria electronic database system. – When one or more computers or some other electronic devices are used to store this collection of related or structured data items and records, along with the software that manage and control how the data is accessed and used, then we have an electronic database system. – Usually, the data in a database is stored on the computers disk in a format which we humans cannot read or understand directly. What is a database? (…continued) Part 1: Part 1: General Introduction downloaded from

12 12 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – To aid our access to, understanding of, and manipulation of the data stored in a database, we need a specialized software system to help out. NOTE: Although we have defined it as above, these days the word database is commonly used in a broad sense to refer not only just to structured data but also to the DBMS that is used with it. What is a database? (…continued) Part 1: Part 1: General Introduction downloaded from

13 13 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria What is a database management system (DBMS)? - By this, we mean that a DBMS actually helps control how data is stored, organized, retrieved and manipulated efficiently in one or more databases – thus providing an easy interface or gateway between the human operator and the data stored in a database. A database management system (or DBMS) is a well- developed suite of software programs that efficiently controls how databases are created, maintained and used on one or more computers. Part 1: Part 1: General Introduction downloaded from What is a database management system?

14 14 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – With the help of a DBMS, it is easy to retrieve information from a database, add new data, amend existing data, or delete unwanted data from a database. integrityconsistency – Of course, a DBMS also performs other sophisticated functions, such as maintaining the overall integrity and consistency of data in the database, among other functions. What is a database management system? (…continued) + +These terms shall be explained further in class, so be there and be attentive! + + Part 1: Part 1: General Introduction downloaded from

15 15 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – In the real world, examples of very successful database management systems include Microsoft Access, Microsoft SQL Server, Oracle Database, PostgreSQL, MySQL, and so on. relational database management system RDBMS – In this course, we shall focus our attention on a very popular kind of DBMS, known as the relational database management system, or RDBMS. What is a database management system? (…continued) Part 1: Part 1: General Introduction downloaded from

16 16 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Understanding relational database management system (RDBMS) – We have seen what a database is, and we have also explained what a DBMS is. Now what is a relational database management system, or RDBMS? hierarchical data model network data model – In the early days of computer development, there were database systems which mostly conformed either to the hierarchical data model or the network data model. Part 1: Part 1: General Introduction downloaded from Understanding RDBMS

17 17 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – While they worked well, a major drawback was that these models were too technical for ordinary computer operators to use. relational data model tablesrelated to one anotherkeys – In 1970 or thereabouts, a research fellow called E. F. Codd who was working at IBM introduced the relational data model. In this model, the database is represented as a collection of tables which are related to one another through some sort of keys. Understanding RDBMS (…continued) Part 1: Part 1: General Introduction downloaded from We shall talk more about relational databases later, after reviewing some other interesting data models first.

18 18 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Review of some database models – A database model is a theory or concept or specification that describes how a database is structured and used. – Several basic types of database models have been developed over the years – including flat, hierarchical, network and relational. – Such models describe not only the structure of the conforming databases but also the operations that can be performed on them. Part 1: Part 1: General Introduction downloaded from Review of some data models

19 19 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria schema – Typically, a database has a schema, which is a description of the model, including the types of entities that are in it and the relationships among them. – We shall look at a few database models here and later, we shall discuss the fundamental elements of relational databases and how to develop them. Part 1: Part 1: General Introduction downloaded from Review of some data models (…continued)

20 20 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria The flat model – The flat (or table) model consists of a single, two- dimensional array of data elements, where all members of a given column are assumed to be similar values, and all members of a row are assumed to be related to one another. – However, a flat file structure involves data records that really have no structured interrelationship. Part 1: Part 1: General Introduction downloaded from Review of the flat model

21 Pretty Picture 21 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – A flat file might take up less computer space than a structured file, but requires the database application to know exactly how the data are organized within the file otherwise the application will not work. – Take a simple tabular file that is used to store a list of Local Government Areas with information about each – such as name, the State, Country and Region it belongs to, population, land area, etc: Part 1: Part 1: General Introduction downloaded from Review of the flat model (…continued)

22 22 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from Review of the flat model (…continued) Fig. 1: Flat file structure.

23 23 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – In such a tabular flat file as shown in Fig. 2, LGA names and other details are stored such that each row would have the specific data values associated with an individual LGA. – Columns of the table often have a type associated with them, defining them as character data, integers or floating point numbers, date or time information, etc. – Strictly speaking, a flat file model may not qualify as a data model, but is quite common for people to loosely consider it as one. Part 1: Part 1: General Introduction downloaded from Review of the flat model (…continued)

24 24 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria The hierarchical model – A hierarchical data model is a data model in which the data is organized such that records are linked together into a tree-like structure. – The structure allows repeating information using parent-child relationships whereby any child may only have one parent but a parent can have multiple children. Part 1: Part 1: General Introduction downloaded from Review of the hierarchical data model

25 25 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Parents and children are tied together by links called pointers. A parent will have a list of pointers to each of their children. This type of database is highly inflexible but can be very efficient in the processing of data. – The hierarchical model collects all the instances of a specific record together as a record type. These record types are the equivalent of tables in the relational model, and with the individual records being the equivalent of rows. Part 1: Part 1: General Introduction downloaded from Review of the hierarchical data model (…continued)

26 26 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – The hierarchical model uses 1:N mapping between record types to create links among records. Part 1: Part 1: General Introduction downloaded from Review of the hierarchical data model (…continued) Fig. 2: Hierarchical structure.

27 27 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Hierarchical structures were widely used in the first mainframe database management systems; and even now they are used in describing the structure of XML documents. – This structure allows one 1:N relationship between two types of data but, they are quite restricted. Part 1: Part 1: General Introduction downloaded from Review of the hierarchical data model (…continued)

28 28 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – For example, the hierarchical structure is inefficient for certain database operations when a full path (as opposed to upward link and sort field) is not also included for each record. – Despite the restrictions however, this structure is very efficient to describe many relationships in the real world; such as recipes, table of contents, ordering of paragraphs/verses, any nested and sorted information. Part 1: Part 1: General Introduction downloaded from Review of the hierarchical data model (…continued)

29 29 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria The network model – The popularity of the network data model coincided with the popularity of the hierarchical data model. – Some data were more naturally modeled with more than one parent per child. So, the network model permitted the modeling of many-to-many relationships in data. Part 1: Part 1: General Introduction downloaded from Review the network model

30 30 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – In many ways, the network database model was designed to solve some of the more serious problems with the hierarchical model. – Specifically, the network model solves the problem of data redundancy by representing relationships in terms of records and sets rather than hierarchy. Part 1: Part 1: General Introduction downloaded from Review the network model (…continued)

31 31 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Network databases were designed to address some of the issues of inflexibility of the earlier hierarchical databases. – Each parent could have many children and each child could have many parents. – This model gives more flexibility of data access than the hierarchical model but at the cost of processing efficiency. Part 1: Part 1: General Introduction downloaded from Review the network model (…continued)

32 32 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria recordssets – According to the definition given by the CODASYL (Conference on Data Systems Languages) specification, the network model organizes data using two fundamental constructs, called records and sets. – Records contain fields (which may be organized hierarchically, as in the programming language COBOL). Part 1: Part 1: General Introduction downloaded from Review the network model (…continued)

33 33 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Sets (not to be confused with mathematical sets) define one-to-many relationships between records: one owner, many members. – A record may be an owner in any number of sets, and a member in any number of sets. Part 1: Part 1: General Introduction downloaded from Pretty Picture Review the network model (…continued)

34 34 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from Review the network model (…continued) Fig. 3: Network structure.

35 35 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – The network model is a variation on the hierarchical model, to the extent that it is built on the concept of multiple branches (lower-level structures) emanating from one or more nodes (higher-level structures), while the model differs from the hierarchical model in that branches can be connected to multiple nodes. – The network model is able to represent redundancy in data more efficiently than in the hierarchical model. Part 1: Part 1: General Introduction downloaded from Review the network model (…continued)

36 36 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – The operations of the network model are navigational in style: a program maintains a current position, and navigates from one record to another by following the relationships in which the record participates. – Records can also be located by supplying key values. Part 1: Part 1: General Introduction downloaded from Review the network model (…continued)

37 37 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria The relational model data independence – The theory of relational databases is based on the idea that information systems should maintain data independence, i.e. that the user of a database system should not be concerned with the internal workings, or structure of data in the system. interrelatedtables – A relational database is a way of organizing data such that the data appears to the user to be stored in a series of interrelated tables. Part 1: Part 1: General Introduction downloaded from Review of the relational model

38 38 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria a collection tablesrelated keys – In 1970 or thereabouts, a research fellow called Edgar F. Codd who was working at IBM introduced the relational data model. In this model, the database is represented as a collection tables which are related to one another through some sort of keys. – Edgar Codd proposed that users should be abstracted from the internal representation of the data, such that if the internal representation of that data were to change (e.g. because of system growth), the way that the user perceives the data should remain unchanged. Part 1: Part 1: General Introduction downloaded from Review of the relational model (…continued)

39 39 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – To this end, Codd proposed a relational view of data, rather than pre-existing graphical or network views. – Interest in this model was initially confined to academia, perhaps because the theoretical basis is not easy to understand. Pretty Picture Part 1: Part 1: General Introduction downloaded from Review of the relational model (…continued)

40 40 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from Review of the relational model (…continued) Fig. 4: Relational structure.

41 41 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Relational databases did not become mainstream until around 1980 but from then onward however, they became the dominant type for high-performance applications because of their efficiency, ease of use, and ability to perform a variety of useful tasks that had not been originally envisioned. Part 1: Part 1: General Introduction downloaded from Review of the relational model (…continued)

42 42 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Object and object-relational models – Object-oriented databases became a new focus of research during the 1990s, in part because of the great success that the object-oriented concept was having in programming languages (e.g., C++ and Java). multimediaengineering data – Such databases have had some success in fields in which it is necessary to accommodate bulky and more complex data than relational systems can easily cope with, such as multimedia and engineering data, and some object-oriented concepts were thus integrated into leading commercial relational database products. Part 1: Part 1: General Introduction downloaded from Review of object and object-oriented models

43 43 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Object-relational database management systems (ORDBMSs) add new object storage capabilities to the relational systems at the core of modern information systems. – As mentioned above, these new facilities integrate management of traditional fielded data, complex objects such as time-series and geospatial data and diverse binary media such as audio, video, images, and applets. Part 1: Part 1: General Introduction downloaded from Review of object and object-oriented models (…continued)

44 44 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – By encapsulating methods with data structures, an ORDBMS server can execute complex analytical and data manipulation operations to search and transform multimedia and other complex objects. – It must be noted, however, that object databases have not done pretty well because of a lack of standardization: although standards were defined by the Object Database Management Group (ODMG), they were never implemented well enough to ensure interoperability between products. Part 1: Part 1: General Introduction downloaded from Review of object and object-oriented models (…continued)

45 45 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – Nevertheless, object databases have been used successfully in many applications: usually specialized applications such as engineering databases or molecular biology databases rather than mainstream commercial data processing. Part 1: Part 1: General Introduction downloaded from Review of object and object-oriented models (…continued)

46 46 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from What you shall learn – The relational data model: properties of relational tables concept of files, tables, records and fields concept of keys, entities and relations types of relations (among entities) A closer look at the relational data model

47 47 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from Properties of Relational Tables – We have already learnt that a relational database allows the definition of data structures, storage and retrieval operations as well as integrity constraints. tables. – We have also learnt that in such a database the data and relations between them are organized in tables. – A table is a collection of records and each record in a table contains the same fields. A closer look at the relational model

48 48 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – As tables, relational databases have some important properties as enumerated below: o Values are atomic o Each row is unique o Each column has a unique name o Column values are of the same kind o The sequence of columns is insignificant o The sequence of rows is insignificant Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

49 49 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Understanding files, tables, records and fields file – In data processing, using an office metaphor, a file is simply a collection of related records. Database files consist of tables, queries, forms, views, reports and so on which are related to the subject of the database. table – A table in a relational database is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows. – A table has a specified or fixed number of columns, but can have any number of rows. Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

50 50 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria record; fields – Each row in a table represents a record; while the vertical columns constitute the fields of the record. Pretty Picture Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

51 51 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria DateItemCodeSupplierUnitPriceQtyReceivedTOTAL 24/05/2010TB-720 EMENCO pvt LTD, INDIA , /05/2010TB-382 EMENCO pvt LTD, INDIA , /05/2010WH-555 GUING LU INTL, CHINA 1, , :::::: field attribute each column is a field or attribute of a record record table each row is a record of one stock entry and all the records together make up a table Fig. 5: Concepts of fields and records explained. Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

52 52 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria more than one table with interrelated data – As it is, the single table shown in Fig. 5 with a row-and-column structure does not, technically speaking, constitute a relational database. A relational database must have more than one table with interrelated data, not just one table. flat file – The stocks entry table we have seen in Fig. 5 is, technically speaking, a flat file type of database. Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

53 53 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria – But if we now bring in, say, the daily sales record table, and consider it together with the stocks entry table shown in Fig. 5, then we are getting closer to having a relational database. key, key – Take note, however, that the idea of having just two or more tables together does not necessarily make a relational database. The two or more tables must be related via at least one key, before we can say we are having a relational database. So, what is a key? Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

54 54 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Understanding keys, entities and relations – In a relational database, certain fields of a table may be designated as keys. – [And] as you already know by now, databases use tables to organize information; and each table consists of a number of rows, each of which corresponds to a single database record. keys. – So, how do databases keep all of these records straight? Its through the use of keys. Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

55 55 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria keyrecord key – Simply put, a key (or record key) is just any data field (or attribute) that can be used to identify a record in a table. This means that any of the data fields in a table can be used as a record key. uniquely primary keys. – However, we often dont just want to identify records, but we want to uniquely identify records. So rather than talk about just keys, we often talk about primary keys. Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

56 56 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria uniquely identifies – A primary key is an attribute that uniquely identifies any given record in a table. – It can either be a normal attribute that is guaranteed to be unique (such as a students Matriculation Number, or a bank customers Account Number in a table with no more than one record per person) or it can be generated by the DBMS (such as a globally unique identifier, or GUID, in Microsoft SQL Server or an auto-number column in Microsoft Access). Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

57 Entities – An entity is a person, place, thing, event, or concept of interest to the business or organization about which we want to collect and store multiple instances of data. – For example, in a school environment possible entities might be Student, Instructor, and Class. – And in a banking environment, possible entities might include Customer, Account, Teller, Auditor or Cash Withdrawal. 57 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria NOTE: NOTE: Further detailed explanations shall be given in class, so students, be there and be attentive! Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

58 Entities – An entity must have a name, which is a noun; and has attributes which describe the data we are interested in storing. – An entity should also have an identifier, which uniquely identifies one instance of that entity. – The attribute which acts as the identifier is usually underlined or marked with an asterisk. 58 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria NOTE: NOTE: Further detailed explanations shall be given in class, so students, be there and be attentive! Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

59 Types of relationships (among entities) interrelatedtables – You will recall that a relational database is a way of organizing data such that the data appears to the user to be stored in a series of interrelated tables. interaction – In database speak, the relationship among entities is simply the interaction between the entities; and such interactions are usually derived from the business rules that operate on the domain of discourse. 59 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

60 – Thus in a commerce-oriented database system for example, a customer places one or more orders (for one or more items to be supplied). places – So the word places defines the relationship between that instance of a customer and the order or orders that they place. 60 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

61 – Depending on the notation used, a relationship may be represented by a diamond shape, or more simply, by the line connecting the entities. – In either case, verbs are used to label the relationships. 61 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

62 – A major part of designing a relational database is dividing the data elements into related tables. – After all else is done, you will be ready to start working with the data, and both you and the DBMS will rely on relationships between the tables to pull the data together in meaningful ways. – Lets take a quick and relatively simple example: 62 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

63 orderscustomers – In a commerce-oriented system, information about orders (placed by customers) is useless unless you (and/or the DBMS) can tell which customer placed a particular order. A major part of designing a relational database is dividing the data elements into related tables. – However, good database design principles require that you don't store customer and order information in the same table. 63 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

64 – Instead, you should store order and customer data in two different tables that will then be related in one of three or four ways (that we shall discuss shortly). – To view any order and its corresponding customer information at the same time, you (and/or the DBMS) can then use the relationship between the two tables to do so. normalization normalized – This approach is called normalization (we shall look at that later in this course); and the tables are said to be normalized. 64 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

65 – Normalized tables are the foundation of relational databases, and relationships are the cornerstone. – Okay, example done, now lets go back to our discussion about types of relationships among entities. – So we know what relationships are: you have a lot of relationships in your personal life, starting with members of your family, for example. 65 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

66 – For instance, you and your mother are related. You have only one mother, but she may have several children. – You and your siblings are related, too; and if you have many brothers and sisters, then they will have many brothers and sisters as well. – If you have a spouse, then both you and your spouse have a spouse -- you each have each other -- but only one at a time. 66 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

67 – Database relationships are somewhat like that too, in the sense that they are associations between entities (or tables). – In relational database studies, there are four major types of relationships that should be understood by everyone. These are: one-to-one relationships (1:1) one-to-many relationships (1:n) many-to-one relationships (n:1) many-to-many relationships (m:n) 67 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

68 One-to-One Relationships (1:1) – Here, both entities can have only one record on either side of the relationship. In a workplace for example, each employee is associated with one department (assuming no employee is allowed to serve in more than one department at a time). – In the case of families, 1:1 relationship can be seen in settings where only monogamy is allowed: at any given time, a man can have one wife and a wife can have only one husband. 68 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

69 One-to-Many Relationships (1:N) – Here, one entity is associated with many other entities. The primary key table contains only one record that may relate to none, one, or many records in the related table. – Example: – Example: A company may have many employees, all of whom belong to that one company. – Example: – Example: You (and your siblings) have only one mother, but your mother may have several children. 69 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

70 Many-to-One Relationships (N:1) – Here, many entities are associated with only one entity. This is actually like the one-to-many relationship in reverse. – Example: – Example: In a company, many employees could be associated with one project. – Example: – Example: In a class of a school, many students may be associated with (taught by) one instructor. 70 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

71 Many-to-Many Relationships (M:N) – Here, many entities are associated with many other entities. – Example: – Example: In a company, many employees could be associated with multiple projects (completed/existing), and at the same time, projects are associated with multiple employees. – Example: – Example: If you have several siblings, so do your siblings (have many siblings). 71 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

72 – During actual implementation, many-to-many relationships require a third table, known as an associate, linking or junction table, because relational systems cant directly accommodate the relationship. 72 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria Part 1: Part 1: General Introduction downloaded from A closer look at the relational model (… continued)

73 The End Thank You Thank You Coming up in Part 2: relational database design and development process, with emphasis on E-R diagramming and data dictionaries 73 DCS209: Introduction to Database Management (I) IACC, ABU, Zaria downloaded from


Download ppt "DCS209: Introduction to Database Management (I) prepared and delivered by Iya Abubakar Computer Centre (IACC)Ahmadu Bello University, Zaria M-Auwal Gene."

Similar presentations


Ads by Google