Ders # 7. Veri Bütünlüğü Programlama ve Güvenlik. From Elmasri/Navathe textbook Ch9,26 Sciore textbook, Ch 9-10

Similar documents
Chapter 9. MORE SQL: Assertions, Views, and Programming Techniques. Constraints as Assertions. Assertions: An Example

SQL- Updates, Asser0ons and Views

SQL: Advanced Queries, Assertions, Triggers, and Views. Copyright 2012 Ramez Elmasri and Shamkant B. Navathe

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

Views, assertions, and triggers

SQL. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Enhanced Data Models for Advanced Applications. Active Database Concepts

DATABASE DESIGN II - 1DL400

UNIT-V SQL Explain insert, delete and update statements in SQL with example.

CSC 261/461 Database Systems Lecture 6. Fall 2017

Assertions, Views, and Programming. CS157A Chris Pollett Oct. 31, 2005.

More SQL: Complex Queries, Triggers, Views, and Schema Modification

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

The Relational Model 2. Week 3

COSC344 Database Theory and Applications. Lecture 11 Triggers

Slides by: Ms. Shree Jaswal

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

DATABASDESIGN FÖR INGENJÖRER - 1DL124

CSE 565 Computer Security Fall 2018

CS352 Lecture: Integrity and Security Constraints revised 9/8/06

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

CT13 DATABASE MANAGEMENT SYSTEMS DEC 2015

DATABASE SECURITY AND PRIVACY. Some slides were taken from Database Access Control Tutorial, Lars Olson, UIUC CS463, Computer Security

Ref1 for STUDENT RECORD DB: Ref2 for COMPANY DB:

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Database Programming with PL/SQL

SQL: A COMMERCIAL DATABASE LANGUAGE. Complex Constraints

Chapter 9: Database Security: An Introduction. Nguyen Thi Ai Thao

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

An Introduction to Structured Query Language

Simple SQL Queries (contd.)

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

An Introduction to Structured Query Language

CSEN 501 CSEN501 - Databases I

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

CHAPTER 5 SECURITY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

Security and Authorization

An Introduction to Structured Query Language

Database System Concepts

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

Database Systems ( 資料庫系統 )

An Introduction to Structured Query Language

Chapter 10 Advanced topics in relational databases

Access Control. Access control: ensures that all direct accesses to object are authorized a scheme for mapping users to allowed actions

An Introduction to Structured Query Language

Integrity Constraints (Reminder)

Access Control Models

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

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

Sample Question Paper

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

1 Prepared By Heena Patel (Asst. Prof)

D B M G. SQL language: basics. Managing tables. Creating a table Modifying table structure Deleting a table The data dictionary Data integrity

GUJARAT TECHNOLOGICAL UNIVERSITY

SQL STRUCTURED QUERY LANGUAGE

Database Systems Laboratory 5 Grouping, DCL & TCL

UNIVERSITY REGULAR EXAMINATIONS 2013 /2014 ACADEMIC YEAR FOR THE DEGREE OF BACHELOR OF SCIENCE IN COMPUTER SCIENCE

The Relational Model. Week 2

Access Control. Protects against accidental and malicious threats by

COSC 304 Introduction to Database Systems. Views and Security. Dr. Ramon Lawrence University of British Columbia Okanagan

Normalization. Murali Mani. What and Why Normalization? To remove potential redundancy in design

Chapter 6 The Relational Algebra and Calculus

Debapriyo Majumdar DBMS Fall 2016 Indian Statistical Institute Kolkata

Modern Database Systems Lecture 1

Structure Query Language (SQL)

Relational Data Structure and Concepts. Structured Query Language (Part 1) The Entity Integrity Rules. Relational Data Structure and Concepts

Wentworth Institute of Technology COMP2670 Databases Spring 2016 Derbinsky. Physical Tuning. Lecture 12. Physical Tuning

The Relational Model

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

PostgreSQL Documentation. Fast Backward

Database Security Lecture 10

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Database Technology. Topic 6: Triggers and Stored Procedures

q Ø v v v v v v v v IBM - 2

Database Applications (15-415)

CPS221 Lecture: Relational Database Querying and Updating

Database Security. Authentification: verifying the id of a user. Authorization: checking the access privileges

