DATABASE MANAGEMENT SYSTEMS UNIT II- RELATIONAL MODEL

Size: px
Start display at page:

Download "DATABASE MANAGEMENT SYSTEMS UNIT II- RELATIONAL MODEL"

Transcription

1 Objectives DATABASE MANAGEMENT SYSTEMS UNIT II- RELATIONAL MODEL To explain the relational model To know the definition of various keys To know the basic concepts of SQL To write the queries in relational algebra and relational calculus To learn about SQL views, triggers To know the concept of embedded SQL and dynamic SQL 2.1 Basic Structure Formally, given sets D1, D2,. Dn a relation r is a subset of D1 x D2 x x Dn Thus a relation is a set of n-tuples (a1, a2,, an) where each ai Di Example: if customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = {Harrison, Rye, Pittsfield} Then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name x customer-street x customer-city Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the attribute Attribute values are (normally) required to be atomic, that is, indivisible o E.g. multivalued attribute values are not atomic o E.g. composite attribute values are not atomic The special value null is a member of every domain The null value causes complications in the definition of many operations o we shall ignore the effect of null values in our main presentation and consider their effect later Prepared by P.Vasantha Kumari 32

2 Relation Schema A1, A2,, An are attributes R = (A1, A2,, An ) is a relation schema E.g. Customer-schema = (customer-name, customer-street, customer-city) r(r) is a relation on the relation schema R E.g. customer (Customer-schema) Relation Instance The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table 2.2 Keys Let K R K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(r) o by possible r we mean a relation r that could exist in the enterprise we are modeling. o Example: {customer-name, customer-street} and {customer-name} are both superkeys of Customer, if no two customers can possibly have the same name. K is a candidate key if K is minimal Example: {customer-name} is a candidate key for Customer, since it is a superkey (assuming no two customers can possibly have the same name), and no subset of it is a superkey. Determining Keys from E-R Sets Strong entity set. The primary key of the entity set becomes the primary key of the relation. Prepared by P.Vasantha Kumari 33

3 Weak entity set. The primary key of the relation consists of the union of the primary key of the strong entity set and the discriminator of the weak entity set. Relationship set. The union of the primary keys of the related entity sets becomes a super key of the relation. o For binary many-to-one relationship sets, the primary key of the many entity set becomes the relation s primary key. o For one-to-one relationship sets, the relation s primary key can be that of either entity set. o For many-to-many relationship sets, the union of the primary keys becomes the relation s primary key Schema Diagram for the Banking Enterprise 2.3 Query Languages Language in which user requests information from the database. Categories of languages procedural non-procedural Pure languages: Relational Algebra Tuple Relational Calculus Domain Relational Calculus Pure languages form underlying basis of query languages that people use Relational Algebra Procedural language Prepared by P.Vasantha Kumari 34

4 Six basic operators select project union set difference Cartesian product rename The operators take two or more relations as inputs and give a new relation as a result. (i)select Operation Notation: p(r) p is called the selection predicate Defined as: p(r) = {t t r and p(t)} Where p is a formula in propositional calculus consisting of terms connected by : (and), (or), (not) Each term is one of: <attribute> op <attribute> or <constant> where op is one of: =,, >,. <. Example of selection: branch-name= Perryridge (account) Select Operation Example (ii)project Operation Notation: A1, A2,, Ak (r) where A1, A2 are attribute names and r is a relation name. Prepared by P.Vasantha Kumari 35

5 The result is defined as the relation of k columns obtained by erasing the columns that are not listed Duplicate rows removed from result, since relations are sets E.g. To eliminate the branch-name attribute of account account-number, balance (account) Project Operation Example (iii)union Operation Notation: r s Defined as: r s = {t t r or t s} For r s to be valid. r, s must have the same arity (same number of attributes) The attribute domains must be compatible (e.g., 2nd column of r deals with the same type of values as does the 2nd column of s) E.g. to find all customers with either an account or a loan customer-name (depositor) customer-name (borrower) Prepared by P.Vasantha Kumari 36

6 Union Operation Example (iv) Set Difference Operation Notation r s Defined as: r s = {t t r and t s} Set differences must be taken between compatible relations. r and s must have the same arity attribute domains of r and s must be compatible Set Difference Operation Example (v) Cartesian-Product Operation Notation r x s Defined as: r x s = {t q t r and q s} Assume that attributes of r(r) and s(s) are disjoint. (That is, R S = ). If attributes of r(r) and s(s) are not disjoint, then renaming must be used. Prepared by P.Vasantha Kumari 37

7 Cartesian-Product Operation-Example (vi) Composition of Operations Can build expressions using multiple operations Example: A=C(r x s) r x s A=C(r x s) (vii) Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions. Allows us to refer to a relation by more than one name. Prepared by P.Vasantha Kumari 38

8 Example: x (E) returns the expression E under the name X If a relational-algebra expression E has arity n, then o x (A1, A2,, An) (E) returns the result of expression E under the name X, with the attributes renamed to A1, A2,., An. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-only) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number) Example Queries 1. Find all loans of over $1200 amount > 1200 (loan) 2. Find the loan number for each loan of an amount greater than $1200 loan-number ( amount > 1200 (loan)) 3. Find the names of all customers who have a loan, an account, or both, from the bank customer-name (borrower) customer-name (depositor) 4. Find the names of all customers who have a loan and an account at bank. customer-name (borrower) customer-name (depositor) 5. Find the names of all customers who have a loan at the Perryridge branch. customer-name ( branch-name= Perryridge ( borrower.loan-number = loan.loannumber(borrower x loan))) 6. Find the names of all customers who have a loan at the Perryridge branch but do not have an account at any branch of the bank. Prepared by P.Vasantha Kumari 39

9 customer-name ( branch-name = Perryridge ( borrower.loan-number = loan.loannumber(borrower x loan))) customer-name(depositor) 7. Find the names of all customers who have a loan at the Perryridge branch. customer-name( branch-name = Perryridge ( borrower.loan-number = loan.loannumber(borrower x loan))) (or) customer-name( loan.loan-number = borrower.loan-number(( branch-name = Perryridge (loan)) x borrower)) (viii) Formal Definition A basic expression in the relational algebra consists of either one of the following: A relation in the database A constant relation Let E1 and E2 be relational-algebra expressions; the following are all relational-algebra expressions: E1 E2 E1 - E2 E1 x E2 Additional Operations p (E1), P is a predicate on attributes in E1 s(e1), S is a list consisting of some of the attributes in E1 x (E1), x is the new name for the result of E1 We define additional operations that do not add any power to the relational algebra, but that simplify common queries. Set intersection Natural join Division Assignment (a) Set-Intersection Operation Notation: r Defined as: r s ={ t t r and t s } Assume: s r, s have the same arity Prepared by P.Vasantha Kumari 40

10 attributes of r and s are compatible Note: r s = r - (r - s) Set-Intersection Operation - Example (b) Natural-Join Operation Notation: r s Let r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R S obtained as follows: Consider each pair of tuples tr from r and ts from s. If tr and ts have the same value on each of the attributes in R result, where t has the same value as tr on r t has the same value as ts on s Example: R = (A, B, C, D) S = (E, B, D) Result schema = (A, B, C, D, E) r s is defined as: r.a, r.b, r.c, r.d, s.e ( r.b = s.b r.d = s.d (r x s)) Natural Join Operation Example S, add a tuple t to the Prepared by P.Vasantha Kumari 41

11 (c) Division Operation r s Suited to queries that include the phrase for all. Let r and s be relations on schemas R and S respectively where R = (A1,, Am, B1,, Bn) S = (B1,, Bn) The result of r s is a relation on schema R S = (A1,, Am) r s = { t t R-S(r) u s ( tu r ) } Division Operation Example Example Queries 1. Find all customers who have an account from at least the Downtown and the Uptown branches. CN( BN= Downtown (depositor account)) CN( BN= Uptown (depositor account)) where CN denotes customer-name and BN denotes branch-name. (or) customer-name, branch-name (depositor account) temp(branch-name) ({( Downtown ), ( Uptown )}) 2. Find all customers who have an account at all branches located in Brooklyn city. customer-name, branch-name (depositor account) branch-name ( branch-city = Brooklyn (branch)) Prepared by P.Vasantha Kumari 42

