Presentation is loading. Please wait.

Presentation is loading. Please wait.

Welcome to CIS 2002: DATABASE DESIGN AND IMPLEMENTATION Semester 1, 2014 – LECTURE 2 7 January 2016 1.

Similar presentations


Presentation on theme: "Welcome to CIS 2002: DATABASE DESIGN AND IMPLEMENTATION Semester 1, 2014 – LECTURE 2 7 January 2016 1."— Presentation transcript:

1 Welcome to CIS 2002: DATABASE DESIGN AND IMPLEMENTATION Semester 1, 2014 – LECTURE 2 7 January 2016 1

2 USAGE OF SLIDES  Use of these lecture slides is restricted to teaching staff and students enrolled in this course. All students who use these slides should have acquired the prescribed texts.  These slides are for the personal use of students on the Study Desk only.  Students should not copy slides, allow third parties access to the slides or distribute the slides.  Copyright of these slides vests in the university and, where applicable, Cengage Education 7 January 2016 2

3 VOLUME OF WORK In this course, the first few weeks are relatively intense in regards to readings, size of lecture, etc. THIS ALLOWS you to build knowledge and skills quickly giving you many weeks to work on practical problems As the semester progresses, the amount of new material introduced each week declines, HOWEVER… Tutorial / practical work becomes progressively more intense 7 January 2016 3

4 WEEKLY ONLINE QUIZ A weekly online quiz will be made available on the Study Desk This will also familiarize you with the process of taking the online test Click on the link Have a practice run after you studied the lecture and tutorials 7 January 2016 4

5 ONLINE TEST Released to the USQStudyDesk next week Available until 23h55 on 24 March 2014 See Introductory Book for more detail The following material will be examined: Casteel, chapter 2 & 8 This test is worth FIVE PERCENT. Read the materials attentively so you know where to look. It is not necessary to rote learn for this test. Practice is key! 7 January 2016 5

6 READINGS – WEEK 2 Study Book, Module 2 Study Book, modules 9.1(optional) Selected Readings 2.1 and 2.2 (Will be used for next 5/6 weeks) Casteel, chapter 2 Casteel, chapter 8 7 January 2016 6

7 Lecture 2 Objectives Working with Oracle ISQLPLUS environment Data Analysis and Modelling Data Models Data Model Concepts Entities Attributes Data Associations (Relationships) Cardinality Business rules SQL WHERE Clause ORDER BY Clause 7 January 2016 7

8 WORKING WITH ORACLE Two interfaces – Oracle SQL Client Interface and Web (HTML) interface In the labs we will use the Web interface ISQLPLUS Web interface is much more user friendly but has a few disadvantages, e.g. some functionality is lost in formatting output 8

9 iSQLPLUS (WEB INTERFACE) 1 We will use this utility in labs and you can use it from home or anywhere as long as there is a good Internet connection Primary server: http://orastud-is1.usq.edu.au:5560/isqlplus/workspace.uix Reserve server: http://oradb-stud2.usq.edu.au:5560/isqlplus Only use the reserve server if you have problems accessing the primary server. You will need to repeat any work already done in primary server, e.g. running table create scripts. 9

10 iSQLPLUS 2 You will get the ISQLPLUS login screen. Enter your username and password and the following host string if it is not already entered for you: Primary server: student Reserve server: student.usq.edu.au Note: Details about your username and password are contained in Tutorial 1 10

11 iSQLPLUS 3 (LOGIN SCREEN – RESERVE SERVER) 11

12 iSQLPLUS 4 You will now be taken into the Oracle Web (HTML) interface (see next slide). Be careful while having more than one SQL statement active at one time. When you have completed a statement, remove it (or click clear button) before starting with the next. 12

13 iSQLPLUS 5 13

14 iSQLPLUS 6 In the workspace tab, you can: Enter SQL command and click on execute Use to save OR cut and paste to Notepad ( not Word) To load a script, click and then select the script file and click in the right hand side. 14

15 iSQLPLUS 7 The tab allows you to retrieve previous SQL statements that were executed. The button at the top allows you to set local (client) preferences – be careful not to change the default formatting options. You can CHANGE PASSWORD from the section. 15

16 ISQLPLUS 8 When you write programs (especially longer programs towards the end of semester) keep a running copy of your work in Notepad. Sometimes, the connection goes down Copying from Word to ISQLPLUS sometimes causes problems, especially with the quotes. 16

