Database Systems  DBMS Fundamental Concepts. Table of Contents 1. Database Models 2. Relational Database Model 3. DBMS & RDBMS Systems 4. Tables, Relationships,

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

Fundamental Concepts Svetlin Nakov Telerik Corporation
By RUPESH KUMAR.  Database? Types? Abstraction?  Database Models?  Database Integrity?  ACID?  RDBMS?  Normalization?  Data Warehouse?  Database.
Management Information Systems, Sixth Edition
Accounting System Design
1 Basic DB Terms Data: Meaningful facts, text, graphics, images, sound, video segments –A collection of individual responses from a marketing research.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
CSE 190: Internet E-Commerce Lecture 10: Data Tier.
3-1 Chapter 3 Data and Knowledge Management
Chapter 11 Data Management Layer Design
Chapter 4: Database Management. Databases Before the Use of Computers Data kept in books, ledgers, card files, folders, and file cabinets Long response.
Introduction to Structured Query Language (SQL)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
IST Databases and DBMSs Todd S. Bacastow January 2005.
Database Lecture # 1 By Ubaid Ullah.
ASP.NET Programming with C# and SQL Server First Edition
Module Title? DBMS Introduction to Database Management System.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
Introduction to Database Systems
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
NoSQL Databases NoSQL Concepts SoftUni Team Technical Trainers Software University
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Relational Database. Database Management System (DBMS)
DBMS Fundamental Concepts Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
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.
Chapter 9 Database Systems Introduction to CS 1 st Semester, 2014 Sanghyun Park.
Telerik Software Academy Telerik School Academy DBMS Fundamental Concepts.
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.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
RDBMS and SQL Saras M Srivastva PGT (Comp. Sc) Kendriya Vidyalaya Tenga Valley, Dist. Kameng (W) Arunachal Pradesh –
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Chapter 3: Relational Databases
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
SQL Basics Review Reviewing what we’ve learned so far…….
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Introduction to Database Programming with Python Gary Stewart
Big Data Yuan Xue CS 292 Special topics on.
Data Resource Management Data Concepts Database Management Types of Databases Chapter 5 McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies,
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Fundamentals of DBMS Notes-1.
NoSQL Databases NoSQL Concepts Databases Telerik Software Academy
Chapter 2 Database Environment.
Accounting System Design
Teaching slides Chapter 8.
Accounting System Design
Understanding Core Database Concepts
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:

Database Systems  DBMS Fundamental Concepts

Table of Contents 1. Database Models 2. Relational Database Model 3. DBMS & RDBMS Systems 4. Tables, Relationships, Multiplicity, E/R Diagrams 5. Normalization 6. Constraints 7. Indices 8. The SQL language 2

Table of Contents (2) 9. Stored Procedures 10. Views 11. Triggers 12. Transactions and Isolation Levels 13. NoSQL Databases 3

RDBMS Systems Relational Databases, Database Servers and RDBMS

Relational Databases  Database models  Hierarchical (tree)  Network / graph  Relational (tables)  Object-oriented  Relational databases  Represent a bunch of tables together with the relationships between them  Rely on a strong mathematical foundation: the relational algebra 5

Relational Database Management System  Relational Database Management Systems (RDBMS) manage data stored in tables  RDBMS systems typically implement  Creating / altering / deleting tables and relationships between them (database schema)  Adding, changing, deleting, searching and retrieving of data ows stored in the tables  Support for the SQL language  Transaction management (optional) 6

RDBMS Systems  RDBMS systems are also known as:  Database management servers  Or just database servers  Popular RDBMS servers:  Microsoft SQL Server  Oracle Database  MySQL  PostgreSQL  SQLite 7

Tables and Relationships Database Tables, Relationships, Multiplicity

Tables  Database tables consist of data, arranged in rows and columns  For example (table Persons ):  All rows have the same structure  Columns have name and type (number, string, date, image, …) IdFirst NameLast NameEmployer 1SvetlozarMirovVMWare 2HristoTenchevXS Software 3VladimirGeorgievHuawei

