Introduction to Relational Databases

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

Concepts of Database Management Sixth Edition
Database Systems: Design, Implementation, and Management Tenth Edition
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
Introduction to Structured Query Language (SQL)
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
ASP.NET Programming with C# and SQL Server First Edition
Chapter 3 Single-Table Queries
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Concepts and Terminology Introduction to Database.
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University 1 Basic SQL Statements Oracle/SQL Plus Commands Kroenke, 11 th ed., Chapter Two.
Concepts of Database Management Seventh Edition
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
1 Ch. 1: Sharing Knowledge and Success  Oracle is an Object-Relational Database (ORDBMS).  RDBMS allows you to put the data in, keep the data, get it.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Query Processing – Implementing Set Operations and Joins Chap. 19.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 CONACT UC:  Magnific training   
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Fundamentals of DBMS Notes-1.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Retrieving Data Using the SQL SELECT Statement
Chapter 3 Introduction to SQL(2)
Top 50 SQL Interview Questions & Answers
Relational Database Design
Writing Basic SQL SELECT Statements
SQL and SQL*Plus Interaction
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
Database Systems: Design, Implementation, and Management Tenth Edition
Using the Set Operators
Translation of ER-diagram into Relational Schema
ORACLE SQL Developer & SQLPLUS Statements
MANAGING DATA RESOURCES
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Chapter 7 Introduction to Structured Query Language (SQL)
Databases and Information Management
Contents Preface I Introduction Lesson Objectives I-2
Relational Database Design
Chapter 8 Advanced SQL.
Using SQL*Plus.
CSC 453 Database Systems Lecture
Database Systems: Design, Implementation, and Management Tenth Edition
Using the Set Operators
Database Systems: Design, Implementation, and Management
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Introduction to Relational Databases Department of Computer and Information Science, School of Science, IUPUI Fall 2003 Introduction to Relational Databases Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu 11/23/2018

Sharing Knowledge and Success Oracle is a relational database management system (RDBMS). RDBMSs allow users to... put data in keep/manage the data get data out and work with it

Sharing Knowledge and Success The Language of Oracle: SQL Structured Query Language, English like query language keywords: select, from, where, and order by Example query: select city, temperature from weather where temperature > 80 order by temperature; Examples of relational databases stock tables in newspaper sports scores 100 year example in book

Database Management Disadvantages of traditional file processing systems… uncontrolled redundancy inconsistent data inflexibility limited data sharing poor enforcement of standards low programmer productivity excessive program maintencance from Database Management, McFadden and Hoffer, pp. 8-14

Database Management: Data Models Hierarchical Data Model (IMS) nested sets of 1:1 or 1:M relationships Network Data Model (IDMS, TOTAL) multiple sets of 1:1, 1:M, M:1, or M:N relationships Relational Data Model (Oracle, SQL Server, DB2) relationships are NOT physically implemented uses primary keys to represent associations terminology: relations (tables), columns, tuples (rows), domain, degree, cardinality, primary keys, concatenated keys, alternate keys, foreign keys, Referential Integrity or R.I. relational algebra, three main operators: select, project, join normalization theory:1NF, 2NF, 3NF

Database Management: Normalization First Normal Form (1NF) Each column contains values about the same attribute, and each table cell value must be a single value. Each column has a distince name, order of columns is immaterial. Each row is distinct, rows cannot be duplicate for the same key The sequence of rows is immaterial. Second Normal Form (2NF) All non-key attributes must be fully dependent on the whole key. Third Normal Form (3NF) Each nonkey attribute should be dependent only on the relation’s key, not on any other nonkey.

The Dangers in a Relational Database It looks very easy to use a RDBMS learning about normalization, SQL, etc. make for instant “experts.” lack of experience with major production systems can create catastrophic project failures. Testing cycles are getting shorter newer development tools make software development quicker, usually systems testing gets shortened. Recent college grads... least experienced developers usually have more training with relational database technology. veteran developers are busy with older projects.

