Databasemagament System - DBMS, Study notes of Database Management Systems (DBMS)

This document about DBMS: Project Requirements , Programming with DBMS, What is PL/SQL, PL/SQL BLOCK STRUCTURE, PL/SQL Block Types, PL/SQL Variable Types.

Typology: Study notes

2010/2011

Uploaded on 09/01/2011

visir66
visir66 🇮🇳

4.4

(74)

97 documents

1 / 121

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
©Silberschatz, Korth and Sudarshan6.1Database System Concepts
DBMS: Project Requirements
DBMS: Project Requirements
We have studies RDBMS Modeling, Querying and Design using
Normalization
SQL :
SQL :
Programming with DBMS
PL-SQL:Introduction
Handling Software Projects,
DataBase Connectivity
ODBC-JDBC: Native Drivers
Embedded SQL
Assertions
Assertions
Triggers
Triggers
Security
Security
Authorization
Authorization
Authorization in SQL
Authorization in SQL
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Databasemagament System - DBMS and more Study notes Database Management Systems (DBMS) in PDF only on Docsity!

DBMS: Project Requirements DBMS: Project Requirements

We have studies RDBMS Modeling, Querying and Design using Normalization

 (^) SQL :SQL :

 (^) Programming with DBMS  (^) PLSQL:Introduction  (^) Handling Software Projects,  DataBase Connectivity  (^) ODBCJDBC: Native Drivers  (^) Embedded SQL

 (^) AssertionsAssertions

 (^) TriggersTriggers

 (^) SecuritySecurity

 (^) AuthorizationAuthorization

 (^) Authorization in SQLAuthorization in SQL

Programming with DBMS Programming with DBMS

 (^) Despite designing and developing the data base , we are often

needed to program it for manipulating data.

 (^) Most of the real life projects involve tasks, which needs

writing program codes for desired results from DBMS.

 (^) Though large number of queries can be handled through SQL

Constructs but even then we are often required to write program codes in RDBMS Environment for the desired work.  (^) Using PL/SQL  (^) Using Other Programming Languages (Java, Visual Basic)  (^) Database Connectivity issues : JDBCDatabase Connectivity issues : JDBC

PL/SQL BLOCK STRUCTURE PL/SQL BLOCK STRUCTURE

DECLARE (optional)

variable declarations

BEGIN (required)

SQL statements

PL/SQL statements or subblocks

EXCEPTION (optional)

actions to perform when errors occur

END; (required)

PL/SQL Block Types PL/SQL Block Types

Anonymous

DECLARE

BEGIN

statements

EXCEPTION

END;

Procedure

PROCEDURE IS BEGIN statements EXCEPTION END;

Function

FUNCTION RETURN IS BEGIN statements EXCEPTION END;

Stored Procedures Stored Procedures

 (^) Stored Procedures are PL/SQL code stored in the database and executed when called by the user.  (^) Called by procedure name from another PL/SQL block or using EXECUTE from SQL+. For example EXEC SQR(50)  (^) Example:

Create procedure SQR (v_num_to_square IN number)SQR AS v_answer number(10); BEGINBEGIN v_answer := v_num_to_square * v_num_to_square; dbms_output.put_line(v_answer); END;END /

Triggers & Assertions Triggers & Assertions

 (^) Triggers: What and How to write triggers

Triggering actions

When to use & when NOT to use.

 (^) Assertions: What and How?

Assertions

Example Assertions

Trigger concepts Trigger concepts

 (^) Triggers are PL/SQL programs that automatically fire when:

 (^) A DML statement, such as an UPDATE, INSERT or DELETE statement occurs on a table  (^) A system event, such as SHUTDOWN, STARTUP or SERVERERROR occurs  (^) A user event, such as LOGON or LOGOFF occurs  (^) A DDL statement, such as CREATE, DROP or ALTER occurs

Trigger restrictions

 (^) Triggers cannot be fired for a SELECT statement.

 (^) Triggers can never be executed explicitly like procedures or functions.

 (^) Triggers can call database procedures, functions and packages.

Triggers Triggers

 (^) A trigger is a statement that is executed automatically by the

system as a side effect of a modification to the database.

 (^) To design a trigger mechanism, we must:

 (^) Specify the conditions under which the trigger is to be executed.  (^) Specify the actions to be taken when the trigger executes.

 (^) Triggers introduced to SQL standard in SQL:1999, but supported

even earlier using nonstandard syntax by most databases.

Trigger Example Trigger Example

 (^) Suppose that instead of allowing negative account balances, the

bank deals with overdrafts by  (^) setting the account balance to zero  (^) creating a loan in the amount of the overdraft  (^) giving this loan a loan number identical to the account number of the overdrawn account

 (^) The condition for executing the trigger is an update to the

account relation that results in a negative balance value.

Trigger Example in SQL:1999 Trigger Example in SQL:

create trigger overdrafttrigger after update on account referencing new row as nrow for each row when nrow.balance < 0 begin atomic insert into borrower (select customername, accountnumber from depositor where nrow.accountnumber = depositor.accountnumber ); insert into loan values (n.row.accountnumber, nrow.branchname,

  • nrow.balance); update account set balance = 0 where account.accountnumber = nrow.accountnumber end

External World Actions External World Actions

 (^) We sometimes require external world actions, such as

 (^) reordering an item whose quantity in a warehouse has become small, or  (^) turning on an alarm light , to be triggered on a database update

 (^) Triggers cannot be used to directly implement externalworld actions, BUT  (^) Triggers can be used to record actionstobetaken in a separate table, and we can have an external process that repeatedly scans the table and carries out externalworld actions.

 (^) E.g. Suppose a warehouse has the following tables

 (^) inventory(item, level): How much of each item is in the warehouse  minlevel(item, level) : What is the minimum desired level of each item  reorder(item, amount): What quantity should we reorder at a time  (^) orders(item, amount) : Orders to be placed (read by external process)

External World Actions (Cont.) External World Actions (Cont.)

create trigger reordertrigger after update of amount on inventory referencing old row as orow, new row as nrow

for each row when nrow.level < = (select level from minlevel where minlevel.item = orow.item) and orow.level > (select level from minlevel where minlevel.item = orow.item) begin insert into orders (select item, amount from reorder where reorder.item = orow.item) end

When Not To Use Triggers When Not To Use Triggers

 (^) Triggers were used earlier for tasks such as

 (^) maintaining summary data (e.g. total salary of each department)  (^) Replicating databases by recording changes to special relations (called change or delta relations) and having a separate process that applies the changes over to a replica

 (^) There are better ways of doing these now:

 (^) Databases today provide built in materialized view facilities to maintain summary data  (^) Databases provide builtin support for replication

 (^) Encapsulation facilities can be used instead of triggers in many

cases  (^) Define methods to update fields  (^) Carry out actions as part of the update methods instead of through a trigger

Triggers & Assertions Triggers & Assertions

 (^) Triggers and Assertions both are very useful constructs in DBMS

which are used for controlling some behavior in a given Information system.

 (^) Triggers are fired depending upon the triggering event and

should be used sparingly.

 (^) Assertions can be told as extension of the concept of

Constraints, which impose some conditions on Database manipulations which needed to be followed before any otherbefore any other action action takes place.

 (^) Assertions also should be used sparingly as it is expensive!