Over the Past 2 weeks we have looked (in brief) at the basic elements of a relational database.  What we understand by the phrase database?  How the.

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
Advertisements

A Brief Introduction to Relational Databases
SQL Basics Based on the relational algebra we just learned. Nonprocedural language – what to be done not how Simple, powerful language Used for both data.
Design process Identify entities and attributes –What do you want to know? –Note that the question of whether something is an attribute or an entity may.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Structured Query Language Part I Chapter Three CIS 218.
Relational Databases.  So far we have looked at retrieving data from multiple tables and the different ways to join the relations/tables that are required.
SQL (Standard Query Language) Yong Choi School of Business CSU, Bakersfield.
Information systems and databases Database information systems Read the textbook: Chapter 2: Information systems and databases FOR MORE INFO...
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Objectives of the Lecture : This weeks lecture will look at how database tables/relations work. Last week we identified how we could identify the possible.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
Relational databases.  Retrieving data from a database requires pulling data from multiple tables  Tables relate to each other in distinct ways, modelled.
Subqueries. So far when data has been filtered the filter has been known and simply added to the Where clause but often you don’t know what the filter.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
Lecture 1 - Introduction Databases & module Emma-Jane Phillips Pandon 122.
Inner Join vs. Outer Join
University of Sunderland COM 220Lecture Two Slide 1 Database Theory.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Deanery of Business & Computer Sciences SQL Structured Query Language Implementation Lecture – 8 Database Technology Level I.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Relational Databases.  In week 1 we looked at the concept of a key, the primary key is a column/attribute that uniquely identifies the rest of the data.
Relational Databases. Objectives of the Lecture : This weeks lecture will look at how database tables/relations work. Last week we identified how we could.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
WDM3304 week 6 Table Joins. Primary keys, foreign keys Primary key: A field of a table designated to provide a unique identifier for a specific row of.
While you are waiting for class to start... (1) Login to SQL Server 2012 Management Studio (2) Execute the file called “SQLLab3.sql”. It is located on.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
SQL Structured Query Language. Aims  To introduce the implementation of a Physical design using SQL.  To introduce SQL Data Definition Language (DDL).
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Structured Query Language
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Relational Databases. SQL Sub-queries: queries within queries  So far when data has been filtered the filter has been known and simply added to the Where.
1 COMP 1100 Basic SQL David J. Stucki. Outline SQL Overview Retrievals Schema creation Table creation Constraints Inserts Updates 2.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
DBM 380 AID Focus Dreams/dbm380aid.com
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
Chapter 5 Introduction to SQL.
COMP3017 Advanced Databases
DBM 380 aid Perfect Education/dbm380aid.com
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
DBM 380 aid Education Begins/dbm380aid.com
Structured Query Language (SQL)
CIS 336 str Competitive Success/snaptutorial.com
CIS 336 str Education for Service- -snaptutorial.com.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
JOINs JOINs can be used to combine tables A CROSS JOIN B
Introduction To Structured Query Language (SQL)
CMPT 354: Database System I
Data Manipulation using Relational Algebra
Yong Choi School of Business CSU, Bakersfield
CSC 453 Database Systems Lecture
A Very Brief Introduction to Relational Databases
Geo-Databases: lecture 3 Simple Queries in SQL
Database SQL.
Manipulating Data Lesson 3.
Presentation transcript:

Over the Past 2 weeks we have looked (in brief) at the basic elements of a relational database.  What we understand by the phrase database?  How the paper system needs to be adapted for computer database system?  How tables/relations are identified and broken down? This understanding will be added to over the course, adding complexity and depth of knowledge. This week we are going to start to look at the use of SQL to extract the data from the database.

 Identify all data elements from the paper-based system.  The raw elements fall initially into 2 clusters (Order & Invoice) but closer examination indicate that additional elements are needed (customer, product, seller etc.)  Order needs to be split into 2 (orderheader & orderline)  Invoice links to order and customer

Orderheader (ordernum, orderdate, deliveryid, fulfilled, custid, ordervalue,....) Orderline (ordernum, orderlinenum, prodid, quantity, linevalue, discount....) product(prodid, desc, price, quantity, sellerid, condition, postage, memo....) Seller(sellerid, name, addr1, addr2, addr3, addpc,....) Customer(custid, firstname, surname, addr1, addr2, addr3, creditlimit...) Etc....

 SQL is the basis of all database programming  As a language SQL is:  Non-procedural  Specify the target, not the mechanism (what not how)  Safe  Negations limited by context  Set-oriented  All operations are on entire sets of tuples  Relationally complete  Has the power of the relational algebra  Functionally incomplete  Does not have the power of a programming language like Java

 Non-procedural  No loops or tests for end of file  Set-oriented  The operation is automatically applied to all the rows in STUDENT  Relationally complete  Restrict, project & join shown in this lecture (all others are available)  Functionally incomplete  Does not matter here if just want information displayed

The basic SQL statement comprises 3 main elements, what you want, where it is found and how it can be filtered. select * from student where major = 'Games';  FROM statement specifies tables to be queried (source/range)  WHERE statement specifies restriction on values to be processed (predicate)  SELECT statement specifies what is to be retrieved (target), * means all columns in this case.

 In your seminar you will run a script that will create the following tables: o Marks o Enrolled o Class o Subject o Student o Staffmember o Department StaffMemberClassSubject Department StudentEnrolled Marks

If we want a list of staff names in the database we determine the table that holds that data and retrieve the data from that table. Select * select name From staffmember;from staffmember; STAFFID NAME DEPTID Glen Maxwell Esme Lettitia Bertie Wooster Andrew Turnbull Mark Hurrell; Akhtar Ali Ben Wightman Tim Rose Gareth Price Neil Thompson Paul Samson Grant Smith John Tait Gareth Phillips Emma-Jane Phillips 4 NAME Glen Maxwell Esme Lettitia Bertie Wooster Andrew Turnbull Mark Hurrell; Akhtar Ali Ben Wightman Tim Rose Gareth Price Neil Thompson Paul Samson Grant Smith John Tait Gareth Phillips Emma-Jane Phillips

1) Identify the tables/relation which hold the information you need understand your system and the ERD 2) Determine the attributes of the table/relation that are required do not default to select * 3) Is all the data held in one table/relation? 1) If multiple relations required identify the related elements for each relation. Range of joining tables select appropriate method.

Identify the names of students who are enrolled on the course COMP What tables/relations do we need? Enrolled & student??? 2. Is there a relationship between these relations? yes through studentid 3. Which attributes do you need? only name select stuname from student, enrolled where subjectid = 'COMP2031' and student.studentid = enrolled.studentid; COMP2031 STUNAME Jim Smith Jack Smith Tom Jones Isacc Thomas Glenda Williamson John Smith Grant Smith Charlie Brown Carl Smith Karl Brown David Jones Warrick Brown

 There are more effective ways of pulling data from multiple tables/relations but initially we are going to force the join in the where clause  Attributes that are shared between relations/tables must be of the same datatype and have the same meaning but do not need the same attribute name staffmemberdepartment Name Null? Type STAFFID NOT NULL NUMBER(6) NAME VARCHAR2(20) DEPTID NUMBER(5) Name Null? Type DEPTID NOT NULL NUMBER(5) DNAME VARCHAR2(25)

Department table DEPTID DNAME Staffmember table STAFFID NAME DEPTID The attribute that relates staffmember and department is deptid Write SQL to list the names of the staff and the name of the department they work with. select name, dname from staffmember, department where staffmember.deptid = department.deptid; StaffMemberClassSubject Department StudentEnrolled Marks