Information Systems Engineering. Other Database Concepts

Similar documents
Information Systems Engineering. SQL Structured Query Language DML Data Manipulation (sub)language

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

Database Modifications and Transactions

Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Information Systems for Engineers. Exercise 10. ETH Zurich, Fall Semester Hand-out Due

Data Definition Language (DDL), Views and Indexes Instructor: Shel Finkelstein

Set Operations, Union

TRANSACTION PROPERTIES

COSC344 Database Theory and Applications. Lecture 21 Transactions

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Isolation Levels and Concurrency

Database Management Systems Introduction to DBMS

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 10: Transaction processing. November 14, Lecturer: Rasmus Pagh

CSE 530A ACID. Washington University Fall 2013

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

Lab IV. Transaction Management. Database Laboratory

Databases - Transactions

D B M G D B M G 2. SQL language: other definitions. Transactions. Transactions. Introduction Transactions in SQL Properties of transactions

Lecture 12: Transactions. Monday, March 2, 2015

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL. Overview

Relational Algebra. Spring 2012 Instructor: Hassan Khosravi

Weak Levels of Consistency

Learning Alliance Corporation, Inc. For more info: go to

SQL: Transactions. Introduction to Databases CompSci 316 Fall 2017

T-SQL Training: T-SQL for SQL Server for Developers

TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION 4/3/2014

Overview. Data Integrity. Three basic types of data integrity. Integrity implementation and enforcement. Database constraints Transaction Trigger

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Database Security: Transactions, Access Control, and SQL Injection

Database Usage (and Construction)

Textbook: Chapter 4. Chapter 5: Intermediate SQL. CS425 Fall 2016 Boris Glavic. Chapter 5: Intermediate SQL. View Definition.

CSE 344 MARCH 21 ST TRANSACTIONS

CS425 Fall 2017 Boris Glavic Chapter 5: Intermediate SQL

Announcements. SQL: Part IV. Transactions. Summary of SQL features covered so far. Fine prints. SQL transactions. Reading assignments for this week

SQL: Transactions. Announcements (October 2) Transactions. CPS 116 Introduction to Database Systems. Project milestone #1 due in 1½ weeks

AVANTUS TRAINING PTE LTD

Transactions. A Banking Example

COURSE OUTLINE: Querying Microsoft SQL Server

What is Transaction? Why Transaction Management Required? JDBC Transaction Management in Java with Example. JDBC Transaction Management Example

Databases: transaction processing

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

1/9/13. + The Transaction Concept. Transaction Processing. Multiple online users: Gives rise to the concurrency problem.

Information Systems (Informationssysteme)

Querying Microsoft SQL Server

TRANSACTION PROCESSING MONITOR OVERVIEW OF TPM FOR DISTRIBUTED TRANSACTION PROCESSING

A transaction is a sequence of one or more processing steps. It refers to database objects such as tables, views, joins and so forth.

XI. Transactions CS Computer App in Business: Databases. Lecture Topics

Database Management Systems

Microsoft Querying Data with Transact-SQL - Performance Course

CHAPTER: TRANSACTIONS

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

Database Systems CSE 414

5. Single-row function

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Transaction Processing Dr Fawaz Alarfaj Al Imam Mohammed Ibn Saud Islamic University

Chapter 2. DB2 concepts

Integrity Constraints, Triggers, Transactions and Procedures

SQL Interview Questions

20461: Querying Microsoft SQL Server 2014 Databases

CPSC 421 Database Management Systems. Lecture 19: Physical Database Design Concurrency Control and Recovery

20461: Querying Microsoft SQL Server

After completing this course, participants will be able to:

Querying Microsoft SQL Server (MOC 20461C)

Duration Level Technology Delivery Method Training Credits. Classroom ILT 5 Days Intermediate SQL Server

Administration Naive DBMS CMPT 454 Topics. John Edgar 2

Querying Data with Transact-SQL

UNIT 3 UNIT 3. Transaction Management and Concurrency Control, Performance tuning and query optimization of SQL and NoSQL Databases.

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601

20461D: Querying Microsoft SQL Server

A REVIEW OF BASIC KNOWLEDGE OF DATABASE SYSTEM

Information Systems Engineering

Querying Microsoft SQL Server

Chapter 22. Transaction Management

Introduction to Database Systems

Using XA with Rdb (DECdtm XA Gateway)

Course Outline. Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led

Microsoft Querying Microsoft SQL Server 2014

Querying Microsoft SQL Server 2014

CSE 190D Database System Implementation

Querying Data with Transact-SQL

"Charting the Course to Your Success!" MOC D Querying Microsoft SQL Server Course Summary

Information Systems Engineering. Entity Relationship Model

Chapter 4: Intermediate SQL

Transactions and ACID

Chapter 20 Introduction to Transaction Processing Concepts and Theory

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Joins, NULL, and Aggregation

Information Systems Engineering

20761B: QUERYING DATA WITH TRANSACT-SQL

Transactions. Silberschatz, Korth and Sudarshan

Querying Microsoft SQL Server

Transactions and Isolation

Introduction to Transaction Management

Plan. Department of Informatics. Advanced Software Engineering Prof. J. Pasquier-Rocha Cours de Master en Informatique - SH 2003/04

QUERYING MICROSOFT SQL SERVER COURSE OUTLINE. Course: 20461C; Duration: 5 Days; Instructor-led

John Edgar 2

Data Structure: Relational Model

Database Systemer, Forår 2006 IT Universitet i København. Lecture 10: Transaction processing. 6 april, Forelæser: Esben Rune Hansen