5 Integrity Constraints and Triggers

CPS221 Lecture: Relational Database Querying and Updating

download instant at The Relational Data Model

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. Physical Tuning. Lecture 10. Physical Tuning

Chapter 24. Active Database Concepts and Triggers. Outline. Trigger Example. Event-Condition-Action (ECA) Model

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Outline. Textbook Chapter 6. Note 1. CSIE30600/CSIEB0290 Database Systems Basic SQL 2

The Relational Model. Chapter 3

SQL (Structured Query Language) Truong Tuan Anh CSE-HCMUT

Misc. Triggers Views Roles Sequences - Synonyms. Eng. Mohammed Alokshiya. Islamic University of Gaza. Faculty of Engineering

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

Instructor: Jinze Liu. Fall 2008

B.C.A DATA BASE MANAGEMENT SYSTEM MODULE SPECIFICATION SHEET. Course Outline

General Overview - rel. model. Carnegie Mellon Univ. Dept. of Computer Science Database Applications. Reminder: our Mini-U db

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

Transcription:

Ders # 7 Veri Bütünlüğü Programlama ve Güvenlik From Elmasri/Navathe textbook Ch9,26 Sciore textbook, Ch 9-10

Outline: General Constraints as Assertions Triggers Security Objective: Specification of more general constraints via assertions, triggers Coordination of users access to data. Authorization issues on dabases.

Constraints as Assertions General constraints: constraints that do not fit in the basic SQL categories (such as unique, primary key, not null, foreign key..) Mechanism: CREAT ASSERTION a constraint name, followed by CHECK, followed by a condition The salary of an employee must not be greater than the salary of the manager of the department that the employee works for CREAT ASSERTION SALARY_CONSTRAINT CHECK (NOT EXISTS ( SELECT * FROM EMPLOYEE E, EMPLOYEE M, DEPARTMENT D WHERE E.SALARY > M.SALARY AND E.DNO=D.NUMBER AND D.MGRSSN=M.SSN))

SQL Triggers Objective: to monitor a database and take initiate action when a condition occurs Triggers are action that fire automatically based on these conditions Triggers are expressed in a syntax similar to assertions and include the following: Event : Such as an insert, deleted, or update operation Condition : optional Action:To be taken when the condition is satisfied CREATE TRIGGER <name>: Creates a trigger ALTER TRIGGER <name> : Alters a trigger (assuming one exists) CREATE OR ALTER TRIGGER <name> Creates a trigger if one does not exist Alters a trigger if one does exist

A student record database:

A student record database:

A student record database:

fig_05_05

Triggers on Simplified COMPANY DB EMPLOYEE (NAME, SSN, SALARY, DNO, SUPERVİSOR_SSN) DEPARTMENT (DNAME, DNO, TOTAL_SAL, MANAGER _SSN) EXAMPLE 1: A trigger to compare an employee s salary to his/her supervisor during insert or update operations: CREATE TRIGGER INFORM_SUPERVISOR BEFORE INSERT OR UPDATE OF SALARY, SUPERVISOR_SSN ON EMPLOYEE FOR EACH ROW WHEN NEW.SALARY> (SELECT SALARY FROM EMPLOYEE WHERE SSN=NEW.SUPERVISOR_SSN)) INFORM_SUPERVISOR (NEW.SUPERVISOR_SSN,NEW.SSN);

EXAMPLE2: Triggers on Simplified COMPANY DB EMPLOYEE (NAME, SSN, SALARY, DNO, SUPERVİSOR_SSN) DEPARTMENT (DNAME, DNO, TOTAL_SAL, MANAGER _SSN) keep updated the DEPARTMENT.TOTAL_SAL 4 events runs the trigger: T1: Total_sal1 (When a new employees is added to a department, modify the Total_sal of the Department to include the new employees salary) This trigger will execute AFTER INSERT ON Employee table It will do the following FOR EACH ROW WHEN NEW.Dno is NOT NULL The trigger will UPDATE DEPARTMENT By SETting the new Total_sal to be the sum of» old Total_sal and NEW. Salary» WHERE the Dno matches the NEW.Dno; T2:Total_sal2: (changing salary of existing Emp.) T3: (Deleting an employee.) T4: (Changing department of an employee.)

