Telerik Software Academy Telerik School Academy DBMS Fundamental Concepts.

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

Fundamental Concepts Svetlin Nakov Telerik Corporation
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
C# Fundamentals – Part I
Welcome to the JSON-stores world Telerik Software Academy Databases.
NoSQL Concepts, Redis, MongoDB, CouchDB
Telerik Software Academy Telerik School Academy Creating E/R Diagrams with SQL Server.
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Transaction Management and Concurrency Control Telerik Software Academy Databases.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Svetlin Nakov Telerik Software Academy Manager Technical Training
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Accessing SQL Server and MySQL – Live Demo Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Processing Matrices and Multidimensional Tables Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Creating E/R Diagrams with SQL Server Management Studio and MySQL Workbench Svetlin Nakov Telerik Software Academy Manager Technical.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Loops, Conditional Statements, Functions Tran Anh Tuan Edit from Telerik Academy
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Course Introduction Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer
What is a Database, MySQL Specifics Trần Anh Tuấn Edit from Telerik Software Academy
NoSQL Databases NoSQL Concepts SoftUni Team Technical Trainers Software University
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
ORM Concepts, Entity Framework (EF), DbContext
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
DBMS Fundamental Concepts Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
Creating and Running Your First C# Program Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Course Overview Doncho Minkov Telerik Software Academy Technical Trainer
The past, the present, the future Learning & Development Team Telerik Software Academy.
Learn to Design Error Steady Code Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Building Rock-Solid Software Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Inheritance, Abstraction, Encapsulation, Polymorphism Telerik Software Academy Mobile apps for iPhone & iPad.
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
Database Systems  DBMS Fundamental Concepts. Table of Contents 1. Database Models 2. Relational Database Model 3. DBMS & RDBMS Systems 4. Tables, Relationships,
What why and how? Telerik School Academy Unity 2D Game Development.
Windows Security Model Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
NoSQL Databases NoSQL Concepts Databases Telerik Software Academy
Presentation transcript:

Telerik Software Academy Telerik School Academy DBMS Fundamental Concepts

1. Relational Databases  Models  DBMS & RDBMS Systems 2. Database Tables  Relationships and Multiplicity  E/R Diagrams  Normalization  Constraints  Indices 2

3. The SQL language 4. Subordinates  Stored Procedures  Views  Triggers  Transactions and Isolation Levels 5. NoSQL Databases 6. Relational vs. NoSQL Databases 3

Relational Databases, Database Servers and RDBMS

 Database models  Hierarchical (tree)  Network / graph  Relational (table)  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 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 stored in the tables  Support for the SQL language  Transaction management (optional) 6

 RDBMS systems are also known as:  Database management servers  Or just database servers  Popular RDBMS servers:  Microsoft SQL Server  Oracle Database  MySQL  IBM DB 2  PostgreSQL  SQLite 7

8

 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, or other) Id First Name Last Name Employer1NikolayKostovTelerik 2StephenForteTelerik 3SteveJobsApple 9

 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  The primary key can be composed by several columns (composite primary key) Id First Name Last Name Employer1NikolayKostovTelerik 2StephenForteTelerik 3SteveJobsApple 11 Primary key

12

 Relationships between tables are based on interconnections: primary key / foreign key 13IdName CountryId 1Sofia1 2Plovdiv1 3Munich2 4Berlin2 5Moscow3 IdName1Bulgaria 2Germany 3Russia Towns Countries Primary key Foreign key

 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 14

 Relationship one-to-many (or many-to-one)  A single record in the first table has many corresponding records in the second table  Used very often 15IdName CountryId 1Sofia1 2Plovdiv1 3Munich2 4Berlin2 5Moscow3 IdName1Bulgaria 2Germany 3Russia Towns Countries

 Relationship many-to-many  Records in the first table have many correspon- ding records in the second one and vice versa  Implemented through additional table 16IdName1Pesho 2Minka 3Gosho 4Penka IdName1.NET 2Java 3PHP Students Courses StudentId CourseId StudentsCourses

IdTitle1Ph.D.  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 17 IdIdIdIdNameAge1 Ivan Daddy 72 2 Goiko Dude 26 3 Grand Mara 24 PersonsIdSpecialty2 Computer Science 3Chemistry Students Primary & Foreign key in the same time Primary key Primary & foreign key in the same time Professors

 How do we represent trees and graphs? 18 Root DocumentsPictures Birthday Party

 The primary / foreign key relationships can point to one and the same table  Example: employees in a company have a manager, who is also an employee 19IdFolderParentId1Root (null) 2Documents1 3Pictures1 4 Birthday Party 3 Employees Primary key Foreign key Self- relationship

20

 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) 21

22 The diagram is created with Microsoft SQL Server Management Studio

23 The diagram is created with ERwin

24 The diagram is created with fabFORCE DB Designer for MySQL

