SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

Database Systems: Design, Implementation, and Management Tenth Edition
Accounting System Design
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 SQL Group Functions.
1 Introduction to Web Application Introduction to Data Base.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Database – Part 2a Dr. V.T. Raja Oregon State University.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
Michael F. Price College of Business Chapter 6: Logical database design and the relational model.
Database Architecture The Relational Database Model.
Concepts of Database Management, Fifth Edition
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 6 Group Functions. Chapter Objectives  Differentiate between single-row and multiple-row functions  Use the SUM and AVG functions for numeric.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
MIS 385/MBA 664 Systems Implementation with DBMS/ Database Management Dave Salisbury ( )
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Concepts and Terminology Introduction to Database.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
RELATIONSHIPS Generally there are two main database types: flat-file and relational.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
PLUG IT IN 3 Fundamentals of Relational Database Operations.
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta.
SQL 101 for Web Developers 14 November What is a database and why have one? Tables, relationships, normalization SQL – What SQL is and isn’t – CRUD:
Using Special Operators (LIKE and IN)
DataBase Management System What is DBMS Purpose of DBMS Data Abstraction Data Definition Language Data Manipulation Language Data Models Data Keys Relationships.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Relational Theory and Design
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
12/2/2015CPSC , CPSC , Lecture 41 Relational Model.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
Understand Relational Database Management Systems Software Development Fundamentals LESSON 6.1.
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Logical Database Design and the Relational Model.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
Microsoft Access 2010 Chapter 11 Database Design.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 MySQL  DDL ◦ Create ◦ Alter  DML ◦ Insert ◦ Select ◦ Update ◦ Delete  DDL(again) ◦ Drop ◦ Truncate.
Select Complex Queries Database Management Fundamentals LESSON 3.1b.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Lab 13 Databases and SQL.
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Database Systems: Design, Implementation, and Management Tenth Edition
CIS 207 The Relational Database Model
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Relational Model and ER Model: in a Nutshell
SQL LANGUAGE and Relational Data Model TUTORIAL
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
SQL LANGUAGE and Relational Data Model TUTORIAL
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Database systems Lecture 3 – SQL + CRUD
Query Functions.
Presentation transcript:

SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha

Outline  Relational Data Model  Step1 Define the purpose  Step2 Gather data, define constraints  Step3 Create Relationship  Step4 Refine and Normalize the design  SQL Language

Relational Data Model (1)  Relation : Organizing data into collections of two- dimensional table called “Relations”  ERD  Relational Data Model  Database

Relational Data Model (2) S_idname Agegpa Fields (Attributes, Columns) Tuples (Records /Rows )

RD- Step1 Define the purpose  Gather the requirements and define the objective of your database

RD Step2 Gather data, define constraints  Primary Key  Unique and not Null  Simple  Should not change  Often uses Integer  Other constraints  Not null  Positive values

RD - Step3 Create Relationship (1)  Identify the relationships among tables:  One-to-Many  Many-to-Many  One-to-One

RD - Step3 Create Relationship (2)  One-to-Many

RD - Step3 Create Relationship (3)  Many-to-Many

RD - Step3 Create Relationship (4)  One-to-One

RD- Step4 Refine and normalize the design (1)  Normalization  First Normal Form (1NF) A table is 1NF if every cell contains a single value, not a list of values.  Second Normal Form (2NF) A table is 2NF, if it is 1NF and every non-key column is fully dependent on the primary key.  Third Normal Form (3NF) A table is 3NF, if it is 2NF and the non-key columns are independent of each others.

 Entity Integrity Rule  The primary key cannot contain NULL.  Referential Integrity Rule  Each foreign key must be matched to a primary key value in the parent table RD- Step4 Refine and normalize the design (2)

Basic Syntax of SQL Language SELECT attribute name(s) FROM table name WHERE comparison predicate (Boolean expression) GROUP BY attribute name(s) HAVING comparison predicate ORDER BY attribute name(s)

Create Tables

SELECT ALL records

Formula Like & DISTINCT

SELECT specific records with conditions

SQL ORDER BY

SQL UPDATE UPDATE table name SET column1 = value, column2 = value2,… WHERE comparison predicate (Boolean expression)

AVG() - Returns the average value COUNT() - Returns the number of rows FIRST() - Returns the first value LAST() - Returns the last value MAX() - Returns the largest value MIN() - Returns the smallest value SUM() - Returns the sum SQL IN OPERATOR

SQL Alias

SQL Joins  INNER JOIN: Return rows when there is at least one match in both tables  LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table  RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table SELECT column_name(s) FROM table_name1 JOIN_TYPES table_name2 ON table_name1.column_name = table_name2.column_name

SQL INNER JOIN

SQL LEFT JOIN

SQL RIGHT JOIN

SQL GROUP BY Statement

SQL HAVING Clause

PosgreSQL Arrays (1)

PosgreSQL Arrays (2)

PosgreSQL Arrays (3)

PosgreSQL Composite Types