UNIT-IV (Relational Database Language, PL/SQL)

Transcription:

Information Systems Engineering Other Database Concepts 1

Views In a database it is possible to create virtual tables called views Views are not stored in the database They are defined and computed from the tables in the database schema through a SELECT statement They can be referenced and queried as normal tables They are computed at the time of use Under certain restrictions they support modification statements (INSERT, UPDATE, DELETE) transmitting the modifications to the underlying real tables The modified attributes should be linked to only one base table Columns resulting from any computation, aggregation, grouping, having condition or distinct are not allowed to be modified MIB - ESIN apm@feup 2

Views (2) Views are defined by a CREATE VIEW SQL statement Views have a name that should be different from any table The database stores only the view definition The CREATE VIEW statement is defined as CREATE VIEW <view-name> [(<col-name> n )] AS <select-statement> If the list of <col-name> is present, the attributes are renamed for those names The number must match the attributes produced by the <select-statement> MIB - ESIN apm@feup 3

Example Consider the Movies table already seen Movies(title, year, length, genre, studio, producer_id) We can define a view representing the movies made by Paramount CREATE VIEW ParamountMovies AS SELECT title, year FROM Movies WHERE studio = Paramount If we want the Movies made by Paramount in 1979 we can emit the following statement SELECT title FROM ParamountMovies WHERE year = 1979 MIB - ESIN apm@feup 4

Other examples Considering Movies(title, year, length, genre, studio, producer_id) MovieExec(id, name, address, netsalary) We can have a virtual table with renaming CREATE VIEW MovieProd(movie, producer) AS SELECT title, name FROM Movies, MovieExec WHERE producer_id = id If we want the actors from Paramount movies Make a query involving ParamountMovies SELECT DISTINCT starname FROM ParamountMovies, StarsIn WHERE title = movie AND year = movieyear Using a view with other tables is the same as using a subquery MIB - ESIN apm@feup 5

Triggers A trigger is a sequence of SQL statements (the action) that is automatically executed whenever another INSERT, UPDATE or DELETE statement (the event), affecting a table or view, is executed Triggers have names and are stored in the database The action can be executed after the event (only if it is successful) or instead of it The action can contain a condition It is possible to access the values that have disappeared in the event (deleted virtual table) or the newly created (inserted virtual table) MIB - ESIN apm@feup 6

Trigger definition A trigger is created in SQL as CREATE TRIGGER <name> ON { <table> <view> } { AFTER INSTEAD OF } { [INSERT][,][UPDATE][,][DELETE] } AS <sql_statement> The <sql_statement> can be a composed statement, i.e. a list of statements between BEGIN and END It can also be a IF <condition> statement or any other allowed in SQL Server Triggers can help in the verification and correction of constraints In the case of views, they can promote not allowed modifications, replacing simple statements with other more complex but accomplishing the modifications MIB - ESIN apm@feup 7

Example In the SkyClub database we want to automatically promote the skill level of a member to Advanced, whenever they complete 18 jumps We can define a trigger for that, executing on UPDATE statements Such a trigger could be CREATE TRIGGER AdvancedSkill ON SkyMember AFTER UPDATE AS BEGIN UPDATE SkyMember SET skill = A WHERE email IN (SELECT email FROM inserted WHERE jumps >= 18) PRINT Possible promotions done END MIB - ESIN apm@feup 8

Transactions A transaction allows to execute a set of SQL statements as if it were a single and indivisible statement If any of the composing statements fails nothing is changed in the database (all intermediate modifications are rolled back) A transaction must verify the so called ACID properties A (Atomicity) All statements inside a transaction act as a single and indivisible one C (Consistency) Before and after the transaction the database is in a consistent state I (Isolation) Possible temporary inconsistences are not seen by other statements D (Durability) After a successful transaction data is already persisted MIB - ESIN apm@feup 9

Transactions in SQL A transaction begins with BEGIN TRANSACTION [<name>] It ends with COMMIT TRANSACTION [<name>] Transaction successful and modifications persisted ROLLBACK TRANSACTION [<name>] Transaction failed and all modifications are undone The programmer must know the conditions for success or failure and write one of the endings Immediately after the execution of a statement Consult variables @@rowcount or @@error Use the constructions BEGIN TRY END TRY and BEGIN CATCH END CATCH MIB - ESIN apm@feup 10

Transactions in SQL (2) Generic constructions BEGIN TRANSACTION BEGIN TRY /* SQL statements */ COMMIT TRANSACTION END TRY BEGIN CATCH ROLLBACK TRANSACTION END CATCH BEGIN TRANSACTION /* SQL statement */ IF @@rowcount = 0 BEGIN ROLLBACK TRANSACTION RETURN END /* SQL statement */ IF @@error <> 0 BEGIN ROLLBACK TRANSACTION RETURN END COMMIT TRANSACTION MIB - ESIN apm@feup 11

Example From a bank database we have the following relation representing accounts: Accounts(acctNo, balance) A transfer of money from one account to another should be in a transaction DECLARE @amount money = 100.00; BEGIN TRANSACTION UPDATE Accounts SET balance = balance + @amount WHERE acctno = 456; IF @@rowcount = 0 BEGIN ROLLBACK TRANSACTION RETURN END UPDATE Accounts SET balance = balance - @amount WHERE acctno = 123; IF @@rowcount = 0 BEGIN ROLLBACK TRANSACTION RETURN END COMMIT TRANSATION MIB - ESIN apm@feup 12