12 (ix)extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions Generalized Projection Extends the projection operation by allowing arithmetic functions to be used in the projection list. F1, F2,, Fn(E) E is any relational-algebra expression Each of F1, F2,, Fn are are arithmetic expressions involving constants and attributes in the schema of E. Given relation credit-info(customer-name, limit, credit-balance), find how much more each person can spend: customer-name, limit credit-balance (credit-info) Aggregate Functions and Operations Aggregation function takes a collection of values and returns a single value as a result. avg: average value min: minimum value max: maximum value sum: sum of values count: number of values Aggregate operation in relational algebra G1, G2,, Gn g F1( A1), F2( A2),, Fn( An) (E) E is any relational-algebra expression G1, G2, Gn is a list of attributes on which to group (can be empty) Each Fi is an aggregate function Each Ai is an attribute name Outer Join An extension of the join operation that avoids loss of information. Computes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join. Uses null values: null signifies that the value is unknown or does not exist Prepared by P.Vasantha Kumari 43

13 Outer Join Example All comparisons involving null are (roughly speaking) false by definition. Will study precise meaning of comparisons with nulls later Prepared by P.Vasantha Kumari 44

14 2.3.2 Domain Relational Calculus A nonprocedural query language equivalent in power to the tuple relational calculus Each query is an expression of the form: { x1, x2,, xn P(x1, x2,, xn)} o x1, x2,, xn represent domain variables o P represents a formula similar to that of the predicate calculus Example Queries 1. Find the loan-number, branch-name, and amount for loans of over $1200 { l, b, a l, b, a loan a > 1200} 2. Find the names of all customers who have a loan of over $1200 { c l, b, a ( c, l borrower l, b, a loan a > 1200)} 3. Find the names of all customers who have a loan from the Perryridge branch and the loan amount: { c, a l ( c, l borrower b( l, b, a loan b = Perryridge ))} or { c, a l ( c, l borrower l, Perryridge, a loan)} 4. Find the names of all customers having a loan, an account, or both at the Perryridge branch: { c l ({ c, l borrower b,a( l, b, a loan b = Perryridge )) a( c, a depositor b,n( a, b, n account b = Perryridge ))} 5. Find the names of all customers who have an account at all branches located in Brooklyn: { c s, n ( c, s, n customer) x,y,z( x, y, z branch y = Brooklyn ) a,b( x, y, z account c,a depositor)} Safety of Expressions { x1, x2,, xn P(x1, x2,, xn)}is safe if all of the following hold: 1.All values that appear in tuples of the expression are values from dom(p) (that is, the values appear either in P or in a tuple of a relation mentioned in P). 2.For every there exists subformula of the form x (P1(x)), the subformula is true if and only if there is a value of x in dom(p1) such that P1(x) is true. 3. For every for all subformula of the form x (P1 (x)), the subformula is true if and only if P1(x) is true for all values x from dom (P1). Prepared by P.Vasantha Kumari 45

15 2.3.3 Tuple Relational Calculus A nonprocedural query language, where each query is of the form {t P (t) } It is the set of all tuples t such that predicate P is true for t t is a tuple variable, t[a] denotes the value of tuple t on attribute A t r denotes that tuple t is in relation r P is a formula similar to that of the predicate calculus Predicate Calculus Formula Set of attributes and constants o Set of comparison operators: (e.g.,,,,,, ) o Set of connectives: and ( ), or (v) not ( ) o Implication ( ): x y, if x if true, then y is true o x y x v y o Set of quantifiers: o t r (Q(t)) there exists a tuple in t in relation r such that predicate Q(t) is true o t r (Q(t)) Q is true for all tuples t in relation r Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city) account (account-number, branch-name, balance) loan (loan-number, branch-name, amount) depositor (customer-name, account-number) borrower (customer-name, loan-number) Example Queries 1. Find the loan-number, branch-name, and amount for loans of over $1200 {t t loan t [amount] 1200} 2. Find the loan number for each loan of an amount greater than $1200 {t s loan (t[loan-number] = s[loan-number] s [amount] 1200)} 3.Find the names of all customers having a loan, an account, or both at the bank Prepared by P.Vasantha Kumari 46

