Relational Data Model Lu Chaojun, SJTU.

Slides:



Advertisements
Similar presentations
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
Advertisements

Database Design -- Basic SQL
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Representing Data Elements Gayatri Gopalakrishnan.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Basic SQL types String –Char(n): fixed length. Padded –Varchar(n): variable length Number –Integer: 32 bit –Decimal(5,2): –Real, Double: 32 bit,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
1 Relational Data Model CS 157B Nidhi Patel. 2 What is a Data Model? A notation for describing data or information A notation for describing data or information.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
1 The Relational Model Instructor: Mohamed Eltabakh
CG084&085 / / 1 The Relational Data Model Properties of Relations Keys and Constraints.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Ms. Hatoon Al-Sagri CCIS – IS Department SQL-99 :Schema Definition, Constraints, Queries, and Views 1.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
1 CS1368 Introduction* Relational Model, Schemas, SQL Semistructured Model, XML * The slides in this lecture are adapted from slides used in Standford's.
SQL: DDL John Ortiz Cs.utsa.edu.
Lu Chaojun, SJTU Relational Data Model 1. Lu Chaojun, SJTU What’s a Data Model? A notation (collection of conceptual tools) for describing data as seen.
CS 338The Relational Model2-1 The Relational Model Lecture Topics Overview of SQL Underlying relational model Relational database structure SQL DDL and.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
©Silberschatz, Korth and Sudarshan1 Structured Query Language (SQL) Data Definition Language Domains Integrity Constraints.
1 CS 430 Database Theory Winter 2005 Lecture 10: Introduction to SQL.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Databases : SQL-Schema Definition and View 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
1. 2 Design of databases. E/R model (entity-relationship model) Relational model (tables) UML (unified modeling language) Database programming. SQL, Relational.
CPSC 603 Database Systems Lecturer: Laurie Webster II, Ph.D., P.E.
Structured Query Language (SQL) DDL
CPSC-310 Database Systems
COP Introduction to Database Structures
The Relational Model.
COP4710 Database Systems Relational Model.
CS 480: Database Systems Lecture 13 February 13,2013.
Constraints and Triggers
Database Design and Programming
Database Models Relational Model
Instructor: Mohamed Eltabakh
The Relational Model Relational Data Model
Relational Databases The Relational Model.
Relational Databases The Relational Model.
SQL OVERVIEW DEFINING A SCHEMA
2018, Fall Pusan National University Ki-Joune Li
The Relational Model Textbook /7/2018.
Defining a Database Schema
CMPT 354: Database System I
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Instructor: Mohamed Eltabakh
Lectures 2: Introduction to SQL 1
Session - 6 Sequence - 1 SQL: The Structured Query Language:
CMSC-461 Database Management Systems
CE223 Database Systems Introduction
CSC 453 Database Technologies
SQL (Structured Query Language)
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Relational Data Model Lu Chaojun, SJTU

What’s a Data Model? A notation (collection of conceptual tools) for describing data as seen by the user. Structure of data (math representation) Examples: relational model = relations(tables); semistructured model = trees/graphs. Operations on data. Constraints on data. Lu Chaojun, SJTU

Data Model: An Analogy Data Structure Operation Constraint 站得住 不能煮破 18个褶 3 Lu Chaojun, SJTU

Some Data Models Widely used today: Others History: Relational, OR Semistructured Others OO History: Hierarchical Network Lu Chaojun, SJTU

Comparison Relational model is preferred, because of its simple and limited, yet versatile, approach to structuring data limited, yet useful, collection of operations allow implementation of VHL language: SQL ease of use: just state what to do efficiency: optimization possible Semistructured models have more flexibility, but less preferred in DBMS Lu Chaojun, SJTU

Relational Model: Basics Relation = table Attribute = column ( header) tuple = row Reminder: In math, a relation R is a subset of S1× S2 ×… × Sn i.e. R = {(a1, a2,…, an) | ai  Si } Lu Chaojun, SJTU

Relation: an example codename name 007 James Bond 008 Steven Chow Spy Attributes (column headers) codename name 007 James Bond 008 Steven Chow Spy Tuples (rows) Relation name Lu Chaojun, SJTU

Relational Model: Basics(cont.) Relation schema = relation_name(attribute_list) usually not change over time SET of attributes, not a LIST. But take the “list” as standard order. Optionally: types, other structure info Example: Spy(codename,name) Relation instance = current set of tuples change over time Not a list Relational DB schema = set of relation schemas RDB instance Lu Chaojun, SJTU