17 ISQLPLUS 9 Always click on icon at the top to finish your session. REMEMBER THIS!! Don’t just close the browser. 17

18 Data Analysis and Modelling We use the key elements of the Finkelstein approach for data analysis and modelling This approach (also called Information Engineering) is the standard at USQ - with minor adaptations based on industry standards 7 January 2016 18

19 Analysis & Modelling - A Tool Analysis – goal is to break a complex requirement into smaller parts to better understand the requirement. Modelling - goal is to try and make a model of the requirement to better understand the requirement. Models are: inexpensive to produce relatively easy/cheap to change excellent communication for structured ideas exchange 7 January 2016 19

20 Logical Model basis of existing system Focuses on WHAT, not HOW interpret in plain English 7 January 2016 20

21 Data Model in SDLC Used during the data analysis phase of the SDLC BUT can be used as standalone tool or outside the SDLC paradigm Database design (logical and physical) Used as a means of communication with users contains business rules relevant to the data 7 January 2016 21

22 Data Modelling: art or science? Is Data Modelling an art or science ? Can it be done by following a specified set of rules/procedures. You decide as you do it. 7 January 2016 22

23 What about Process ? The theory says that good Data Modelling is independent of process. Is this really the case ? Can we create models, even databases without considering how they will be used ? If you are working on a system which already exists, do you think that you will work independent of process ? 7 January 2016 23

24 Modelling Methods Many Modelling methods Entity relationship (ER) modelling Natural language Information Analysis Method (NIAM) Unified Modelling Language (UML) 7 January 2016 24 Our focus

25 What is the data model? A graphical representation that is an abstraction of the data (or ‘things’) under investigation 7 January 2016 25

26 Data Model Three level architecture Conceptual Schema – to organise the data requirements Logical Schema – to describe the structure of data, e.g. table and columns Physical Schema – to describe the physical means in storing data, e.g. storage, partitions, CPU 7 January 2016 26

27 Data Model Concepts Data Entities (Entities) Entity type - classification (e.g. UNIVERSITY) Entity occurrence - individual (e.g. USQ) Data Attributes Data Associations (Relationships) Cardinality Business rules 7 January 2016 27

28 Data Entity Represents some 'thing' that is to be stored for later reference. Always named in the singular e.g. CUSTOMER, ORDER, STUDENT Is any object of interest to the organisation under investigation, any part of the system, or any object about which data can be collected and stored 7 January 2016 28

29 Data Entity (2) Often shortened to ‘entity’ Entity refers to the logical representation of data compared with the physical representation on disk or on paper (record) 7 January 2016 29

30 Data Attribute A 'piece' of information that describes a data entity. Referred to as an attribute or a data item. Always uniquely named in the singular. 7 January 2016 30 Entity: PLAYER Attributes: player name, position, nationality

31 Data Relationship or Association Indicates that a relationship exists between two entities. May be called association or relationship Two entity occurrences are related if a change in one makes a significance difference to the other, 7 January 2016 31 eg. The relationship between jobs and workers a job has a worker/s associated with it a worker/s have jobs associated with them the removal of one effects the other

32 The Data Model Is built from: Entities Attributes Associations 1/7/2016 32

33 The Data Model - Illustrated 1/7/2016 33 ENTITY A ENTITY B

34 Cardinality - One to One A department has one manager and a manager manages one department 1/7/2016 34 DEPTMANAGER

35 Cardinality - One to Many 1/7/2016 35 ORDERINVOICE An order generates (one or) many invoices and an invoice is generated against one order

36 Cardinality - Many to Many 1/7/2016 36 PRODUCTPART A product contains (one or) many parts and a part is used in (one or) many products

37 Cardinality Tells how many occurrences of one entity type are linked to occurrences of the other entity type Ask: "What is the maximum number of instances in the second entity that this first entity can be related to?" Then repeat in the reverse order. 1/7/2016 37

38 Cardinality One to one One to Many Many to many 1/7/2016 38

39 Business Rules or Optionality Optional Mandatory Optional becoming mandatory (not used extensively in this course) 1/7/2016 39