16 {t s borrower( t[customer-name] = s[customer-name]) u depositor( t[customer-name] = u[customer-name]) 4.Find the names of all customers who have a loan and an account at the bank {t s borrower( t[customer-name] = s[customer-name]) u depositor( t[customer-name] = u[customer-name]) 5.Find the names of all customers having a loan at the Perryridge branch {t s borrower(t[customer-name] = s[customer-name] u loan(u[branch-name] = Perryridge u[loan-number] = s[loan-number]))} 6.Find the names of all customers who have a loan at the Perryridge branch, but no account at any branch of the bank {t s borrower( t[customer-name] = s[customer-name] u loan(u[branch-name] = Perryridge u[loan-number] = s[loan-number])) not v depositor (v[customer-name] = t[customername]) } 7.Find the names of all customers having a loan from the Perryridge branch, and the cities they live in {t s loan(s[branch-name] = Perryridge u borrower (u[loan-number] = s[loan-number] t [customer-name] = u[customer-name]) v customer (u[customer-name] = v[customername] t[customer-city] = v[customer-city])))} 8. Find the names of all customers who have an account at all branches located in Brooklyn: {t c customer (t[customer.name] = c[customer-name]) s branch(s[branch-city] = Brooklyn u account ( s[branch-name] = u[branch-name] s depositor ( t[customer-name] = s[customer-name] s[account-number] = u[account-number] )) )} Safety of Expressions It is possible to write tuple calculus expressions that generate infinite relations. For example, {t t r} results in an infinite relation if the domain of any attribute of relation r is infinite To guard against the problem, we restrict the set of allowable expressions to safe expressions. An expression {t P(t)} in the tuple relational calculus is safe if every component of t appears in one of the relations, tuples, or constants that appear in P Prepared by P.Vasantha Kumari 47

17 o NOTE: this is more than just a syntax condition. E.g. { t t[a]=5 true } is not safe --- it defines an infinite set with attribute values that do not appear in any relation or tuples or constants in P. 2.4 SQL fundamentals Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select A1, A2,..., An from r1, r2,..., rm where P Ais represent attributes, ris represent relations, P is a predicate. This query is equivalent to the relational algebra expression. A1, A2,..., An( P (r1 x r2 x... x rm)) The result of an SQL query is a relation. The select Clause The select clause list the attributes desired in the result of a query corresponds to the projection operation of the relational algebra E.g. find the names of all branches in the loan relation select branch-namefrom loan In the pure relational algebra syntax, the query would be: branch-name(loan) SQL allows duplicates in relations as well as in query results. To force the elimination of duplicates, insert the keyword distinct after select. Find the names of all branches in the loan relations, and remove duplicates select distinct branch-name from loan The keyword all specifies that duplicates not be removed. select all branch-name from loan An asterisk in the select clause denotes all attributes select * from loan The select clause can contain arithmetic expressions involving the operation, +,,, and /, and operating on constants or attributes of tuples. The query: select loan-number, branch-name, amount 100 from loan would return a relation which is the same as the loan relations, except that the attribute amount is multiplied by 100. Prepared by P.Vasantha Kumari 48

18 The where Clause The where clause specifies conditions that the result must satisfy corresponds to the selection predicate of the relational algebra. To find all loan number for loans made at the Perryridge branch with loan amounts greater than $1200. select loan-numberfrom loan where branch-name = Perryridge and amount > 1200 Comparison results can be combined using the logical connectives and, or, and not. Comparisons can be applied to results of arithmetic expressions. SQL includes a between comparison operator E.g. Find the loan number of those loans with loan amounts between $90,000 and $100,000 (that is, $90,000 and $100,000) select loan-numberfrom loan where amount between and The from Clause The from clause lists the relations involved in the query corresponds to the Cartesian product operation of the relational algebra. Find the Cartesian product borrower x loan select from borrower, loan Find the name, loan number and loan amount of all customers having a loan at the Perryridge branch. select customer-name, borrower.loan-number, amountfrom borrower, loan where borrower.loan-number = loan.loan-number and branch-name = Perryridge The Rename Operation The SQL allows renaming relations and attributes using the as clause: old-name as new-name Find the name, loan number and loan amount of all customers; rename the column name loannumber as loan-id. select customer-name, borrower.loan-number as loan-id, amount from borrower, loan where borrower.loan-number = loan.loan-number Tuple Variables Tuple variables are defined in the from clause via the use of the as clause. Find the customer names and their loan numbers for all customers having a loan at some branch. Prepared by P.Vasantha Kumari 49

19 select customer-name, T.loan-number, S.amount from borrower as T, loan as S where T.loan-number = S.loan-number Find the names of all branches that have greater assets than some branch located in Brooklyn. select distinct T.branch-name from branch as T, branch as S where T.assets > S.assets and S.branch-city = Brooklyn String Operations SQL includes a string-matching operator for comparisons on character strings. Patterns are described using two special characters: percent (%). The % character matches any substring. underscore (_). The _ character matches any character. Find the names of all customers whose street includes the substring Main. select customer-name from customer where customer-street like %Main% Match the name Main% like Main\% escape \ SQL supports a variety of string operations such as concatenation (using ) converting from upper to lower case (and vice versa) finding string length, extracting substrings, etc. Ordering the Display of Tuples List in alphabetic order the names of all customers having a loan in Perryridge branch select distinct customer-name from borrower, loan where borrower loan-number - loan.loannumber and branch-name = Perryridge order by customer-name We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default. E.g. order by customer-name desc Duplicates In relations with duplicates, SQL can define how many copies of tuples appear in the result. Multiset versions of some of the relational algebra operators given multiset relations r1 and r2: (r1): If there are c1 copies of tuple t1 in r1, and t1 satisfies selections,, then there are c1 copies of t1 in (r1). A(r): For each copy of tuple t1 in r1, there is a copy of tuple A(t1) in A(r1) where A(t1) denotes the projection of the single tuple t1. Prepared by P.Vasantha Kumari 50

20 r1 x r2 : If there are c1 copies of tuple t1 in r1 and c2 copies of tuple t2 in r2, there are c1 x c2 copies of the tuple t1. t2 in r1 x r2 Example: Suppose multiset relations r1 (A, B) and r2 (C) are as follows: r1 = {(1, a) (2,a)} r2 = {(2), (3), (3)} Then B(r1) would be {(a), (a)}, while B(r1) x r2 would be {(a,2), (a,2), (a,3), (a,3), (a,3), (a,3)} SQL duplicate semantics: select A1,, A2,..., An from r1, r2,..., rm where P is equivalent to the multiset version of the expression: A1,, A2,..., An( P (r1 x r2 x... x rm)) Set Operations The set operations union, intersect, and except operate on relations and correspond to the relational algebra operations Each of the above operations automatically eliminates duplicates; to retain all duplicates use the corresponding multiset versions union all, intersect all and except all. Suppose a tuple occurs m times in r and n times in s, then, it occurs: m + n times in r union all s min(m,n) times in r intersect all s max(0, m n) times in r except all s Aggregate Functions These functions operate on the multiset of values of a column of a relation, and return a value avg: average value min: minimum value max: maximum value sum: sum of values count: number of values Aggregate Functions Group By Find the number of depositors for each branch. select branch-name, count (distinct customer-name) from depositor, account where depositor.account-number = account.account-numbergroup by branch-name Note: Attributes in select clause outside of aggregate functions must appear in group by list Aggregate Functions Having Clause Prepared by P.Vasantha Kumari 51

21 Find the names of all branches where the average account balance is more than $1,200. select branch-name, avg (balance)from accountgroup by branch-namehaving avg (balance) > 1200 Note: predicates in the having clause are applied after the formation of groups whereas predicates in the where clause are applied before forming groups Null Values It is possible for tuples to have a null value, denoted by null, for some of their attributes null signifies an unknown value or that a value does not exist. The predicate is null can be used to check for null values. E.g. Find all loan number which appear in the loan relation with null values for amount. select loan-number from loan where amount is null The result of any arithmetic expression involving null is null E.g. 5 + null returns null However, aggregate functions simply ignore nulls more on this shortly Nested Subqueries SQL provides a mechanism for the nesting of subqueries. A subquery is a select-from-where expression that is nested within another query.a common use of subqueries is to perform tests for set membership, set comparisons, and set cardinality Example Query 1.Find all customers who have both an account and a loan at the bank. select distinct customer-namefrom borrower where customer-name in (select customer-name from depositor) 2. Find all customers who have a loan at the bank but do not have an account at the bank select distinct customer-namefrom borrowerwhere customer-name not in (select customer-name from depositor) 3.Find all customers who have both an account and a loan at the Perryridge branch select distinct customer-namefrom borrower, loanwhere borrower.loan-number = loan.loannumber and branch-name = Perryridge and (branch-name, customer-name) in (select branchname, customer-name from depositor, account where depositor.account-number = account.account-number) Set Comparison Prepared by P.Vasantha Kumari 52

22 Find all branches that have greater assets than some branch located in Brooklyn. select distinct T.branch-name from branch as T, branch as S where T.assets > S.assets and S.branch-city = Brooklyn 2.5 Integrity Domain Constraints Integrity constraints guard against accidental damage to the database, by ensuring that authorized changes to the database do not result in a loss of data consistency. Domain constraints are the most elementary form of integrity constraint. They test values inserted in the database, and test queries to ensure that the comparisons make sense. New domains can be created from existing data types E.g. create domain Dollars numeric(12, 2) create domain Pounds numeric(12,2) We cannot assign or compare a value of type Dollars to a value of type Pounds. However, we can convert type as below (cast r.a as Pounds) Should also multiply by the dollar-to-pound conversion-rate) The check clause in SQL-92 permits domains to be restricted: Use check clause to ensure that an hourly-wage domain allows only values greater than a specified value. create domain hourly-wage numeric(5,2)constraint value-test check(value > = 4.00) The domain has a constraint that ensures that the hourly-wage is greater than 4.00 The clause constraint value-test is optional; useful to indicate which constraint an update violated can have complex conditions in domain check create domain AccountType char(10) constraint account-type-test check (value in ( Checking, Saving ))check (branch-name in (select branch-name from branch)) Referential Integrity Ensures that a value that appears in one relation for a given set of attributes also appears for a certain set of attributes in another relation. Example: If Perryridge is a branch name appearing in one of the tuples in the account relation, then there exists a tuple in the branch relation for branch Perryridge. Formal Definition Let r1(r1) and r2(r2) be relations with primary keys K1 and K2 respectively. Prepared by P.Vasantha Kumari 53

23 The subset of R2 is a foreign key referencing K1 in relation r1, if for every t2 in r2 there must be a tuple t1 in r1 such that t1[k1] = t2[ ]. Referential integrity constraint also called subset dependency since its can be written as (r2) K1 (r1) Referential Integrity in the E-R Model Consider relationship set R between entity sets E1 and E2. The relational schema for R includes the primary keys K1 of E1 and K2 of E2. Then K1 and K2 form foreign keys on the relational schemas for E1 and E2 respectively. E 1 R E 2 Weak entity sets are also a source of referential integrity constraints. For the relation schema for a weak entity set must include the primary key attributes of the entity set on which it depends Checking Referential Integrity on Database Modification The following tests must be made in order to preserve the following referential integrity constraint: (r2) K (r1) Insert. If a tuple t2 is inserted into r2, the system must ensure that there is a tuple t1 in r1 such that t1[k] = t2[ ]. That is t2 [ ] K (r1) Delete. If a tuple, t1 is deleted from r1, the system must compute the set of tuples in r2 that reference t1: = t1[k] (r2) If this set is not empty either the delete command is rejected as an error, or the tuples that reference t1 must themselves be deleted (cascading deletions are possible). Update. There are two cases: If a tuple t2 is updated in relation r2 and the update modifies values for foreign key, then a test similar to the insert case is made: Let t2 denote the new value of tuple t2. The system must ensure that t2 [ ] K(r1).If a tuple t1 is updated in r1, and the update modifies values for the primary key (K), then a test similar to the delete case is made: The system must compute = t1[k] (r2) using the old value of t1 (the value before the update is applied). If this set is not empty, the update may be rejected as an error, or the update may be cascaded to the tuples in the set, or the tuples in the set may be deleted. Prepared by P.Vasantha Kumari 54