The Dangers in a Relational Database How to reduce the confusion… Normalization 1NF: 2NF: 3NF: English names for tables and columns, English code names

The Dangers in a Relational Database

The Dangers in a Relational Database Bad Examples of Table and Column Names: Tables DEPT EMP EMPS MYEMPS PE PROJ TITLES PERSONNEL Columns AD1 AU_LNAME AU_ORD BLOC CDLEXP DEPTNO DNAME DISCOUNTTYPE EMPNO ENAME ENUMBER ESAL HIGHQTY HIRANGE LORANGE LOWQTY NOTE ORD_NUM PNAME PROJNO PUBDATE QTYOH SLSTAXPCT WORKHRS Reasons abbreviation used without good reason inconsistent abbreviations, underlines, and use of plurals purpose not apparent from name name rules have limitations

Chapter 2: The Dangers in a Relational Database Use English Name for Data: Poor Example: Better Example:

The Basic Parts of Speech in SQL SQL is a language. Oracle7 SQL is a superset of the American National Standards Institute (ANSI) and the International Standards Organization (ISO) SQL92 standard at entry level conformance. PL/SQL is Oracle’s procedural language extension to SQL. It allows you to link several SQL commands through procedural language. SQL*Plus (SQLPLUS from command line) is a tool that allows users to interact with Oracle. SQL*Plus enables you to manipulate SQL commands and PL/SQL blocks, and to perform many additional tasks as well. Through SQL*Plus, you can: enter, edit, store, retrieve, and run SQL commands and PL/SQL blocks format, perform calculations on, store, and print query results in the form of reports list column definitions for any table access and copy data between SQL databases send messages to and accept responses from an end user

The Basic Parts of Speech in SQL SQL*Plus,… very quick overview first, create/run a script to start an Oracle database instance from the command line: sqlplus SQL> Common commands in SQL*Plus: get <filename> @<filename> save <filename> list or l change or c edit save ! (shell to OS) Capitalization generally doen’t matter

Relational Algebra: The Basic Parts of Speech in SQL manipulates 1 or 2 relations (tables) and returns 1 new relation as a result. basic relational algebra operators are SELECT, PROJECT and JOIN. SELECT returns a horizontal subset of a relation. PROJECT returns a vertical subset of a relation JOIN returns the combination of 2 relations based on common attributes. from Database Management, McFadden and Hoffer, pp. 214-216

Select, Project, Select and Project The Basic Parts of Speech in SQL Select, Project, Select and Project Join

Simple Select Examples The Basic Parts of Speech in SQL Simple Select Examples Select statement, single table query, all rows: SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE FROM CUSTOMER ORDER BY CUSTOMER_NUMBER; ... specific rows (where clause): WHERE CUSTOMER_NUMBER > 500; ... with a calculation: SELECT CUSTOMER_NUMBER, LAST, (CREDIT_LIM - BALANCE) ... multiple where conditions (and): WHERE BALANCE >= 500 AND BALANCE <= 1000;

The Basic Parts of Speech in SQL The SELECT clause: can be a list of columns, an asterik * for all columns, a calculation (or other expressions), group functions (chapter 9), distinct keyword -- removes duplicates. SELECT DISTINCT SUPPLIER FROM PRODUCTS; column names can be renamed in the output with an alias. SELECT CUSTOMER_NUMBER, LAST, FIRST, (CREDIT_LIM - BALANCE) AS REMAINING_CREDIT FROM CUSTOMER; The FROM clause: in single tables queries, just provide your table’s name …. more on this in multi-table queries.

Chapter 3: The Basic Parts of Speech in SQL The WHERE Clause: this is a logical, boolean expression which must evalute to true for each row in the query’s output. where clause comparison operators: = equal to <, > less than, greater than <=, >= less than or equal, greater than or equal <>, != , ^= not equal compound conditions are built with the boolean operators AND, OR. AND is evaluated first by default. Use parenthesis ( ) to force the order of OR/AND. a compliment of a condition can be evaluated with NOT. Examples below are equivalent: SELECT PART_DESCRIPTION FROM PART WHERE WAREHOUSE_NUMBER != ‘3’; SELECT PART_DESCRIPTION FROM PART WHERE NOT (WAREHOUSE_NUMBER=‘3’);

