Docsity

dbms notes by rss sir, Lecture notes of Database Management Systems (DBMS)

Partial preview of the text

Download dbms notes by rss sir and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

Unit 3 Query Languages

“A person who never made a

mistake never tried anything new."

— Albert Einstein

Algebra

  • Algebra is the branch of mathematics that helps in the representation of problems or situations in the form of mathematical expressions.
  • For e.g. If the area of the rectangle is 36 cm 2 . Its length is represented as l and width is represented as b. Then this statement is represented as : l × b = 36
  • BoB wants to visit a zoo. A ticket for the entry to the zoo cost 4.he has only 3. How much more money does he need to buy the ticket?
  • Answer: Let BoB need $y more to buy the ticket.
  • So, we will solve this problem using algebra, 3 + y = 4,
  • We add y to 3 to get 4.Now we need to find the value of y.
  • y = 4 − 3 y = 1
Algebra
  • Abstract algebra, Linear algebra, and Boolean algebra
  • Abstract algebra is the set of advanced topics of algebra that deal with abstract algebraic structures rather than the usual number systems. The most important of these structures are groups(Closure:Identity:Inverse: Associativity: The defined multiplication is associative, i.e., for all A,B,C in G, (AB)C=A(BC).),rings, and fields. It's used in computer science for secure communication, in physics to understand symmetries and conservation laws, and in engineering to design error-correcting codes.
  • Linear algebra is the study of linear combinations. It is the study of vector spaces, lines and planes, and some mappings that are required to perform the linear transformations. It includes vectors, matrices and linear functions.
  • Boolean algebra is a branch of mathematics that deals with operations on logical values with binary variables. Applications are digital circuit design,pocket calculator,CD Palyer,Cell Phone and other electronic products.

Relational Algebra

  • Basic/Fundamental Operations:
    1. Select (σ)
    1. Project (∏)
    1. Union ( )
    1. Set Difference (-)
    1. Cartesian product (X)
    1. Rename (ρ)
  • Derived Operations:
    1. Natural Join ( )
    1. Left, Right, Full outer join ( , , )

Relational Algebra : Operations

  • Select (σ): This operation is used to fetch rows from given table or relation on the basis of given conditions, it is denoted by “Sigma(σ)”.
  • Syntax : σ Condition/Predicate(Relation/Table name)
  • where clause in SQL, is used for the same purpose.
  • For example : Consider the table of relation R(Roll No, Name, Age, Marks). If we want to select the name and age of student, then it can be done by:
  • Query Used : σ Age>21 (Student_Details)

AND and OR Conjunctive Operators

  • The SQL AND & OR operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called as the conjunctive operators.
  • These operators provide a means to make multiple comparisons with different operators in the same SQL statement.
  • Q: Find Names of all CUSTOMERs , where the salary is greater than 2000 and the age is less than 25 years.
  • ᴨ Name [σ Salary>2000 and Age< (Customer)]
  • Q: SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 OR age < 25;
  • ᴨ (^) ID,Name , Salary [σSalary>2000 Or Age<25 (Customer)]

Relational Algebra : Operations

  • IntersecƟon(∩) : Intersection operator is denoted by ∩ symbol and it is used to select common rows (tuples) from two tables (relations).
  • Lets say we have two relations R1 and R2 both have same columns and we want to select all those tuples(rows) that are present in both the relations, then in that case we can apply intersection operation on these two relations R1 ∩ R2.
  • Note: Only those rows that are present in both the tables will appear in the result set. COURSE ∩ STUDENT

Relational Algebra : Operations

  • Set Difference (-) : In order to fetch the data which is not present in any one of the relation, set difference operation is used. The set difference operation is denoted by “Minus(-)”.
  • Lets say we have two relations R1 and R2 and we want to select all those tuples(rows) that are present in Relation R1 but not present in Relation R2, this can be done using Set difference R1 – R2.
  • For example : Consider the two tables with relations X 1 (Name, Age) and X 2 (Name, Age). If we wish to apply the set difference operation, then it can be done by :

Examples

  • 1] List students whose "AGE" is 20
  • 2] List all the names from STUDENT and EMPLOYEE relation.
  • 3] List students those who are not EMPLOYEE and those who are employee.

Relational Algebra : Operations

  • Cartesian product (X): The Cartesian product operation will generate the possible combinations among the tuples from the relations resulting in table containing all the data.
  • It combines the information of two or more relations in one single relation. Cartesian product is different from union operation and is denoted by “Cross(X)”.

Relational Algebra : Operations

  • Rename (ρ) : Rename (ρ) operation can be used to rename a relation or an attribute of a relation.
  • Rename (ρ) Syntax: ρ(new_relation_name, old_relation_name)
  • Query: ρ(CUST_NAMES, ∏(Customer_Name)(CUSTOMER))

Relational Algebra examples

    1. Find Indian player id.
    1. List out players those who are having more than 10000 runs.
    1. List out player along with their country details having age below 25 and more than 100 wickets.
    1. List all the countries in Player relation.