24 Referential Integrity in SQL Primary and candidate keys and foreign keys can be specified as part of the SQL create table statement: The primary key clause lists attributes that comprise the primary key. The unique key clause lists attributes that comprise a candidate key. The foreign key clause lists the attributes that comprise the foreign key and the name of the relation referenced by the foreign key. By default, a foreign key references the primary key attributes of the referenced table foreign key (account-number) references account Short form for specifying a single column as foreign key account-number char (10) references account Reference columns in the referenced table can be explicitly specified but must be declared as primary/candidate keys foreign key (account-number) references account(account-number) 2.6 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 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 create trigger overdraft-trigger after update on account referencing new row as nrow for each row when nrow.balance < 0 begin atomic insert into borrower Prepared by P.Vasantha Kumari 55

25 (select customer-name, account-number from depositor where nrow.account-number = depositor.account-number); insert into loan values (n.row.account-number, nrow.branch-name, nrow.balance); update account set balance = 0 where account.account-number = nrow.account-number end Triggering Events and Actions in SQL Triggering event can be insert, delete or update Triggers on update can be restricted to specific attributes E.g. create trigger overdraft-trigger after update of balance on account Values of attributes before and after an update can be referenced referencing old row as : for deletes and updates referencing new row as : for inserts and updates Triggers can be activated before an event, which can serve as extra constraints. E.g. convert blanks to null. create trigger setnull-trigger before update on r referencing new row as nrow for each row when nrow.phone-number = set nrow.phone-number = null 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 built-in support for replication,encapsulation facilities can be used instead of triggers in many cases, Define methods to update fields and carry out actions as part of the update methods instead of through a trigger. Prepared by P.Vasantha Kumari 56

26 2.7 Security Security - protection from malicious attempts to steal or modify data. o Database system level Authentication and authorization mechanisms to allow specific users access only to required data We concentrate on authorization in the rest of this chapter o Operating system level Operating system super-users can do anything they want to the database! Good operating system level security is required. o Network level: must use encryption to prevent Eavesdropping (unauthorized reading of messages) Masquerading (pretending to be an authorized user or sending messages supposedly from authorized users) o Physical level Physical access to computers allows destruction of data by intruders; traditional lock-and-key security is needed Computers must also be protected from floods, fire, etc. More in Chapter 17 (Recovery) o Human level Users must be screened to ensure that an authorized users do not give access to intruders Users should be trained on password selection and secrecy Authorization Forms of authorization on parts of the database: Read authorization - allows reading, but not modification of data. Insert authorization - allows insertion of new data, but not modification of existing data. Update authorization - allows modification, but not deletion of data. Delete authorization - allows deletion of data Forms of authorization to modify the database schema: Index authorization - allows creation and deletion of indices. Resources authorization - allows creation of new relations. Prepared by P.Vasantha Kumari 57

27 Alteration authorization - allows addition or deletion of attributes in a relation. Drop authorization - allows deletion of relations. Authorization and Views Users can be given authorization on views, without being given any authorization on the relations used in the view definition Ability of views to hide data serves both to simplify usage of the system and to enhance security by allowing users access only to data they need for their job A combination or relational-level security and view-level security can be used to limit a user s access to precisely the data that user needs. Audit Trails An audit trail is a log of all changes (inserts/deletes/updates) to the database along with information such as which user performed the change, and when the change was performed. Used to track erroneous/fraudulent updates. Can be implemented using triggers, but many database systems provide direct support. Encryption Data may be encrypted when database authorization provisions do not offer sufficient protection. Relatively simple for authorized users to encrypt and decrypt data. Encryption scheme depends not on the secrecy of the algorithm but on the secrecy of a parameter of the algorithm called the encryption key. Extremely difficult for an intruder to determine the encryption key. Data Encryption Standard (DES) substitutes characters and rearranges their order on the basis of an encryption key which is provided to authorized users via a secure mechanism. Scheme is no more secure than the key transmission mechanism since the key has to be shared. Advanced Encryption Standard (AES) is a new standard replacing DES, and is based on the Rijndael algorithm, but is also dependent on shared secret keys Public-key encryption is based on each user having two keys: public key publicly published key used to encrypt data, but cannot be used to decrypt data private key -- key known only to individual user, and used to decrypt data. Need not be transmitted to the site doing encryption. Encryption scheme is such that it is impossible or extremely hard to decrypt data given only the public key. Prepared by P.Vasantha Kumari 58