Table Schema  The schema of a table is an ordered sequence of column specifications (name and type)  For example the Persons table has the following schema: 10 Persons ( Id: number, Id: number, FirstName: string, FirstName: string, LastName: string, LastName: string, Employer: string Employer: string)

 Primary key is a column of the table that uniquely identifies its rows (usually its is a number)  Two records (rows) are different if and only if their primary keys are different  Composite primary key – composed by several columns 11 IdFirst NameLast NameEmployer 1SvetlinNakovSoftUni 2HristoTenchevXS Software 3VladimirGeorgievSoftUni Primary key

Relationships  Relationships between tables are based on interconnections: primary key / foreign key 12 Towns Countries IdNameCountryId 1Sofia1 2Varna1 3Munich2 4Berlin2 5Moscow3 IdName 1Bulgaria 2Germany 3Russia Primary Key Foreign Key

Relationships (2)  The foreign key is an identifier of a record located in another table (usually its primary key)  By using relationships we avoid repeating data in the database  In the last example the name of the country is not repeated for each town (its number is used instead)  Relationships have multiplicity:  One-to-many – e.g. country / towns  Many-to-many – e.g. student / course  One-to-one – e.g. example human / student 13

Relationships' Multiplicity – One-To-Many  Relationship one-to-many (or many-to-one) – used often  A single record in the first table has many corresponding records in the second table 14 Towns Countries IdNameCountryId 1Sofia1 2Varna1 3Munich2 4Berlin2 5Moscow3 IdName 1Bulgaria 2Germany 3Russia

Relationships' Multiplicity – Many-To- Many  Relationship many-to-many  Records in the first table have many corresponding records in the second one and vice versa  Implemented through additional table 15 Students Courses StudentsCourses IdName 1Pesho 2Minka 3Gosho 4Jivka StudentIdCourseId IdName 1.NET 2Databases 3JavaScript

Relationships' Multiplicity – One-To-One  Relationship one-to-one  A single record in a table corresponds to a single record in the other table  Used to model inheritance between tables 16 Persons Students Professors IdNameAge 1Baba Mara67 2Stancho33 3Bay Gosho45 IdTitle 1Ph.D. IdSpecialty 2Computer Science 3Chemistry Primary & foreign key Primary Key

Representing Hierarchical Data  How do we represent trees and graphs? 17 Root Document s Pictures Birthday Party

Self-Relationships  The primary / foreign key relationships can point to one and the same table  Example: folders hold sub-folders 18 Folders Self- Relationship IdFolderParentId 1RootNULL 2Documents1 3Pictures1 4Birthday Party3 Foreign Key Primary Key

E/R Diagrams Entity / Relationship Diagrams and DB Modeling Tools

Relational Schema  Relational schema of a DB is the collection of:  The schemas of all tables  Relationships between the tables  Any other database objects (e.g. constraints)  The relational schema describes the structure of the database  Doesn't contain data, but metadata  Relational schemas are graphically displayed in Entity / Relationship diagrams (E/R Diagrams) 20

E/R Diagrams – Examples 21 The diagram is created with Microsoft SQL Server Management Studio

E/R Diagrams – Examples (2) 22 The diagram is created with ERwin

E/R Diagrams – Examples (3) 23 The diagram is created with fabFORCE DB Designer for MySQL

E/R Diagrams – Examples (4) 24 The diagram is created with MS Visio

Tools for E/R Design  Data modeling tools allow building E/R diagrams, generate / import DB schemas:  SQL Server Management Studio  MySQL Workbench  Oracle JDeveloper  Microsoft Visio  CASE Studio  Computer Associates ERwin  IBM Rational Rose 25

DB Normalization Avoiding Duplicated Data through Database Schema Normalization

Normalization  Normalization of the relational schema removes repeating data  Non-normalized schemas can contain many repeated data, e.g. 27 ProductProducerPriceCategoryShopTown yoghurtMlexis Ltd.0.67foodstore "Mente"Sofia bread "Dobrudja" Bakery "Smoky"0.85foodstore "Mente"Sofia beer "Zagorka"Zagorka Corp.0.68soft drinksstall "non- stop" Varna beer "Tuborg"Shoumen Drinks Corp. 0.87soft drinksstall "non- stop" Varna

Normalization (2)  1 -st Normal Form  Data is stored in tables  Fields in the rows are atomic (inseparable) values  There are no repetitions within a single row  A primary key is defined for each table 28 BookTitleISBN (PK)AuthorAuthor .NET Framework Mr. Beginning SQL Santa

