SQL LANGUAGE and Relational Data Model TUTORIAL

Slides:



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

The Hierarchical Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Introduction to Structured Query Language (SQL)
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Introduction to Structured Query Language (SQL)
SQL Tutorials To understand some of the topics please analyze the following tutorials: The following tutorials will help:
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Chapter 4 The Relational Model.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
2440: 141 Web Site Administration Database Management Using SQL Professor: Enoch E. Damson.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
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)
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Dr Gordon Russell, Napier University Unit SQL 1 1 SQL 1 Unit 1.2.
Jennifer Widom Relational Databases The Relational Model.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Web Database Programming Using PHP
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
Chapter 5 Introduction to SQL.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Relational Database Design
Insert, Update and the rest…
 2012 Pearson Education, Inc. All rights reserved.
© The McGraw-Hill Companies, All Rights Reserved APPENDIX C DESIGNING DATABASES APPENDIX C DESIGNING DATABASES.
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
ATS Application Programming: Java Programming
Web Database Programming Using PHP
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.
CSCI-100 Introduction to Computing
Databases and Information Management
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
SQL Tutorial.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Chapter 8 Working with Databases and MySQL
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Database.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
SQL LANGUAGE and Relational Data Model TUTORIAL
“Manipulating Data” Lecture 6.
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
CS122 Using Relational Databases and SQL
“Manipulating Data” Lecture 6.
Databases and Information Management
SQL-1 Week 8-9.
Chapter 4 The Relational Model Pearson Education © 2009.
Spreadsheets, Modelling & Databases
Relational Database Design
logical design for relational database
Chapter 4 The Relational Model Pearson Education © 2009.
SQL: Structured Query Language
SQL: Structured Query Language
CS122 Using Relational Databases and SQL
The University of Akron College of Applied Science & Technology Dept
Information system analysis and design
Presentation transcript:

SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Sheng Guan

Outline Relational Data Model SQL Language Step1 Define the purpose Step2 Gather data, define constraints Step3 Create Relationship SQL Language http://www3.ntu.edu.sg/home/ehchua/programming/sql/relational_database_design.html

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

Relational Data Model (2) Fields (Attributes, Columns) S_id name Email Age gpa 5000 Dave Dave@cs 19 3.3 53666 Jones Jone@cs 18 3.4 53888 Smith Smith@cs 3.2 Tuples (Records /Rows )

RD- Step1 Define the purpose Gather the requirements and define the objective of your database Drafting out the sample input forms, queries and reports, often helps.

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 The column teacherID in the child table Classes is known as the foreign key. A foreign key of a child table is a primary key of a parent table, used to reference the parent table. Take note that for every value in the parent table, there could be zero, one, or more rows in the child table. For every value in the child table, there is one and only one row in the parent table.

RD - Step3 Create Relationship (3) Many-to-Many The many-to-many relationship is, in fact, implemented as two one-to-many relationships, with the introduction of the junction table. - An order has many items in OrderDetails. An OrderDetails item belongs to one particular order. - A product may appears in many OrderDetails. Each OrderDetails item specified one product.

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

Basic Syntax of SQL Language CREATE Tables INSERT into Tables Update Tables SQL (Structured Query Language) is a computer language aimed to store, manipulate, and query data stored in relational databases HAVING is used when you are using an aggregate such as GROUP BY. It is used to check conditions after the aggregation takes place. WHERE is used before the aggregation takes place. Select

Create Tables Note that all data types use rather obvious input formats. Constants that are not simple numeric values must usually be surrounded by single quotes ('), as in the example. The date column is actually quite flexible in what it accepts, but for this tutorial we will stick to the format shown here. The syntax used so far requires you to remember the order of the columns. An alternative syntax allows you to list the columns explicitly: You can list the columns in a different order if you wish or you can even omit some columns, for example, if the precipitation is unknown: Many developers consider explicitly listing the columns better style than relying on the order implicitly.

INSERT into Tables Note that all data types use rather obvious input formats. Constants that are not simple numeric values must usually be surrounded by single quotes ('), as in the example. The date column is actually quite flexible in what it accepts, but for this tutorial we will stick to the format shown here. The syntax used so far requires you to remember the order of the columns. An alternative syntax allows you to list the columns explicitly: You can list the columns in a different order if you wish or you can even omit some columns, for example, if the precipitation is unknown: Many developers consider explicitly listing the columns better style than relying on the order implicitly.

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

SELECT ALL records SQL is not case sensitive. SELECT is the same as select. Tip: The asterisk (*) is a quick way of selecting all columns!

Formula Like & DISTINCT The LIKE operator is used to search for a specified pattern in a column. The "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern. It is also possible to select the city that does NOT contain the pattern “Sa" from the “weather" table, by using the NOT keyword. SELECT * FROM Persons WHERE City NOT LIKE '%tav%‘ % => A substitute for zero or more characters _ => A substitute for exactly one character

SELECT specific records with conditions