A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.

Slides:



Advertisements
Similar presentations
Chapter 23 Database Security and Authorization Copyright © 2004 Pearson Education, Inc.
Advertisements

Introduction to Structured Query Language (SQL)
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
De-normalize if… Performance is unsatisfactory Table has a low update rate –(sacrifice flexibility) Table has a high query rate –(speed up retrieval)
Introduction to Structured Query Language (SQL)
Concepts of Database Management, 4th Edition, Pratt & Adamski
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
Introduction to Structured Query Language (SQL)
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Introduction to DBMS and SQL Introduction to DBMS and SQL GUIDED BY : MR. YOGESH SAROJ (PGT-CS) MR. YOGESH SAROJ (PGT-CS) Presented By : JAYA XII –COM.
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Concepts of Database Management, Fifth Edition Chapter 4: The Relational Model 3: Advanced Topics.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Concepts of Database Management Seventh Edition
1 Database Administration. 2 Objectives  Understand, create, and drop views  Grant and revoke users’ privileges  Understand and obtain information.
Chapter 6 Database Administration
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
1 Chapter 6 Database Administration. 2 Introduction Database administration The process of managing a database Database administrator A person or an entire.
Maintaining a Database Access Project 3. 2 What is Database Maintenance ?  Maintaining a database means modifying the data to keep it up-to-date. This.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Week 5 Lecture 2 Data Integrity Constraints. Learning Objectives  Learn the types and the uses of constraints  Examine the syntax and options for creating.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
DBAdmin D D D D D a a a a a t t t t t a a a a a b b b b b a a a a a s s s s s e e e e eAdministration / Embedded SQL by: Glen Orsburn Chapter 6.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
A Guide to MySQL 6. 2 Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT command.
A Guide to SQL, Sixth Edition 1 Chapter 5 Updating Data.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
SQL Basics Review Reviewing what we’ve learned so far…….
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Understanding Core Database Concepts Lesson 1. Objectives.
3 A Guide to MySQL.
A Guide to SQL, Seventh Edition
國立臺北科技大學 課程:資料庫系統 Chapter 7 SQL Data Definition.
SQL Creating and Managing Tables
SQL Creating and Managing Tables
SQL Creating and Managing Tables
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
A Guide to SQL, Eighth Edition
CH 4 Indexes.
Chapter 2 Views.
IST 318 Database Administration
Presentation transcript:

A Guide to SQL, Seventh Edition

Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database privileges Understand the purpose, advantages, and disadvantages of using an index A Guide to SQL, Seventh Edition

Objectives Create, use, and drop an index Understand and obtain information from the system catalog Use integrity constraints to control data entry A Guide to SQL, Seventh Edition

Views A view is an application program’s or individual user’s picture of the database Base tables are the existing, permanent tables in a relational database A view is a derived table because data in it is retrieved from the base table A Guide to SQL, Seventh Edition

Views To user, a view appears as an actual table, but it is not A view usually includes less information than the full database  Its use represents a great simplification  Provides a measure of security by omitting sensitive information  unavailable to user A Guide to SQL, Seventh Edition

Defining Views A view is defined by creating a defining query  Indicates rows and columns to include Use CREATE VIEW command  CREATE VIEW, followed by the name of the view, AS, and then a query A Guide to SQL, Seventh Edition

Defining Views MySQL does not support views at this time Access users would create the defining query and save the query with view name Data shown in the view does not exist in this form, nor will it ever Not a temporary table A Guide to SQL, Seventh Edition

Queries Involving Views If a query involves a view, SQL changes the query to select data from the table in the database that created the view DBMS does not execute the query in the form Entered query is merged with original query that defined the view to create the final query that is executed A Guide to SQL, Seventh Edition

The query executed by SQL A Guide to SQL, Seventh Edition

Renaming Columns In a View Column names can be assigned in new view Include new column names in parentheses, following the name of the view Output will display new column names A Guide to SQL, Seventh Edition

View Joining Two Tables Defining query of a view can be any valid SQL query A view can join two or more tables A Guide to SQL, Seventh Edition

A View with Statistics A view can involve statistics A Guide to SQL, Seventh Edition

Benefits of Views Views provide data independence  Views can often be used even after database structure changes Different users can view same data differently A view can contain only those columns required by a given user A Guide to SQL, Seventh Edition

