Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Administration, Integrity and Performance.

Similar presentations


Presentation on theme: "Database Administration, Integrity and Performance."— Presentation transcript:

1 Database Administration, Integrity and Performance

2 Objectives b Define the roles of database administrator b Describe the term integrity b Define the term security b Define the basic performance measures

3 The Database Administrator The Database Administrator b Data Administrator(DA) makes the strategies and policies decisions regarding the data of the enterprise. b Database Administrator(DBA) implements those decisions technically.

4 Functions of DBA b Creating the conceptual schema (logical or conceptual database design) b Creating the internal schema (physical database design)

5 Functions of DBA b Defining security and integrity constraints b Defining backup and recovery policies b Monitoring performance and responding to changing environments.

6 SECURITY b Protecting the data against unauthorised disclosure, alteration or destruction.

7 Security is enforced by b DBMS’s security subsystem b Checking access requests to security constraints stored in system catalog b Giving certain privileges in a relation to certain users

8 What are views for? b Automatic Security for hidden data b Short hand capability b Same data to be seen by different users in a different way at the same time b May provide logical data independence immunity of users and user programs to changes in the logical structure of a databaseimmunity of users and user programs to changes in the logical structure of a database GrowthGrowth – new attributes may be added – new relations may be added

9 SQL FACILITIES FOR VIEWS CREATE VIEW AS CREATE VIEW AS [ WITH [ ] CHECK OPTION ] b With check option means that INSERT and UPDATE on the view will be rejected if they violate any integrity constraint implied by the view defining expression b Qualifier is CASCADED { Default } or LOCAL

10 Examples of views CREATE VIEW Bestsupplier AS SELECT S.S#, S.STATUS, S.CITY AS SELECT S.S#, S.STATUS, S.CITY FROM SUPPLIER FROM SUPPLIER WHERE SUPPLIER.STATUS > 15 WHERE SUPPLIER.STATUS > 15 WITH CHECK OPTION ;

11 Examples of views CREATE VIEW GREENPART AS SELECT PART.P#, PART.NAME, PART.WEIGHT AS WT, PART.CITY SELECT PART.P#, PART.NAME, PART.WEIGHT AS WT, PART.CITY FROM PART FROM PART WHERE PART.Color = ‘Green’ WHERE PART.Color = ‘Green’ WITH CHECK OPTION;

12 Examples of views CREATE VIEW HEAVY_GREENPART AS SELECT GP.P#, GP.NAME, GP.WT, GP.CITY SELECT GP.P#, GP.NAME, GP.WT, GP.CITY FROM GREENPART AS GP FROM GREENPART AS GP WHERE GP.WT > 12.0 WHERE GP.WT > 12.0 WITH CHECK OPTION;

13 Views and Security GRANT SELECT, UPDATE (NAME,WT), DELETE ON GREENPART DELETE ON GREENPART TO user1, user2; TO user1, user2; b Privileges can be USAGE, SELECT, INSERT, UPDATE, DELETE and REFERENCES b Can be provided WITH GRANT OPTION

14 REVOKE REVOKE DELETE ON GREENPART FROM user1 RESTRICT b Revoke can be done for GRANT OPTION FOR also b RESTRICT is needed if a privilege is granted further

15 What is Integrity? b Accuracy or correctness of data in a database b Mostly RDBMS provide two kind of Integrity support: Declarative Integrity supportDeclarative Integrity support Procedural Integrity supportProcedural Integrity support

16 Declarative Support b In the form of constraint definitions b If a new constraint is declared then the system ensures that current state of database satisfies it, otherwise, the new constraint is rejected b If a DBMS provides declarative support, then about 90% of typical database definition would consist of constraints.

17 Declarative Support Contd.. A system providing such support relieve application programmers of the burden, thus, increases productivity

18 Golden Rule b No update operation must ever be allowed to leave any relation in a state that violates its own predicate. No update transaction must ever be allowed to leave database in a state that violates its own predicate.

19 State Vs Transition Constraints b Concerned with the correct state of database b Constraints on legal transitions Not married to marriedNot married to married No student class should ever deceaseNo student class should ever decease

20 FOREIGN KEYS. b Let R2 be a relation, then a foreign key in R2 is a set of attributes of R2, say FK, such that : There exists a relation R1 ( R1 & R2 not necessarily distinct) with a candidate key CK; andThere exists a relation R1 ( R1 & R2 not necessarily distinct) with a candidate key CK; and For all times, each value of FK in the current value of R2 is identical to the value of CK in some tuple in the current value of R1.For all times, each value of FK in the current value of R2 is identical to the value of CK in some tuple in the current value of R1.

21 . Foreign Key contd... b Definition requires that every value of given foreign key appears as a value of matching candidate key - Converse is not a requirement b A foreign key is simple or composite b Each attribute of a given foreign key must have a same name and type as the corresponding component of matching candidate key