Normalization (3)  2 -nd Normal Form  Retains all requirements of 1 -st Normal Form  There are no columns that do not depend on part of the primary key (if it consists of several columns) 29 BookTitle (PK)Author (PK)PriceAuthor .NET Framework Mr. Beginning SQLSanta The price depends on the book depends on the author

Normalization (4)  3 -rd Normal Form  Retains all requirements of 2 -nd Normal Form  The only dependencies between columns are of type "a column depends on the PK" 30 IdProductProducer Id PriceCategoryI d ShopI d TownI d 1yoghourt bread "Tipov" rakiya "Biserna" beer "Tuborg"

Normalization (5)  4-th Normal Form  Retains all requirements of 3-rd Normal Form  There is one column at most in each table that can have many possible values for a single key (multi-valued attribute) 31 IdBookArticle 2.NET ProgrammingRegular Expressions 4Mastering JavaScript AJAX Performance Patterns One author can have many books One author can have many articles

Normalization (6)  Example of fully normalized schema (in 4 th Normal Form): 32 Products Producers Categories Shops Towns IdProductProducerI d Pric e CategoryI d ShopIdTownI d 1Youghurt bread "Dobrudja" rakia "Peshtera" beer "Tuborg" IdName 2"Milk" Ltd. 4"Zagorka" AD IdName 4beer 2food IdName 1Billa 4METRO IdName 1Sofia 3Varna

Other Database Objects Constraints, Indices, SQL, Stored Procedures, Views, Triggers

Integrity Constraints  Integrity constraints ensure data integrity in the database tables  Enforce data rules which cannot be violated  Primary key constraint  Ensures that the primary key of a table has unique value for each table row  Unique key constraint  Ensures that all values in a certain column (or a group of columns) are unique 34

Integrity Constraints (2)  Foreign key constraint  Ensures that the value in given column is a key from another table  Check constraint  Ensures that values in a certain column meet some predefined condition  Examples: 35 (hour >= 0) AND (hour = 0) AND (hour < 24) name = UPPER(name)

Indices  Indices speed up searching of values in a certain column or group of columns  Usually implemented as B-trees  Indices can be built-in the table (clustered) or stored externally (non- clustered)  Adding and deleting records in indexed tables is slower!  Indices should be used for big tables only (e.g rows) 36

The SQL Language  SQL (Structured Query Language)  Standardized declarative language for manipulation of relational databases  SQL-2011 is currently in use in most databases  ion ion  SQL language supports:  Creating, altering, deleting tables and other DB objects  Searching, retrieving, inserting, modifying and deleting table data (rows) 37

The SQL Language (2)  SQL consists of:  DDL – Data Definition Language  CREATE, ALTER, DROP commands  DML – Data Manipulation Language  SELECT, INSERT, UPDATE, DELETE commands  Example of SQL SELECT query: 38 SELECT Towns.Name, Countries.Name FROM Towns, Countries WHERE Towns.CountryId = Countries.Id

Stored Procedures  Stored procedures (database-level procedures)  Consist of SQL-like code stored in the database  Code executed inside the database server  Much faster than an external code  Data is locally accessible  Can accept parameters  Can return results  Single value  Record sets 39

Stored Procedures (2)  Stored procedures are written in a language extension of SQL  T-SQL – in Microsoft SQL Server  PL/SQL – in Oracle  Example of stored procedure in Oracle PL/SQL: 40 CREATE OR REPLACE PROCEDURE spInsertCountry(countryName varchar2) IS BEGIN INSERT INTO Countries(Name) INSERT INTO Countries(Name) VALUES(countryName); VALUES(countryName);END;

Views  Views are named SQL SELECT queries which are used as tables  Simplify data access  Facilitate writing of complex SQL queries  Used also to apply security restrictions:  E.g. a certain user isn't given permissions on any of the tables in the database  The user is given permissions on few views (subset of DB) and few stored procedures only 41

Views – Example 42 Companies Towns Countries IdCompanyTownI d 1Mente LTD1 2BulkSoft Inc.2 3HardSoft Corp. 4 4Sputnik Corp.3 IdTownCountyI d 1Sofia1 2New York3 3Moscow2 4Plovdiv1 IdCountry 1Bulgaria 2Russia 3USA