25 The diagram is created with MS Visio

 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 26

27

 Normalization of the relational schema removes repeating data  Non-normalized schemas can contain many data repetitions, e.g. 28ProductProducerPriceCategoryShopTownyoghurt Mlexis Ltd. 0.67food store "Mente" Sofia bread "Dobrudja" Bakery "Smoky" 0.85 food store "Mente" Sofia beer "Zagorka" Zagorka Corp soft drinks stall "non- stop" Varna beer "Tuborg" Shoumen Drinks Corp soft drinks stall "non- stop" Varna

 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 29BookTitle ISBN (PK) AuthorAuthor .NET Framework Mr. Kiro Beginning SQL Santa Claus

 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) 30 BookTitle (PK) Author (PK) Price Author .NET Framework Mr. Kiro Beginning SQL Santa Claus The price depends on the book depends on the author

 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" 31IdProduct Producer Id Price Category Id Shop Id Town Id 1yoghourt bread "Tipov" rakiya "Biserna" beer "Tuborg"

 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) 32AuthorIdBookArticle2.NET Programming Regular Expressions in.NET 4 Mastering JavaScript AJAX Performance Patterns One author can have many books One author can have many articles

 Example of fully normalized schema (in 4 th Normal Form): 33 IdIdIdIdName2 "Milk" Ltd. 4 "Zagorka" AD IdName4beer 2food IdProductProducerIdPrice Catego ryId Shop Id Town Id 1Youghurt bread "Dobrudja" rakia "Peshtera" beer "Tuborg" IdIdIdIdName1Billa 4METROIdName1Sofia 3Varna Products Producers Categories Shops Towns

34

 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 35

 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: 36 (hour >= 0) AND (hour = 0) AND (hour < 24) name = UPPER(name)

37

 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) 38

39

 SQL (Structured Query Language)  Standardized declarative language for manipulation of relational databases  SQL-99 is currently in use in most databases   SQL language supports:  Creating, altering, deleting tables and other objects in the database  Searching, retrieving, inserting, modifying and deleting table data (rows) 40

 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: 41 SELECT Towns.Name, Countries.Name FROM Towns, Countries WHERE Towns.CountryId = Countries.Id

42

 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 43

 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: 44 CREATE OR REPLACE PROCEDURE spInsertCountry(countryName varchar2) IS BEGIN INSERT INTO Countries(Name) INSERT INTO Countries(Name) VALUES(countryName); VALUES(countryName);END;

45

 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 46

47IdCompany TownId 1 Mente LTD 1 2 BulkSoft Inc. 2 3 HardSoft Corp. 4 4 Sputnik Corp. 3 IdTownCountryId1Sofia1 2 New York 3 3Moscow2 4Plovdiv1 CompaniesTownsIdCountry1Bulgaria 2Russia 3USA Countries

48 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";IdCompany1 Mente Ltd. 3 HardSoft Corp. V_BGCompanies

49

 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 of the affected rows, e.g.  To change the newly added data  To maintain logs and history 50

 We have a table holding company names:  A trigger that appends "Ltd." at the end of the name of a new company: 51 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;

52

 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 53

Rollback Commit 54 Read Write Write Durable starting state Durable,consistent, ending state Sequence of reads and writes

 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 55

56

 Document model  Set of documents, e.g. JSON strings  Key-value model  Set of key-value pairs  Hierarchical key-value  Hierarchy of key-value pairs  Wide-column model  Key-value model with schema  Object model  Set of OOP-style objects 57 Name: Nikolay Kostov Gender: male Phone: Address: - Street: Al. Malinov 31 - Post Code: Town: Sofia - Country: Bulgaria Site:

 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”? 58

59

 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 60

61 Name: Nikolay Kostov Gender: male Phone: Address: - Street: Al. Malinov 31 - Post Code: Town: Sofia - Country: Bulgaria Site: Document Model Relational Model Name Nikolay Kostov Gendermale Phone Sitewww.kostov.com CountryBulgaria Street Al. Malinov 31 Post Code 1729 TownSofia * 1 * 1 * 1

 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:

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

1. What database models do you know? 2. Which are the main functions performed by a Relational Database Management System (RDBMS)? 3. Define what is "table" in database terms. 4. Explain the difference between a primary and a foreign key. 5. Explain the different kinds of relationships between tables in relational databases. 6. When is a certain database schema normalized? What are the advantages of normalized databases? 64

7. What are database integrity constraints and when are they used? 8. Point out the pros and cons of using indexes in a database. 9. What's the main purpose of the SQL language? 10. What are transactions used for? Give an example. 11. What is a NoSQL database? 12. Explain the classical non-relational data models. 13. Give few examples of NoSQL databases and their pros and cons. 65

 C# Telerik Academy  csharpfundamentals.telerik.com csharpfundamentals.telerik.com  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com