Row-and-Column Subsets When attempting to add a row to a row-and- column subset view, the DBMS must determine how to enter data Provided every column not included in a view can accept nulls, use INSERT Data may be rejected on some attempts when problems arise A Guide to SQL, Seventh Edition

Row-and-Column Subsets Updates or deletes are not a problem in this view Not every row-and-column subsets are updatable A Guide to SQL, Seventh Edition

Joins Views that involve joins of base tables can cause problems at update A Guide to SQL, Seventh Edition

Updatable Views Updatable view is when a view is derived by joining two tables on primary key of each table Views involving joins by matching the primary key of one table with a column that is not the primary key are not updatable More severe problems are encountered if neither of the join columns is a primary key A Guide to SQL, Seventh Edition

Statistics Most difficult views to update are those that involve statistics You can not add rows to a view that includes calculations A Guide to SQL, Seventh Edition

Dropping a View Remove a view that is no longer needed with DROP VIEW command The DROP VIEW command removes only the view definition  Table and data remain unchanged A Guide to SQL, Seventh Edition

Security Security is the prevention of unauthorized access to a database  Some may be able to retrieve and update anything in a database  Others may be able to retrieve data but not change data  Others may be able to access only a portion of data A Guide to SQL, Seventh Edition

Access Using the GRANT Command Main mechanism for providing access to a database is the GRANT command Database administrator can grant different types of privileges to users and revoke them later Privileges include rights to select, insert, update, index, and delete table data A Guide to SQL, Seventh Edition

Using the REVOKE Command Database administrator uses the REVOKE command to remove privileges from users Format is similar to GRANT command A Guide to SQL, Seventh Edition

Indexes An index speeds up the searching of tables Similar to an index in a book Indexes are more complicated than that shown in the figures A Guide to SQL, Seventh Edition

Indexes The DBMS system manages indexes User determines the columns on which to build indexes Disadvantages  Index occupies disk space  DBMS must update the index as data is entered A Guide to SQL, Seventh Edition

Dropping an Index The command to drop or delete an index is DROP INDEX  DROP INDEX followed by the name of the index to drop Permanently deletes index A Guide to SQL, Seventh Edition

Unique Indexes To ensure uniqueness of non-primary key data, you can create a unique index  Command is CREATE UNIQUE INDEX A unique index will reject any update that would cause a duplicate value in the specified column A Guide to SQL, Seventh Edition

System Catalog Information about tables in the database is kept in the system catalog or data dictionary Describes types of items kept in the catalog Also describes the way in which you can query it to access information about the database structure A Guide to SQL, Seventh Edition

System Catalog The DBMS automatically maintains system catalog  SYSTABLES, information about the tables known to SQL  SYSCOLUMNS, information about the columns within those tables  SYSVIEWS, information about the views that have been used A Guide to SQL, Seventh Edition

Integrity Rules in SQL An integrity constraint is a rule for the data in the database  Examples in Premier Products A sales rep’s number must be unique The sales rep number for a customer must match an exiting sales rep number Item classes for parts must be AP, HW, or SG A Guide to SQL, Seventh Edition

Integrity Support Integrity support is the process of specifying integrity constraints for the database Clauses to support three types of integrity constraints that can be specified within a CREATE TABLE or ALTER TABLE command A Guide to SQL, Seventh Edition

Adding and Changing Integrity Constraints An ALTER TABLE command is followed by ADD to indicate the addition of the constraint To change an integrity constraint, simply enter a new constraint New constraint will immediately replace the original A Guide to SQL, Seventh Edition

Types of Constraints Primary keys  Use ADD PRIMARY KEY clause on ALTER TABLE command to add after creating a table Foreign keys  A column in one table whose value matches the primary key in another Legal values  The CHECK clause ensures only legal values are allowed in a given column A Guide to SQL, Seventh Edition

Parent and Child When specifying a foreign key, the table containing the foreign key is the child Table referenced by the foreign key is the parent A Guide to SQL, Seventh Edition

CHECK Clause The CHECK clause of the ALTER TABLE command is used to ensure only legal values satisfying a particular condition are allowed in a given column Check (Class in (‘AP’, ‘HW’, ‘SG’) ) or Check (Class = ‘AP’ OR CLASS = ‘HW’ OR CLASS = ‘SG’) A Guide to SQL, Seventh Edition

Summary The purpose, creation, use, and benefit of views Examined the features related to security The purpose, advantages, and disadvantages of using indexes Add and drop indexes System catalog information Integrity constraints A Guide to SQL, Seventh Edition