Views – Example (2) 43 CREATE VIEW V_BGCompanies AS SELECT SELECT Companies.Id AS Id, Companies.Id AS Id, Companies.Company AS Company Companies.Company AS Company FROM Companies INNER JOIN FROM Companies INNER JOIN (Towns INNER JOIN Countries ON (Towns INNER JOIN Countries ON Towns.CountryId = Countries.Id) Towns.CountryId = Countries.Id) ON Companies.TownId = Towns.Id ON Companies.TownId = Towns.Id WHERE WHERE Countries.Country = "Bulgaria"; Countries.Country = "Bulgaria"; V_BGCompanies IdCompany 1Mente Ltd. 3HardSoft Corp.

Triggers  Triggers are special stored procedures that are activate when some event occurs, for instance:  When inserting a record  When changing a record  When deleting a record  Triggers can perform additional data processing, e.g.  To change the newly added data  To maintain logs and history on change 44

Triggers – Example  We have a table holding company names:  A trigger that appends "Ltd." at the end of the name of a new company: 45 CREATE TABLE Companies( Id number NOT NULL, Id number NOT NULL, Name varchar(50) NOT NULL) Name varchar(50) NOT NULL) CREATE OR REPLACE TRIGGER trg_Companies_INSERT BEFORE INSERT ON Company BEFORE INSERT ON Company FOR EACH ROW FOR EACH ROWBEGIN :NEW.Name := :NEW.Name || ' Ltd.'; :NEW.Name := :NEW.Name || ' Ltd.';END;

Transactions ACID Transactions and Isolation

Transactions  Transactions are a sequence of database operations which are executed as a single unit:  Either all of them execute successfully  Or none of them is executed at all  Example:  A bank transfer from one account into another (withdrawal + deposit)  If either the withdrawal or the deposit fails the entire operation should be cancelled 47

Rollback Commit DB Transactions Lifecycle 48 Read Write Write Durable starting state Durable,consistent, ending state Sequence of reads and writes

Transactions Behavior  Transactions guarantee the consistency and the integrity of the database  All changes in a transaction are temporary  Changes become final when COMMIT is successfully executed  At any time all changes done in the transaction can be canceled by executing ROLLBACK  All operations are executed as a single unit  Either all of them pass or none of them 49

NoSQL Databases Non-Relational Database Systems

Non-Relational Data Models  Document model (e.g. MongoDB, CouchDB)MongoDBCouchDB  Set of documents, e.g. JSON strings  Key-value model (e.g. Redis)Redis  Set of key-value pairs  Wide-column model (e.g. Cassandra)Cassandra  Key-value model with schema  Object model (e.g. Caché)Caché  Set of OOP-style objects 51

What is NoSQL Database?  NoSQL (non-relational) databases  Use document-based model (non-relational)  Schema-free document storage  Still support CRUD operations (create, read, update, delete)  Still support indexing and querying  Still supports concurrency and transactions  Highly optimized for append / retrieve  Great performance and scalability  NoSQL == “No SQL” or “Not Only SQL”? 52

Relational vs. NoSQL Databases  Relational databases  Data stored as table rows  Relationships between related rows  Single entity spans multiple tables  RDBMS systems are very mature, rock solid  NoSQL databases  Data stored as documents  Single entity (document) is a single record  Documents do not have a fixed structure 53

Relational vs. NoSQL Models 54 Name: Svetlin Nakov Gender: male Phone: Address: - Street: Tintyava Post Code: Town: Sofia - Country: Bulgaria Site: Document Model Relational Model Name Svetlin Nakov Gendermale Phone Site m CountryBulgaria Street Tintyava Post Code 1113 TownSofia * 1 * 1 * 1

NoSQL Database Systems  Redis  Ultra-fast in-memory data structures server  MongoDB  Mature and powerful JSON-document database  CouchDB  JSON-based document database with REST API  Cassandra  Distributed wide-column database  DB Ranking:

Summary / Questions  What is relational database?  Examples of RDBMS?  What is E/R data model?  What is primary key?  What relationships do you know?  What is constraint?  What is transaction?  What is NoSQL database?  Examples? 56