Table Def. in SQL:2003 A table has an ordered collection of one or more columns and an unordered collection of zero or more rows. Each column has a name and a data type. Each row has, for each column, exactly one value in the data type of that column. Lu Chaojun, SJTU

Relational Model: Basics(cont.) Domains atomic values for each attributes each attribute is associated with a domain (type) E.g. R(A1:D1,A2:D2) Key attribute(s) to distinguish tuples in a relation E.g. R(A1, A2, A3) Semantic constraint Create artificial keys Lu Chaojun, SJTU

Why Relational Model? Very simple model single data-modeling concept: relation Very High-level prog. language: SQL simple yet powerful Design theory mathematically strict Lu Chaojun, SJTU

SQL Standard DB language SQL: DDL + DML Relations in SQL SQL:2003, SQL:2008 SQL: DDL + DML Relations in SQL Stored relation: table View: not stored, constructed when needed Temporary table: constructed by SQL processor SJTU Lu Chaojun Lu Chaojun, SJTU

SQL Data Types Data Types Implicit type coercions CHAR(n), VARCHAR(n), clob BIT(n), BIT VARYING(n), blob BOOLEAN SMALLINT, INT/INTEGER, BIGINT DECIMAL(n,d)/NUMERIC(n,d), FLOAT/REAL, DOUBLE PRECISION TIME WITH/WITHOUT TIME ZONE, TIMESTAMP WITH/WITHOUT TIME ZONE, DATE, INTERVAL Implicit type coercions Lu Chaojun, SJTU

SQL Values Integers and reals: as expected Strings: single quotes! Two single quotes = real quote e.g., ’I’’m Back.’ Any value can be NULL. Date: DATE ’yyyy-mm-dd’ Example: DATE ’2011-01-11’ Time: TIME ’hh:mm:ss’, with optional fractions of a second Example: TIME ’15:30:02.5’ SJTU Lu Chaojun Lu Chaojun, SJTU

SQL:2003 Data Types A data type is a set of representable values. Every data value belongs to some data type. Data type Predefined: specified by ISO/IEC 9075, and provided by the SQL-implementation. Atomic Constructed Composite User-defined Lu Chaojun, SJTU

Defining Relation Schema CREATE TABLE name ( column_1 type_1, ... , column_n type_n ); Most simple table declaration. Lu Chaojun, SJTU

Example CREATE TABLE Student ( sno CHAR(10), name VARCHAR(20), age INTEGER, dept VARCHAR(30) ); Lu Chaojun, SJTU

Drop Table DROP TABLE relation; No longer part of DB schema Tuples also removed Lu Chaojun, SJTU

Modifying Relation Schema ALTER TABLE relation ADD column type | DROP column; ADD: use NULL values as default. Lu Chaojun, SJTU

Default Values CREATE TABLE Student ( sno CHAR(10), name VARCHAR(20), age INT DEFAULT 18, dept VARCHAR(30) DEFAULT ‘CS’ ); Default to NULL, if not designated. Lu Chaojun, SJTU

Declaring Keys An attribute or list of attributes may be declared PRIMARY KEY or UNIQUE. Either says that no two tuples of the relation may agree in all the attribute(s) on the list. There are a few distinctions to be mentioned later. Lu Chaojun, SJTU

Declaring Single-Attribute Keys Place PRIMARY KEY or UNIQUE after the type in the declaration of the attribute. Example: CREATE TABLE Student ( sno CHAR(10) PRIMARY KEY, name VARCHAR(20), age INTEGER, dept VARCHAR(30) ); Lu Chaojun, SJTU

Declaring Multiattribute Keys A key declaration can also be another element in the list of elements of a CREATE TABLE statement. This form is essential if the key consists of more than one attribute. May be used even for one-attribute keys. Lu Chaojun, SJTU

Example: Multiattribute Key The student number and course number together are the key for SC: CREATE TABLE SC ( sno CHAR(10), cno CHAR(5), grade INTEGER, PRIMARY KEY (sno, cno) ); Lu Chaojun, SJTU

PRIMARY KEY vs. UNIQUE There can be only one PRIMARY KEY for a relation, but several UNIQUE attributes. No attribute of a PRIMARY KEY can ever be NULL in any tuple. But attributes declared UNIQUE may have NULL’s. Lu Chaojun, SJTU

End Lu Chaojun, SJTU