The Basic Parts of Speech in SQL The WHERE Clause (continued): BETWEEN keyword is the same as >= and =<. For example, these 2 statements are the same: SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE FROM CUSTOMER WHERE BALANCE >= 500 AND BALANCE <= 1000; SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE WHERE BALANCE BETWEEN 500 AND 1000; LIKE keyword is used for pattern matching. ‘%’ is for any number of characters. ‘_’ (underscore) is for one character. SELECT CUSTOMER_NUMBER, LAST, FIRST FROM CUSTOMER WHERE LAST LIKE ‘JONE%’; FROM CUSTOMER WHERE LAST LIKE ‘JONE_’;

The Basic Parts of Speech in SQL The WHERE Clause (continued): IN keyword provides a list of numbers or strings to compare to. This is similar to using OR with =. For example, these 2 statements are the same: SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE FROM CUSTOMER WHERE CUSTOMER_NUMBER IN (10, 11, 12); SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE WHERE (CUSTOMER_NUMBER = 10) OR (CUSTOMER_NUMBER = 11) OR (CUSTOMER_NUMBER = 12); NULL and NOT NULL keywords: NULL does not mean 0, null means no value! Example- this statement only gets customers whom we have a complete name for: SELECT CUSTOMER_NUMBER, LAST, FIRST FROM CUSTOMER WHERE (FIRST IS NOT NULL) AND (LAST IS NOT NULL);

The Basic Parts of Speech in SQL The WHERE Clause (continued): Values can also be compared to another query in the where clause. This is called a subquery. For example: SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE FROM CUSTOMER WHERE CUSTOMER_NUMBER IN (SELECT CUSTOMER_NUMBER FROM CUSTOMER WHERE BALANCE > 500); This however may not work sometimes with a subquery: SELECT CUSTOMER_NUMBER, LAST, FIRST, BALANCE WHERE CUSTOMER_NUMBER = (SELECT CUSTOMER_NUMBER FROM CUSTOMER WHERE BALANCE > 500); because subqueries return sets of values, not a single value.

The Basic Parts of Speech in SQL The WHERE Clause (continued): Tables can be joined by common attributes. This is done in the where clause. SELECT WEATHER.CITY, CONDITION, TEMPERATURE, LATITUDE,. . . FROM WEATHER, LOCATION WHERE WEATHER.CITY = LOCATION.CITY; A shortcut (not in book). Tablenames can be aliased to save typing, reduce wordiness. SELECT W.CITY, CONDITION, TEMPERATURE, LATITUDE,. . . FROM WEATHER W, LOCATION L WHERE W.CITY = L.CITY; Joining data from different tables is one of the more powerful parts of SQL. It is not without its dangers. Joining tables the wrong way (not on common attributes), the wrong data comes back. Forgetting to specify common keys in the where clause returns a “cartesian product” (each row of both tables joined to each other, m times n rows)

The Basic Parts of Speech in SQL The ORDER BY Clause: Specifies the ordering of the returned data. Multiple columns can be selected to sort on. ASC is ascending order order, default. DESC is descending sort order. SELECT FEATURE, SECTION, PAGE FROM NEWSPAPER WHERE SECTION = ‘F’ ORDER BY PAGE DESC, FEATURE ASC; Views: Makes a query act similar to a table. Views are “describe”-able, “select”-able The view’s select statement is ran everytime rows are selected from the view--ie data is not saved somewhere (like a table) CREATE VIEW INVASION AS SELECT W.CITY, CONDITION, TEMPERATURE, LATITUDE FROM WEATHER W, LOCATION L WHERE W.CITY = L.CITY;

Acknowledgements These slides were originally prepared by Tony Teal as part of the IUPUI’s N311 Advanced Database Programming course. 11/23/2018