22 Referential Integrity b Foreign key is a Reference b Matching candidate key tuple is Referenced b Referential constraint : A value of foreign key must match the referenced candidate key b Referencing Relation : Have foreign key b Referenced Relation : Have candidate key

23 Referential Diagrams. b A given relation can be both referenced and referencing at the same line R3 R2 R1 R3 R2 R1 b R1 & R2 are not necessarily distinct Example : (Employee, Mgr.) Self-referencing relation b Foreign to candidate key match is the glue that holds database together

24 SQL Facilities b A candidate key definition b A foreign key definition b A check constraint definition We may assign a name to constraint We may assign a name to constraint

25 Candidate Key UNIQUE ( ) OR PRIMARY KEY ( ) b At most one Primary key definition b Any number of UNIQUE specifications b NOT NULL is by default

26 Foreign Key FOREIGN KEY ( ) References References [( )] [ ON DELETE [ ON DELETE ON UPDATE ] ON UPDATE ] b No action{default} or CASCADE or SET DEFAULT or SET NULL b Second Comma list, if foreign key references a candidate key that is not primary key.The foreign to candidate key matching is done on column position ( left to right)

27 Example of constraints CREATE TABLE SupPart ( S# S# NOT NULL, P# P# NOT NULL, P# P# NOT NULL, QTY QTY NOTNULL, QTY QTY NOTNULL, PRIMARY KEY( S#, P# ), PRIMARY KEY( S#, P# ), FOREIGN KEY ( S#) REFERENCES SUP ON DELETE CASCADE, ON DELETE CASCADE, ON UPDATE CASCADE, ON UPDATE CASCADE, FOREIGN KEY ( P#) REFERENCES PART FOREIGN KEY ( P#) REFERENCES PART ON DELETE CASCADE ON DELETE CASCADE ON UPDATE CASCADE, ON UPDATE CASCADE, CHECK ( QTY > 0 and QTY 0 and QTY < 5000) );

28 TRIGGERED PROCEDURES b Procedures invoked automatically on occurrence of a specified exception or a specified interval of time b CASCADE referential action is a simple example of a triggered procedure-declaratively specified

29 Assertions b General constraints Cerate ASSERTION Cerate ASSERTION check ( ); check ( ); DROP ASSERTIONS ; b Assertions are always satisfied by database. b On creation validity of an assertion is checked b Any change in database may result in checking by an creation =>High overheads

30 Example b The sum of all loans of a branch should be less than total account balances Create assertion sum-constraint check ( not exists (select * from branch where (select sum (amount) from loan where (select sum (amount) from loan where loan.branch-name = where loan.branch-name = branch.branch-name ) branch.branch-name ) >=(select sum (amount) from account where loan.branch-name = where loan.branch-name = branch.branch-name))) branch.branch-name)))

31 Deferred Checking b SQL constraints can be: DEFERABLE (Initially Immediate OR initially deferrable )DEFERABLE (Initially Immediate OR initially deferrable ) NOT DEFERABLENOT DEFERABLE b SET CONSTRAINT ; statement switches on or off the deferrable constraint b Option is IMMEDIATE or DEFERRED

32 Performance Tuning involves b Tuning of hardware resources b Reducing I/O operations

33 Reducing Disk Accesses b Indexing is one major technique used to reduce disk accesses

34 Ordered indices b Based on based on sorted ordering of values b Index involve Access timeAccess time Insertion timeInsertion time Deletion timeDeletion time Space overheadsSpace overheads

35 Ordered indices b Index Structure is associated with a 'Search Key' Primary index- on a sequentially sorted file. (index on primary key- not correct)Primary index- on a sequentially sorted file. (index on primary key- not correct) Indices whose search key specifies an order different from the sequential order of the file are called secondary or non clustering indices.Indices whose search key specifies an order different from the sequential order of the file are called secondary or non clustering indices.

36 Dense Index b An index record/ entry appears for every search key 'value' in the file & a pointer to first data record with that search key value

37 Sparse Index b Entry only for some of the values and a pointer to first value of that type. Take less spaceTake less space A sparse index with one index entry per block may be a good choice.A sparse index with one index entry per block may be a good choice.

38 Multilevel Indices b Are useful when size of index is very large

39 Secondary Indices b It contains pointers to all records b It should not be sparse b Improve performance b Overheads on modification of databases b Tradeoff : Frequency of Queries versus Modifications

40 B Tree b Is one of the major method of implementing index b B tree adds performance overheads for insertion and deletion and adds apace overheads. b This performance overhead is acceptable even for files with high frequency of modification- no cost of reorganization


Download ppt "Database Administration, Integrity and Performance."

Similar presentations


Ads by Google