40 Relationships 1/7/2016 40 A relationship is a logical connection between two entities. It defines and qualifies the relationship between the entities. Relationship Degree (or cardinality) SKILLEMPLOYEE SKILLEMPLOYEE One or many One Relationship Nature Optional Mandatory An employee MAY have (one or) many skills. A skill MUST be assigned to one (and only one) employee.

41 Relationships 1/7/2016 41 SKILL JOBEMPLOYEE Entities Relationships An employee MAY be allocated to many jobs. A job MUST be allocated to (one or) many employees. A job requires (one or) many skills. A skill MAY relate to (one or) Many jobs. An employee MUST have (one or) many skills. A skill may be assigned to (one or) many employees

42 Relational Database Design steps 7 January 2016 42 Data Requirements Data Model Candidate Relations (or just relations) Normalized relations Tables in a relational database Supporting Physical Implementation e.g. indexes

43 1. DATA REQUIREMENTS An employee MUST be assigned to one (and only one) department. For employees, we store empid and employye name A department MAY have (one or) many employees. We store deptno, department name and location 7 January 2016 43

44 2. DATA MODEL CONSIDER THE FOLLOWING ERD 7 January 2016 44 EMPLOYEE An employee MUST be assigned to one (and only one) department A department MAY have (one or) many employees Notes: MAY implies that a department need not have any employees If the department only has one employee, the rule is satisfied. It has the potential to have many employees DEPARTMENT

45 3. CREATE A RELATION Now, convert the entity and (where applicable) it’s relationships, into a relation If an entity is on the MANY side of a relationship, you will need to add a foreign key to the attributes Another name for a set of relations is an ENTITY LIST 7 January 2016 45

46 3 and 4. RELATIONS Consider the relation: EMPLOYEE(empid#,empname,deptid#) The relation is named EMPLOYEE and has THREE attributes. empid# is the primary key deptid# is a foreign key pointing to DEPARTMENT NOTE how keys are represented. These relations are already normalized. 7 January 2016 46

47 RELATIONS 2 The relation DEPARTMENT becomes: DEPARTMENT(deptno#, department name, location) 7 January 2016 47

48 SQL – CASTEEL CHAPTER 8 7 January 2016 48

49 WHERE Clause Syntax A WHERE clause is used to retrieve rows based on a stated condition Requires: Column name Comparison operator Value or column for comparison Values are case sensitive 49

50 WHERE Clause Example List WHERE clause after FROM clause Enclose nonnumeric data in single quotes 50

51 Comparison Operators Indicate how the data should relate to the given search value 51

52 Arithmetic Comparison Operators 52

53 Other Comparison Operators 53

54 BETWEEN…AND Operator Finds values in a specified range 54

55 IN Operator Returns records that match a value in a specified list List must be in parentheses Values are separated by commas 55

56 IN Operator Example 56

57 LIKE Operator Performs pattern searches Used with wildcard characters: Underscore (_) for exactly one character in the indicated position Percent sign (%) represents any number of characters 57

58 LIKE Operator Example 58

59 Logical Operators Used to combine conditions Evaluated in order of NOT, AND, OR: NOT – reverses meaning AND – both conditions must be TRUE OR – at least one condition must be TRUE 59

60 AND Logical Operator Example 60

61 OR Logical Operator Example 61

62 Multiple Logical Operators Resolved in order of NOT, AND, OR 62

63 Multiple Logical Operators Use parentheses to override the order of evaluation 63

64 Resolving Multiple Types of Operators 1. Arithmetic operators 2. Comparison operators 3. Logical operators 64

65 Treatment of NULL Values Absence of data Requires use of IS NULL operator 65

66 Treatment of NULL Values (continued) A common error is using = NULL which does not raise an Oracle error but it also does not return any rows 66

67 ORDER BY Clause Syntax The ORDER BY clause presents data in sorted order Ascending order is default Use DESC keyword to override column default 255 columns maximum 67

68 ORDER BY Clause Syntax Sort Sequence In ascending order, values will be listed in the following sequence: Numeric values Character values NULL values In descending order, sequence is reversed 68

69 ORDER BY Example 69

70 ORDER BY Can Reference Column Position 70


Download ppt "Welcome to CIS 2002: DATABASE DESIGN AND IMPLEMENTATION Semester 1, 2014 – LECTURE 2 7 January 2016 1."

Similar presentations


Ads by Google