28 The RSA public-key encryption scheme is based on the hardness of factoring a very large number (100's of digits) into its prime components. Authentication Password based authentication is widely used, but is susceptible to sniffing on a network Challenge-response systems avoid transmission of passwords DB sends a (randomly generated) challenge string to user. User encrypts string and returns result. DB verifies identity by decrypting result. It can use public-key encryption system by DB sending a message encrypted using user s public key, and user decrypting and sending the message back Digital signatures are used to verify authenticity of data E.g. use private key (in reverse) to encrypt data, and anyone can verify authenticity by using public key (in reverse) to decrypt data. Only holder of private key could have created the encrypted data. Digital signatures also help ensure nonrepudiation: sender cannot later claim to have not created the data Digital Certificates Digital certificates are used to verify authenticity of public keys. Every client (e.g. browser) has public keys of a few root-level certification authorities A site can get its name/url and public key signed by a certification authority: signed document is called a certificate Client can use public key of certification authority to verify certificate Multiple levels of certification authorities can exist. Each certification authority presents its own public-key certificate signed by a higher level authority, and uses its private key to sign the certificate of other web sites/authorities 2.8 Embedded SQL The SQL standard defines embeddings of SQL in a variety of programming languages such as Pascal, PL/I, Fortran, C, and Cobol. A language to which SQL queries are embedded is referred to as a host language, and the SQL structures permitted in the host language comprise embedded SQL. The basic form of these languages follows that of the System R embedding of SQL into PL/I. EXEC SQL statement is used to identify embedded SQL request to the preprocessor Prepared by P.Vasantha Kumari 59

29 EXEC SQL <embedded SQL statement > END-EXEC Note: this varies by language. E.g. the Java embedding uses # SQL {. } ; Example Query From within a host language, find the names and cities of customers with more than the variable amount dollars in some account. It specify the query in SQL and declare a cursor for it EXEC SQL declare c cursor for select customer-name, customer-city from depositor, customer, account where depositor.customer-name = customer.customer-name and depositor account-number = account.account-number and account.balance > :amount END-EXEC The open statement causes the query to be evaluated EXEC SQL open c END-EXEC The fetch statement causes the values of one tuple in the query result to be placed on host language variables. EXEC SQL fetch c into :cn, :cc END-EXEC Repeated calls to fetch get successive tuples in the query result A variable called SQLSTATE in the SQL communication area (SQLCA) gets set to to indicate no more data is available The close statement causes the database system to delete the temporary relation that holds the result of the query. EXEC SQL close c END-EXEC Note: above details vary with language. E.g. the Java embedding defines Java iterators to step through result tuples. 2.9 Dynamic SQL Allows programs to construct and submit SQL queries at run time. Example of the use of dynamic SQL from within a C program. char * sqlprog = update account set balance = balance * 1.05 where account-number =? EXEC SQL prepare dynprog from :sqlprog; Prepared by P.Vasantha Kumari 60

30 char account [10] = A-101 ; EXEC SQL execute dynprog using :account; The dynamic SQL program contains a?, which is a place holder for a value that is provided when the SQL program is executed. ODBC Open DataBase Connectivity(ODBC) standard o standard for application program to communicate with a database server. o application program interface (API) to open a connection with a database, send queries and updates, get back results. Applications such as GUI, spreadsheets, etc. can use ODBC Each database system supporting ODBC provides a "driver" library that must be linked with the client program. When client program makes an ODBC API call, the code in the library communicates with the server to carry out the requested action, and fetch results. ODBC program first allocates an SQL environment, then a database connection handle. Opens database connection using SQLConnect(). Parameters for SQLConnect: o connection handle, o the server to which to connect o the user identifier, o password Must also specify types of arguments: o SQL_NTS denotes previous argument is a null-terminated string. ODBC Code int ODBCexample() { RETCODE error; HENV env; /* environment */ HDBC conn; /* database connection */ SQLAllocEnv(&env); SQLAllocConnect(env, &conn); Prepared by P.Vasantha Kumari 61

31 SQLConnect(conn, "aura.bell-labs.com", SQL_NTS, "avi", SQL_NTS, "avipasswd", SQL_NTS); {. Do actual work } SQLDisconnect(conn); SQLFreeConnect(conn); SQLFreeEnv(env); } Program sends SQL commands to the database by using SQLExecDirect Result tuples are fetched using SQLFetch() SQLBindCol() binds C language variables to attributes of the query result When a tuple is fetched, its attribute values are automatically stored in corresponding C variables. Arguments to SQLBindCol() ODBC stmt variable, attribute position in query result The type conversion from SQL to C. The address of the variable. For variable-length types like character arrays, o The maximum length of the variable o Location to store actual length when a tuple is fetched. o Note: A negative value returned for the length field indicates null value Good programming requires checking results of every function call for errors; we have omitted most checks for brevity. JDBC JDBC is a Java API for communicating with database systems supporting SQL JDBC supports a variety of features for querying and updating data, and for retrieving query results JDBC also supports metadata retrieval, such as querying about relations present in the database and the names and types of relation attributes Model for communicating with the database: o Open a connection o Create a statement object Prepared by P.Vasantha Kumari 62

32 o Execute queries using the Statement object to send queries and fetch results o Exception mechanism to handle errors JDBC Code public static void JDBCexample(String dbid, String userid, String passwd) { try { Class.forName ("oracle.jdbc.driver.oracledriver"); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@aura.belllabs.com:2000:bankdb", userid, passwd); Statement stmt = conn.createstatement(); Do Actual Work. stmt.close(); conn.close(); } catch (SQLException sqle) { System.out.println("SQLException : " + sqle); } } Update to database try { stmt.executeupdate( "insert into account values ('A-9732', 'Perryridge', 1200)"); } catch (SQLException sqle) { System.out.println("Could not insert tuple. " + sqle); } Execute query and fetch and print results ResultSet rset = stmt.executequery( "select branch_name, avg(balance) from account group by branch_name"); while (rset.next()) { System.out.println(rset.getString("branch_name") + " " + rset.getfloat(2)); } Prepared by P.Vasantha Kumari 63

33 2.10 Views Provide a mechanism to hide certain data from the view of certain users. To create a view we use the command:where: Example Queries o <query expression> is any legal expression o The view name is represented by v A view consisting of branches and their customers create view all-customer as (select branch-name, customer-name from depositor, account where depositor.account-number = account.account-number) union (select branch-name, customer-name from borrower, loan where borrower.loan-number = loan.loan-number) Find all customers of the Perryridge branch select customer-name 2.11 Distributed Databases from all-customer where branch-name = Perryridge Data is stored at several sites, each managed by a DBMS that can run independently. Distributed Data Independence: Users should not have to know where data is located (extends Physical and Logical Data Independence principles). Distributed Transaction Atomicity: Users should be able to write Xacts accessing multiple sites just like local Xacts. Users have to be aware of where data is located, i.e., Distributed Data Independence and Distributed Transaction Atomicity are not supported. These properties are hard to support efficiently. For globally distributed sites, these properties may not even be desirable due to administrative overheads of making location of data transparent. Types of Distributed Databases 1.Homogeneous: Every site runs same type of DBMS. 2.Heterogeneous: Different sites run different DBMSs (different RDBMSs or even nonrelational DBMSs). Prepared by P.Vasantha Kumari 64

34 Distributed DBMS Architectures (i) Client-Server:Client ships query to single site. All query processing at server. - Thin vs. fat clients. - Set-oriented communication, client side caching. (ii) Collaborating-Server: Query can span multiple sites. Prepared by P.Vasantha Kumari 65

35 Summary SQL includes a variety of language constructs for queries on the database. All the relationalalgebra operations, including the extended relational-algebra operations, can be expressed by SQL. SQL also allows ordering of query results by sorting on specified attributes. View relations can be defined as relations containing the result of queries. Views are useful for hiding unneeded information, and for collecting together information from more than one relation into a single view. Temporary views defined by using the with clause are also useful for breaking up complex queries into smaller and easier-to-understand parts. SQL provides constructs for updating, inserting, and deleting information. A transaction consists of a sequence of operations, which must appear to be atomic. That is, all the operations are carried out successfully, or none is carried out. In practice, if a transaction cannot complete successfully, any partial actions it carried out are undone. Modifications to the database may lead to the generation of null values in tuples. We discussed how nulls can be introduced, and how the SQL query language handles queries on relations containing null values. Key Terms >> Table >> Relation >> Tuple variable >> Atomic domain >> Null value >> Database schema >> Database instance >> Relation schema >> Relation instance >>Keys >>Foreign key >>Schema diagram >>Query language >>Procedural language >>Nonprocedural language >>Relational algebra Key Term Quiz 1. The defines a set of algebraic operations that operate on tables, and output tables as their results. 2. Views are is an example for nonprocedural languages 4. The set of allowed values for each attribute is called which signifies that the value is unknown or does not exist 6. A language is a language in which a user requests information from the database. 7. The user instructs the system to perform a sequence of operations on the database to compute the desired result. In a nonprocedural language Prepared by P.Vasantha Kumari 66

36 8. The user describes the desired information without giving a specific procedure for obtaining that information. Objective Type Questions 1. What is the SQL command to end a transaction? a. COMMIT b. ROLLBACK c. END d. ENTER 2. Prime and non prime attributes are a. part of any candidate key and not part of candidate key b. not part of any candidate key and part of candidate key c. both part of any candidate key d. both not part of candidate key 3. Any set of attributes of a relation schema is called a. an alternate key b. a candidate key c. a primary key d. a superkey 4. What is SQL stands for? a. Standard Query Language b. Structured Query Language c. Structured Questioning Language d. Structural Query Language e. None of the above. 5. SQL command SELECT is a a. DDL b. DML c. DCL 6. What is the SQL command to end a transaction a. COMMIT b. ROLLBACK c. END d. ENTER 7. Which is the command to remove a database a. DELETE b. DROP c. None of the above 8. Which of the following is True? (i)character " _" stands for one character (ii)character "%" stands for more than one character (iii)character " _" stands for more than one character (iv)character "%" stands for one character a. Both i and ii b. Only i c. Only ii d. Both iii and iv 9. Which one is valid? Prepared by P.Vasantha Kumari 67

37 a. SELECT [ALL DISTINCT]column_list FROM table_list [WHERE conditional expression] [GROUP BY group_by_column_list] [HAVING conditional expression][order BY order_by_column_list] b. SELECT [ALL DISTINCT]column_list FROM table_list [WHERE conditional expression] [GROUP BY group_by_column_list] [HAVING conditional expression][order BY order_by_column_list]; c. SELECT [ALL DISTINCT]column_list FROM table_list [WHERE conditional expression] [GROUP BY group_by_column_list] [HAVING conditional expression][order order_column_list] d. SELECT [ALL DISTINCT]row_list FROM table_list [WHERE conditional expression] [GROUP BY group_by_column_list] [HAVING conditional expression][order BY order_by_column_list] e. All of the above. f. None of the above. 10. Which of the following allows SQL statements to inserted into host languages? a. Embedded SQL b. QBE c. C d. Linker e. All of the above 11. Host variable when used within the Embedded SQL statement need to be prefixed with colon(:) a. True b. False 12. Pick out the correct format of Date value a. yyyy-dd-mm b. yyyy-mm-dd c. dd-mm-yyyy d. mm-dd-yyyy 13. Which of the following is not a data type in SQL? a. Char b. Varchar c. String d. Long 14. The optional keyword that helps to get the answer not in a duplicate way a. GROUP b. COUNT c. ORDER d. DISTINCT e. None of the above 15. Which of the following is a set comparison operator similar to IN? a. REFERENCE b. EXISTS c. LIKE d. GROUP e. All of the above 16. In SQL notation,lower case letter is used to represent reserved words a. True b. False 17. "A change in the organization of records in a table from clustered to nonclustered does not affect the front-end application program." This is an example of a. Data integrity b. Data independence c. Data isolation d. Data consistency 18. Consider the relation: Student_Course (Student#, Course, Marks) Assuming that Marks column contains marks in percentage, which of the following query can be written to retrieve the total marks of the students who have average marks > 75 %? a. SELECT Student#, SUM(Marks) FROM Student_Course HAVING Avg(Marks) > 75; Prepared by P.Vasantha Kumari 68

Chapter 3: Relational Model

Chapter 3: Relational Model Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database

More information

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016

CS34800 Information Systems. The Relational Model Prof. Walid Aref 29 August, 2016 CS34800 Information Systems The Relational Model Prof. Walid Aref 29 August, 2016 1 Chapter: The Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational

More information

Upon completion of this Unit, students will be introduced to the following

Upon completion of this Unit, students will be introduced to the following Instructional Objectives Upon completion of this Unit, students will be introduced to the following The origins of the relational model. The terminology of the relational model. How tables are used to

More information

Chapter 4: SQL. Basic Structure

Chapter 4: SQL. Basic Structure Chapter 4: 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

More information

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers Security Authorization Authorization in SQL 6.1 Domain Constraints Integrity constraints guard against accidental

More information

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University Lecture 3 SQL Shuigeng Zhou September 23, 2008 School of Computer Science Fudan University Outline Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views

More information

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition Language 4.1 Schema Used in Examples

More information

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure. SL Lecture 4 SL Chapter 4 (Sections 4.1, 4.2, 4.3, 4.4, 4.5, 4., 4.8, 4.9, 4.11) Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Modification of the Database

More information

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

More information

DATABASE TECHNOLOGY - 1MB025

DATABASE TECHNOLOGY - 1MB025 1 DATABASE TECHNOLOGY - 1MB025 Fall 2005 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-ht2005/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht05/ Kjell Orsborn Uppsala

More information

DATABASE TECHNOLOGY - 1MB025

DATABASE TECHNOLOGY - 1MB025 1 DATABASE TECHNOLOGY - 1MB025 Fall 2004 An introductory course on database systems http://user.it.uu.se/~udbl/dbt-ht2004/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/ht04/ Kjell Orsborn Uppsala

More information

DATABASTEKNIK - 1DL116

DATABASTEKNIK - 1DL116 1 DATABASTEKNIK - 1DL116 Spring 2004 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2004/ Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala

More information

Chapter 6: Integrity and Security.! Domain Constraints! Referential Integrity! Assertions! Triggers! Security! Authorization! Authorization in SQL

Chapter 6: Integrity and Security.! Domain Constraints! Referential Integrity! Assertions! Triggers! Security! Authorization! Authorization in SQL Chapter 6: Integrity and Security! Domain Constraints! Referential Integrity! Assertions! Triggers! Security! Authorization! Authorization in SQL 6.1 Domain Constraints! Integrity constraints guard against

More information

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU Relational Algebra 1 Structure of Relational Databases A relational database consists of a collection of tables, each of which is assigned a unique name. A row in a table represents a relationship among

More information

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Structure of Relational Databases! Fundamental Relational-Algebra-Operations! Additional

More information

Chapter 6: Formal Relational Query Languages

Chapter 6: Formal Relational Query Languages Chapter 6: Formal Relational Query Languages Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 6: Formal Relational Query Languages Relational Algebra Tuple Relational

More information

Chapter 4: SQL Database System Concepts 4.1 Silberschatz, Korth and Sudarshan

Chapter 4: SQL Database System Concepts 4.1 Silberschatz, Korth and Sudarshan Chapter 4: SQL! Basic Structure! Set Operations! Aggregate Functions! Null Values! Nested Subqueries! Derived Relations! Views! Modification of the Database! Joined Relations! Data Definition Language!

More information

UNIT- II (Relational Data Model & Introduction to SQL)

UNIT- II (Relational Data Model & Introduction to SQL) Database Management System 1 (NCS-502) UNIT- II (Relational Data Model & Introduction to SQL) 2.1 INTRODUCTION: 2.1.1 Database Concept: 2.1.2 Database Schema 2.2 INTEGRITY CONSTRAINTS: 2.2.1 Domain Integrity:

More information

Database System Concepts

Database System Concepts s Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and Sudarshan. Chapter 2: Model Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2009/2010

More information

Silberschatz, Korth and Sudarshan See for conditions on re-use

Silberschatz, Korth and Sudarshan See   for conditions on re-use Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See  for conditions on re-use Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

Chapter 3: SQL. Chapter 3: SQL

Chapter 3: SQL. Chapter 3: SQL Chapter 3: SQL Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 3: SQL Data Definition Basic Query Structure Set Operations Aggregate Functions Null Values Nested

More information

DATABASE DESIGN I - 1DL300

DATABASE DESIGN I - 1DL300 DATABASE DESIGN I - 1DL300 Fall 2010 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht10/ Manivasakan Sabesan Uppsala Database Laboratory Department of Information

More information

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation!

Textbook: Chapter 6! CS425 Fall 2013 Boris Glavic! Chapter 3: Formal Relational Query. Relational Algebra! Select Operation Example! Select Operation! Chapter 3: Formal Relational Query Languages CS425 Fall 2013 Boris Glavic Chapter 3: Formal Relational Query Languages Relational Algebra Tuple Relational Calculus Domain Relational Calculus Textbook:

More information

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See   for conditions on re-use Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Data Definition! Basic Query Structure! Set Operations! Aggregate Functions! Null Values!

More information

DATABASE TECHNOLOGY. Spring An introduction to database systems

DATABASE TECHNOLOGY. Spring An introduction to database systems 1 DATABASE TECHNOLOGY Spring 2007 An introduction to database systems Kjell Orsborn Uppsala Database Laboratory Department of Information Technology, Uppsala University, Uppsala, Sweden 2 Introduction

More information

QQ Group

QQ Group QQ Group: 617230453 1 Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join 2 Generalized Projection Extends the projection operation by allowing arithmetic functions

More information

Chapter 4: Advanced SQL

Chapter 4: Advanced SQL Chapter 4: Advanced SQL Chapter 4: Advanced SQL SQL Data Types and Schemas Integrity Constraints Authorization Embedded SQL Dynamic SQL Functions and Procedural Constructs** Recursive Queries** Advanced

More information

The SQL database language Parts of the SQL language

The SQL database language Parts of the SQL language DATABASE DESIGN I - 1DL300 Fall 2011 Introduction to SQL Elmasri/Navathe ch 4,5 Padron-McCarthy/Risch ch 7,8,9 An introductory course on database systems http://www.it.uu.se/edu/course/homepage/dbastekn/ht11

More information

Simple SQL Queries (2)

Simple SQL Queries (2) Simple SQL Queries (2) Review SQL the structured query language for relational databases DDL: data definition language DML: data manipulation language Create and maintain tables CMPT 354: Database I --

More information

How to program applications. CS 2550 / Spring 2006 Principles of Database Systems. SQL is not enough. Roadmap

How to program applications. CS 2550 / Spring 2006 Principles of Database Systems. SQL is not enough. Roadmap How to program applications CS 2550 / Spring 2006 Principles of Database Systems 05 SQL Programming Using existing languages: Embed SQL into Host language ESQL, SQLJ Use a library of functions Design a

More information

Database Systems SQL SL03

Database Systems SQL SL03 Inf4Oec10, SL03 1/52 M. Böhlen, ifi@uzh Informatik für Ökonomen II Fall 2010 Database Systems SQL SL03 Data Definition Language Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates,

More information

DATABASDESIGN FÖR INGENJÖRER - 1DL124

DATABASDESIGN FÖR INGENJÖRER - 1DL124 1 DATABASDESIGN FÖR INGENJÖRER - 1DL124 Sommar 2005 En introduktionskurs i databassystem http://user.it.uu.se/~udbl/dbt-sommar05/ alt. http://www.it.uu.se/edu/course/homepage/dbdesign/st05/ Kjell Orsborn

More information

Database Systems SQL SL03

Database Systems SQL SL03 Checking... Informatik für Ökonomen II Fall 2010 Data Definition Language Database Systems SQL SL03 Table Expressions, Query Specifications, Query Expressions Subqueries, Duplicates, Null Values Modification

More information

Relational Algebra. Procedural language Six basic operators

Relational Algebra. Procedural language Six basic operators Relational algebra Relational Algebra Procedural language Six basic operators select: σ project: union: set difference: Cartesian product: x rename: ρ The operators take one or two relations as inputs

More information

User Interfaces and Tools. Web Interfaces to Database (Cont.) Web Interfaces to Databases. Client Side Scripting and Applets.

User Interfaces and Tools. Web Interfaces to Database (Cont.) Web Interfaces to Databases. Client Side Scripting and Applets. Ch 8: Application Design and Development User Interfaces and Tools Web Interfaces to Databases Web Fundamentals Servlets and JSP Building Large Web Applications Triggers Authorization in SQL Application

More information

Chapter 5: Other Relational Languages

Chapter 5: Other Relational Languages Chapter 5: Other Relational Languages Database System Concepts, 5th Ed. See www.db-book.com for conditions on re-use Chapter 5: Other Relational Languages Tuple Relational Calculus Domain Relational Calculus

More information

Database System Concepts

Database System Concepts Chapter 4(+8): Advanced SQL Departamento de Engenharia Informática Instituto Superior Técnico 1 st Semester 2007/2008 Slides (fortemente) baseados nos slides oficiais do livro c Silberschatz, Korth and

More information

Integrity and Security

Integrity and Security C H A P T E R 6 Integrity and Security This chapter presents several types of integrity constraints, including domain constraints, referential integrity constraints, assertions and triggers, as well as

More information

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

A database can be modeled as: + a collection of entities, + a set of relationships among entities. The Relational Model Lecture 2 The Entity-Relationship Model and its Translation to the Relational Model Entity-Relationship (ER) Model + Entity Sets + Relationship Sets + Database Design Issues + Mapping

More information

Database System Concepts"

Database System Concepts Database System Concepts! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Database System Concepts" User Interfaces and Tools! Web Interfaces to Databases! Web Fundamentals!

More information

SQL Interview Questions

SQL Interview Questions SQL Interview Questions SQL stands for Structured Query Language. It is used as a programming language for querying Relational Database Management Systems. In this tutorial, we shall go through the basic

More information

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400) 1 DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400) Spring 2008 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-vt2008/ alt. http://www.it.uu.se/edu/course/homepage/dbastekn/vt08/

More information

DATABASE DESIGN - 1DL400

DATABASE DESIGN - 1DL400 DATABASE DESIGN - 1DL400 Spring 2012 A course on modern database systems http://www.it.uu.se/edu/course/homepage/dbastekn2/vt12/ Tore Risch Uppsala Database Laboratory Department of Information Technology,

More information

Lecture 4 Advanced SQL

Lecture 4 Advanced SQL Lecture 4 Advanced SQL Shuigeng Zhou March 20, 2013 School of Computer Science Fudan University Outline SQL data types and schemas Domain Constraints ( 域约束 ) Referential Integrity ( 引用完整性 ) Assertions

More information

Chapter 8: Application Design and Development

Chapter 8: Application Design and Development Chapter 8: Application Design and Development Database System Concepts See www.db-book.com for conditions on re-use Database System Concepts Chapter 8: Application Design and Development User Interfaces

More information

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of The SQL Query Language Data Definition Basic Query

More information

DATABASE DESIGN - 1DL400

DATABASE DESIGN - 1DL400 DATABASE DESIGN - 1DL400 Spring 2014 2014-01-21 A course on modern database systems http://www.it.uu.se/research/group/udbl/kurser/dbii_vt14/integrity.pdf Tore Risch Uppsala Database Laboratory Department

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13 CS121 MIDTERM REVIEW CS121: Relational Databases Fall 2017 Lecture 13 2 Before We Start Midterm Overview 3 6 hours, multiple sittings Open book, open notes, open lecture slides No collaboration Possible

More information

Principles of Data Management

Principles of Data Management Principles of Data Management Alvin Lin August 2018 - December 2018 Structured Query Language Structured Query Language (SQL) was created at IBM in the 80s: SQL-86 (first standard) SQL-89 SQL-92 (what

More information

The SQL data-definition language (DDL) allows defining :

The SQL data-definition language (DDL) allows defining : Introduction to SQL Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query Structure Additional Basic Operations Set Operations Null Values Aggregate Functions Nested Subqueries

More information

Chapter 5: Advanced SQL" Chapter 5: Advanced SQL"

Chapter 5: Advanced SQL Chapter 5: Advanced SQL Chapter 5: Advanced SQL" Database System Concepts, 6 th Ed.! Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-use " Chapter 5: Advanced SQL" Accessing SQL From a Programming Language!

More information

Data about data is database Select correct option: True False Partially True None of the Above

Data about data is database Select correct option: True False Partially True None of the Above Within a table, each primary key value. is a minimal super key is always the first field in each table must be numeric must be unique Foreign Key is A field in a table that matches a key field in another

More information

Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL Chapter 3: Introduction to SQL Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Chapter 3: Introduction to SQL Overview of the SQL Query Language Data Definition Basic Query

More information

Contents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions...

Contents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions... Contents Contents...283 Introduction...283 Basic Steps in Query Processing...284 Introduction...285 Transformation of Relational Expressions...287 Equivalence Rules...289 Transformation Example: Pushing

More information

Chapter 2: Intro to Relational Model

Chapter 2: Intro to Relational Model Non è possibile visualizzare l'immagine. Chapter 2: Intro to Relational Model Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Example of a Relation attributes (or columns)

More information

Relational Model, Relational Algebra, and SQL

Relational Model, Relational Algebra, and SQL Relational Model, Relational Algebra, and SQL August 29, 2007 1 Relational Model Data model. constraints. Set of conceptual tools for describing of data, data semantics, data relationships, and data integrity

More information

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g.

ADVANCED DATABASES ; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room ) Advanced DB Copyright by S.-g. 4541.564; Spring 2015 Prof. Sang-goo Lee (11:00pm: Mon & Wed: Room 301-203) ADVANCED DATABASES Copyright by S.-g. Lee Review - 1 General Info. Text Book Database System Concepts, 6 th Ed., Silberschatz,

More information

Chapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog

Chapter 5: Other Relational Languages.! Query-by-Example (QBE)! Datalog Chapter 5: Other Relational Languages! Query-by-Example (QBE)! Datalog 5.1 Query-by by-example (QBE)! Basic Structure! Queries on One Relation! Queries on Several Relations! The Condition Box! The Result

More information

UNIT 2 RELATIONAL MODEL

UNIT 2 RELATIONAL MODEL UNIT 2 RELATIONAL MODEL RELATIONAL MODEL CONCEPTS The relational Model of Data is based on the concept of a Relation. A Relation is a mathematical concept based on the ideas of sets. The strength of the

More information

Chapter 2: Relational Model

Chapter 2: Relational Model Chapter 2: Relational Model Database System Concepts, 5 th Ed. See www.db-book.com for conditions on re-use Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

More information

Other Relational Query Languages

Other Relational Query Languages APPENDIXC Other Relational Query Languages In Chapter 6 we presented the relational algebra, which forms the basis of the widely used SQL query language. SQL was covered in great detail in Chapters 3 and

More information

Midterm Review. Winter Lecture 13

Midterm Review. Winter Lecture 13 Midterm Review Winter 2006-2007 Lecture 13 Midterm Overview 3 hours, single sitting Topics: Relational model relations, keys, relational algebra expressions SQL DDL commands CREATE TABLE, CREATE VIEW Specifying

More information

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

Comp 5311 Database Management Systems. 2. Relational Model and Algebra Comp 5311 Database Management Systems 2. Relational Model and Algebra 1 Basic Concepts of the Relational Model Entities and relationships of the E-R model are stored in tables also called relations (not

More information

Database Technology Introduction. Heiko Paulheim

Database Technology Introduction. Heiko Paulheim Database Technology Introduction Outline The Need for Databases Data Models Relational Databases Database Design Storage Manager Query Processing Transaction Manager Introduction to the Relational Model

More information

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called Q.1 Short Questions Marks 1. Considering functional dependency, one in which removal from some attributes must affect dependency is called 01 A. full functional dependency B. partial dependency C. prime

More information

Relational Databases

Relational Databases Relational Databases Jan Chomicki University at Buffalo Jan Chomicki () Relational databases 1 / 49 Plan of the course 1 Relational databases 2 Relational database design 3 Conceptual database design 4

More information

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5 SQL QUERIES CS121: Relational Databases Fall 2017 Lecture 5 SQL Queries 2 SQL queries use the SELECT statement General form is: SELECT A 1, A 2,... FROM r 1, r 2,... WHERE P; r i are the relations (tables)

More information

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions. COSC 304 Introduction to Database Systems Relational Model and Algebra Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Relational Model History The relational model was

More information

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Comp 5311 Database Management Systems. 4b. Structured Query Language 3 Comp 5311 Database Management Systems 4b. Structured Query Language 3 1 SQL as Data Definition Language Creates the Students relation. The type (domain) of each field is specified, and enforced by the

More information

Other Query Languages. Winter Lecture 11

Other Query Languages. Winter Lecture 11 Other Query Languages Winter 2006-2007 Lecture 11 Query Languages Previously covered relational algebra A procedural query language Foundation of the Structured Query Language (SQL) Supports wide variety

More information

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity COS 597A: Principles of Database and Information Systems Relational model continued Understanding how to use the relational model 1 with as weak entity folded into folded into branches: (br_, librarian,

More information

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel 1 In this chapter, you will learn: The basic commands

More information

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management Tenth Edition Chapter 7 Introduction to Structured Query Language (SQL) Objectives In this chapter, students will learn: The basic commands and

More information

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 6 Basic SQL Slide 6-2 Chapter 6 Outline SQL Data Definition and Data Types Specifying Constraints in SQL Basic Retrieval Queries in SQL INSERT, DELETE, and UPDATE Statements in SQL Additional Features

More information

DBMS: AN INTERACTIVE TUTORIAL

DBMS: AN INTERACTIVE TUTORIAL DBMS: AN INTERACTIVE TUTORIAL Organized & Prepared By Sharafat Ibn Mollah Mosharraf 12 th Batch (05-06) Dept. of Computer Science & Engineering University of Dhaka Table of Contents INTRODUCTION TO DATABASE

More information

Relational Model: History

Relational Model: History Relational Model: History Objectives of Relational Model: 1. Promote high degree of data independence 2. Eliminate redundancy, consistency, etc. problems 3. Enable proliferation of non-procedural DML s

More information

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

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601 Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Database Management System Subject Code: CS 601 Multiple Choice Type Questions 1. Data structure or the data stored

More information

SQL (Structured Query Language)

SQL (Structured Query Language) Lecture Note #4 COSC4820/5820 Database Systems Department of Computer Science University of Wyoming Byunggu Yu, 02/13/2001 SQL (Structured Query Language) 1. Schema Creation/Modification: DDL (Data Definition

More information

CS 582 Database Management Systems II

CS 582 Database Management Systems II Review of SQL Basics SQL overview Several parts Data-definition language (DDL): insert, delete, modify schemas Data-manipulation language (DML): insert, delete, modify tuples Integrity View definition

More information

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated

More information

Other Query Languages II. Winter Lecture 12

Other Query Languages II. Winter Lecture 12 Other Query Languages II Winter 2006-2007 Lecture 12 Last Lecture Previously discussed tuple relational calculus Purely declarative query language Same expressive power as relational algebra Could also

More information

SQL STRUCTURED QUERY LANGUAGE

SQL STRUCTURED QUERY LANGUAGE STRUCTURED QUERY LANGUAGE SQL Structured Query Language 4.1 Introduction Originally, SQL was called SEQUEL (for Structured English QUery Language) and implemented at IBM Research as the interface for an

More information

The Relational Model

The Relational Model The Relational Model What is the Relational Model Relations Domain Constraints SQL Integrity Constraints Translating an ER diagram to the Relational Model and SQL Views A relational database consists

More information

Relational Data Model

Relational Data Model Relational Data Model 1. Relational data model Information models try to put the real-world information complexity in a framework that can be easily understood. Data models must capture data structure

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14 Query Optimization Chapter 14: Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Chapter 14 Query Optimization

Chapter 14 Query Optimization Chapter 14: Query Optimization Chapter 14 Query Optimization! Introduction! Catalog Information for Cost Estimation! Estimation of Statistics! Transformation of Relational Expressions! Dynamic Programming

More information

Introduction to SQL (III)

Introduction to SQL (III) Introduction to SQL (III) 1 Roadmap of This Lecture Transactions Integrity Constraints SQL Data Types and Schemas Authorization Embedded SQL 2 Transactions Unit of work Atomic transaction either fully

More information

Chapter 4 SQL. Database Systems p. 121/567

Chapter 4 SQL. Database Systems p. 121/567 Chapter 4 SQL Database Systems p. 121/567 General Remarks SQL stands for Structured Query Language Formerly known as SEQUEL: Structured English Query Language Standardized query language for relational

More information

SQL. SQL DDL Statements

SQL. SQL DDL Statements SQL Structured Query Language Declarative Specify the properties that should hold in the result, not how to obtain the result Complex queries have procedural elements International Standard SQL1 (1986)

More information

CSE 132A Database Systems Principles

CSE 132A Database Systems Principles CSE 132A Database Systems Principles Prof. Alin Deutsch RELATIONAL DATA MODEL Some slides are based or modified from originals by Elmasri and Navathe, Fundamentals of Database Systems, 4th Edition 2004

More information

SQL functions fit into two broad categories: Data definition language Data manipulation language

SQL functions fit into two broad categories: Data definition language Data manipulation language Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition Chapter 7 Beginning Structured Query Language (SQL) MDM NUR RAZIA BINTI MOHD SURADI 019-3932846 razia@unisel.edu.my

More information

SQL: Queries, Programming, Triggers. Basic SQL Query. Conceptual Evaluation Strategy. Example of Conceptual Evaluation. A Note on Range Variables

SQL: Queries, Programming, Triggers. Basic SQL Query. Conceptual Evaluation Strategy. Example of Conceptual Evaluation. A Note on Range Variables SQL: Queries, Programming, Triggers Chapter 5 Database Management Systems, R. Ramakrishnan and J. Gehrke 1 R1 Example Instances We will use these instances of the Sailors and Reserves relations in our

More information

First lecture of this chapter is in slides (PPT file)

First lecture of this chapter is in slides (PPT file) First lecture of this chapter is in slides (PPT file) Review of referential integrity CREATE TABLE other_table ( b1 INTEGER, c1 INTEGER, PRIMARY KEY (b1, c1) ) CREATE TABLE t ( a integer PRIMARY KEY, b2

More information

Relational Model. Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT)

Relational Model. Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT) 2. Relational Model Prepared by: Ms. Pankti Dharwa ( Asst. Prof, SVBIT) Attribute Types Each attribute of a relation has a name The set of allowed values for each attribute is called the domain of the

More information

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered

More information

Basant Group of Institution

Basant Group of Institution Basant Group of Institution Visual Basic 6.0 Objective Question Q.1 In the relational modes, cardinality is termed as: (A) Number of tuples. (B) Number of attributes. (C) Number of tables. (D) Number of

More information

DATABASE TECHNOLOGY - 1DL124

DATABASE TECHNOLOGY - 1DL124 1 DATABASE TECHNOLOGY - 1DL124 Summer 2007 An introductury course on database systems http://user.it.uu.se/~udbl/dbt-sommar07/ alt. http://www.it.uu.se/edu/course/homepage/dbdesign/st07/ Kjell Orsborn

More information