Relational data model. Concepts. Relational data model. Represent database as collection of relations. In relational model row is known as tuple , column header known as attribute, and table known as relation. Relation Schema. Account = (account-number, branch-name, balance)
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Relational data model • Represent database as collection of relations. • In relational model row is known as tuple, column header known as attribute, and table known as relation.
Relational data model • Domain : Set of all possible values • Domain of account-number : set of all account number • Domain of branch name : set of all branch name
Domain • Atomic domain: Elements of the domain are indivisible units. • domain=(rakesh, mahesh, raj) • Domain=(rakeshkumar, maheshverma, raj mittal)
Null values • Customer=(cus_id, name, address, contact_no) • Sandeep does not have any telephone. null
Null values • Customer=(cus_id, name, address, contact_no) • Address of customer not known at time of record entry. null Null values signify value is unknown or does not exists.
Super Key • Super key: set of one and more attributes that, taken collectively allow uniquely identify tuple in the relation. <Roll No> <Roll No, Student_name> <Roll no, Branch> <Roll no, student_name, branch> <Roll no, Student_name, Branch, address> Student_name, address>
Candidate key • Candidate key: Super key whose proper subset are not super key or minimal super key. <Roll No> <Roll No, Student_name> subset <Roll no> <Student name> <Roll no, Branch> subset < Roll no> <Branch> <Roll no, student_name, branch> <Roll no> < student_name> <branch> <Roll no, Student_name, Branch, address> <Student_name, address> = <Student_name> < Address> X X X X
key • R=<A1,A2,A3,…> • t=<v1,v2,v3,….> • If K is primary key of relation R then for any t1,t2 • t1[K] =/= t[K]
Domain Constraint • Value of attribute A must be atomic value from domain. • Domain=(rakesh, mahesh, sanjay) • Domain=(rakeshverma, maheshsingh, sanjaymittal)
Delete operation delete employee with id 120122 from faculty Faculty Dept Referential integrity constraints
Update operation Update id of faculty with id=120122 to id=120111 Faculty Dept Referential integrity constraints
Relational Algebra • Basic set of relational model operation. How to represent operation of relation. Example : if data of employee Amit is required then how to write this query
Relational Algebra(Select) • Basic set of relational model operation. Faculty All data is required σ ( Faculty )
Relational Algebra(Select) • Basic set of relational model operation. Faculty Record of kapil is required σname=kapil( Faculty )
Relational Algebra • Basic set of relational model operation. Faculty Record of faculties are required whose qualification is M.tech σqualification=M.tech( Faculty )
Relational Algebra Record of faculties are required whose qualification is M.tech and who live in noida σqualification=M.tech ^ address=noida( Faculty )
Assertions • An assertion is a predicate expressing a condition that we wish the database always to satisfy. • An assertion in SQL takes the form create assertion <assertion-name> check <predicate> • When an assertion is made, the system tests it for validity, and tests it again on every update that may violate the assertion • This testing may introduce a significant amount of overhead; hence assertions should be used with great care. • Asserting for all X, P(X) is achieved in a round-about fashion using not exists X such that not P(X)
Assertion Example • The amount of every account never less than 1000 Create assertion balance_constraint check(amount>1000)
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.
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.
Disadvantage • . Simple validations can be done at the application level itself . • Triggers executes invisibly from client-application which connects to the database server.So it is difficult to figure out what happens at the database layer. • Triggers runs on every update made to the table therefore it adds more load to the database and cause the system to run slow.
SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Joined Relations Data Definition Language Embedded SQL, ODBC and JDBC
Create table • Create table faculty ( Employee_id number primary key, Name varchar(20), Address varchar(100), Contact number(10), Qualification varchar(5) )