Example2 (implementing T1) Can be CREATE or ALTER T1: CREATE TRIGGER Total_sal1 AFTER INSERT ON Employee FOR EACH ROW WHEN (NEW.Dno is NOT NULL) UPDATE DEPARTMENT SET Total_sal = Total_sal + NEW. Salary WHERE Dno = NEW.Dno; Can be BEFORE, AFTER, INSTEAD OF Can be INSERT, UPDATE, DELETE The condition The action

Example 3 &4 (implementing T2)

Cont T2 (for each statement) Salary DNO 200 300 Old O Salary DNO 200 Null 300 Null New N Salary DNO 700 Null 900 Null No action!

Authorization methods (yetkilendirme metodları) Discretionary access control Privileges are associated with tables Based on the assumption that the users are trustworthy. Provided by SQL Mandotary access control Privileges are associated with data Eliminates the loopholes of dicreationary method, thus suited for high-security systems (like military) Less flexible 15

Discretionary access control Privileges (hak, yetki) The table s owner grants privileges on it to other users. Kinds of privileges: Select Insert Delete Update SQL grant statement assigns priveleges to users: SYNTAX : grant priv_type on table_name to user_name Example: grant select on COURSE to public 16

UNIVERSITY database 17

users / roles A user is the person who logged into the database. The role is the category of users. For a better feasibility, privileges are granted to roles. Thus the admin should define roles in the database. define users in the database. assign one or more roles to the user. (In case of more than one role, the user is granted the union of priveleges from each role) 18

Fine-tuning: Column privileges grant select on ENROLL to dean, professor The purpose of this privilege was for keeping student enrollments and grades private. Instead of all or nothing aspect, it is better to use column priveleges. Study the following column privileges: grant select(studentid,grade) on ENROLL to dean, professor grant update(grade) on ENROLL to professor grant insert(sname,majorid) on STUDENT to admissions 19

Privileges required by SQL statements: Select requires select privilege on every field mentioned in the query. Insert (update) requires Insert (update) privilege for the field to be inserted (modified), plus the select privilege on every field mentioned in its where clause. delete requires delete privilege for the field to be deleted, plus the select privilege on every field mentioned in its where clause. Example: Determine Who is authorized to execute the SQL statements in the table. 20

More Fine-tuning: Privileges on Views grant update(grade) on ENROLL to professor Column privileges gives roles(users) too much power. A professor can change a grade given by another professor. Solution: Revoke the previous privileges (@slide 4) of professors on ENROLL table. Give the privileges on the following view. 21

Privileges on constraints assertions restricts the contents, limits what the user can do. It is not difficult for a malicious user to define an assertion that would make a table useless. create assertion MakeTableUseless check (not exist select s.* from STUDENT where SName!= abc and GradYear!= 0) Thus, allowing to define assertions should be under authorization. grant references on STUDENT to dean 22

Grant-option Privileges grant insert on STUDENT to admissions with grant option The above grant grants the following previliges to admiision: To insert records on STUDENT table To grant that privilege to others. Since it is a powerful, it is critical to grant that kind of privileges.. 23

Mandatory access control Remember that discretionary controls assume that the users are trustworthy. A malicious professor can easily violate confidentiality. Since the professor is the owner, she can authorize anybody to look at student grades which is supposed to be private. Mandatory access control ensure confidentiality by assigning priveleges to data, rather than to tables(or columns) The IDEA in Mandatory access control : When private data is copied to other tables, it still remains confidential. This idea is implemented by classification levels. 24

Classification levels Every record (or table) and each user is assigned a classification level. Top secret Secret Classified Unclassfied A user is authorized to execute an SQL if his level is at least as high as the level of input tables. Suppose ENROLL s level is secret, SECTION s level is classified and COURSE s level is unclassified. In such a case, the user that has at least a level of secret is able to execute the query. The query s output table has the highest level of its input tables. 25

SUMMARY on Authorization methods Prefered in commercial databases Discretionary access control Privileges are associated with tables Based on the assumption that the users are trustworthy. Provided by SQL Mandotary access control Privileges are associated with data Eliminates the loopholes of dicreationary method, thus suited for high-security systems (like military) Less flexible 26