logo
  • Writing Services
    • Writing Services
      • Essays & Papers
      • Essay Service
      • Write my research paper
      • Apa paper writing service
      • Write my scholarship essay
      • Dissertation writing services
      • Coursework writing service
      • Homework & Assignment
      • Pay for homework
      • English assignment help
      • Do my assignment
      • Assignment help
      • Finance assignment help
      • Do my math homework
      • Spss assignment help
      • Do my homework
      • Biology assignment help
      • Chemistry assignment help
      • More services
      • Personal statement writing service
      • Do my excel assignment
      • Law essay writing service
      • Annotated bibliography writing service
      • Research proposal writing services
      • Nursing assignment help
      • Write my lab report
      • Capstone project writing service
      • Do my powerpoint presentation
  • Study Resources
    • Study Resources
      • Universities
      • Courses
      • Documents

Lecture Note

Database Basics: Keys, Operations & Subqueries

  • University:

    College
  • Course:

    College Mathematics
  • Academic year:

    2023

  • Views:

    19

    Pages:

    41

  • Author:

    Avaiya Priyank

Topics to be covered ▪ ▪ ▪ ▪ ▪ ▪ ▪ Structure of Relational Database Domain Keys of relations Relational Algebra Implementing Relational Algebra using SQL Set Operators Sub queries Definitions Arity = No. of Columns = 3 Total No. of Tuples = Cardinality of relation Row = Record = Tuple • Attribute = Column Name • 2 attribute in same relation (table) can't have same name Set of permitted values for that attribute = Domain • Predefined row/column format for storing information. • Relation = Table Keys ▪ Super Key • A super key is a set of one or more attributes whose values uniquely identifies each record within a relation. Super Key (EnrollNo) Super Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Candidate Key • A candidate is a subset of a super key. • A candidate key is the least combination of attribute that uniquely identifies each record in the table. • The least combination of fields distinguishes a candidate key from a super key. Keys ▪ Candidate Key What is the difference between super key and candidate key?? Candidate Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Super Key V/S Candidate Key EnrollNo alone works as a super key?? Answer is Yes So (EnrollNo, Branch) is super key but not candidate key. Super Key (EnrollNo, Branch) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Super Key V/S Candidate Key RollNo and Branch alone works as a super key?? Answer is No Super Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Super Key V/S Candidate Key RollNo and Semester alone works as a super key?? Answer is No Super Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Super Key V/S Candidate Key Branch and Semester alone works as a super key?? Answer is No Super Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Super Key V/S Candidate Key (RollNo, Branch, Semester) is super key as well as candidate key. Super Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Primary key • A Primary key is chosen by database designer to identify tuples uniquely in a relation. ▪ Alternate key • If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of that table. Keys ▪ Primary Key V/S Alternate Key Candidate Primary KeyKey EnrollNo Candidate Key Alternate Key (RollNo, Branch, Semester) EnrollNo RollNo Name 6662030701 101 6662030702 102 6662030601 Branch Semester SPI BackLog Pritesh CE 3 8 0 3 7 0 101 Vaibha CE vMihir CI 3 8 0 6662030602 102 Darshan CI 3 6 1 5662030701 101 Priya CE 5 8 0 5662030702 102 5 7 1 5662030601 101 Shrey CE aNiddhi CI 5 7 1 Keys ▪ Foreign key • A foreign key is a set of one or more attributes whose values are derived from the primary key attribute of another relation. Stu_ID RollNo Name Branch Semester SPI BackLog 1 101 Pritesh CE 3 9 0 2 102 Vaibhav CI 3 8 0 3 101 Nidhi CE 5 7 1 4 105 Shyam CI 5 8 2 Fac_ID Stu_ID Fac_SN Fac_Name Branch 1 1 501 Akash CE 2 2 502 Mohit CI 3 4 504 Nitin CE 4 1 515 Harnish CI Relational algebra operation ▪ It is a language for expressing relational database queries. ▪ It is a procedural query language. ▪ Operations are as below; 1. Selection 2. Projection 3. Division 4. Cartesian product / Cross product 5. Rename 6. Set Operations • Union • Intersection • Difference / Minus Selection operation ▪ Retrieve one or more than one row/s (tuples) that satisfies the condition/s with all columns (attribute) ▪ Symbol : σ (Sigma) ▪ Notation : σ(condition) ▪ Operators: • =,!=, <,>,<=,>=, Λ(AND), ∨(OR) ▪ Example: Student Stu_ID Stu_RollNo Name Department 1 101 Ram Computer 2 105 Param IT 3 208 Krishti Computer 4 106 Balram Electrical Selection operation example ▪ Find out the list of students from the following table who have department = “Computer” Stu_ID Stu_RollNo Name Department 1 101 Ram Computer 2 105 Param IT 3 208 Krishti Computer 4 106 Balram Electrical Name Department ▪ σDepartment=“Computer” (Student) ▪ Output: Stu_ID Stu_RollNo 1 101 Ram Computer 3 208 Krishti Computer Projection operation ▪ Retrieve one or more than one column/s (attribute) that satisfies the condition/s with all rows (tuples) ▪ Symbol : ∏ (Pi) ▪ Notation : ∏ (column name)
▪ Example: Student Stu_ID Stu_RollNo Name Department 1 101 Ram Computer 2 105 Param IT 3 208 Krishti Computer 4 106 Balram Electrical Projection operation example ▪ List all the student’s name and department Stu_ID Stu_RollNo Name Department 1 101 Ram Computer 2 105 Param IT 3 208 Krishti Computer 4 106 Balram Electrical ▪ ∏Name, Department (Student) ▪ Output: Name Department Ram Computer Param IT Krishti Computer Balram Electrical Combined Projection & Selection Operation ▪ Example: Display rollno, name & department of “CE” department students. RollNo Name Department SPI Student 101 Raj CE 8 102 Meet ME 9 103 Harsh EE 8 104 Punit CE 9 ∏ RollNo, Name, Department (σ Department=‘CE’ (Student) ) Output-1 Output-2 1 RollNo Name 2 Department 101 Raj CE 8 104 Punit CE 9 RollNo Name Branch 101 Raj CE 104 Punit CE SPI Combined Projection & Selection Operation ▪ Example: Display rollno and name of “CE” department students. RollNo Name Department SPI 101 Raj CE 8 Student 102 Meet ME 9 103 Harsh EE 8 104 Punit CE 9 σ Department=‘CE’ (∏ RollNo, Name(Student) ) 2 Output-1 RollNo Name 101 Raj 102 Meet 103 Harsh 104 Punit 1 Where is branch column to check condition?? So we can’t use selection left side and projection right side. Division Operator ▪ Symbol: ÷ ▪ Notation: Relation1 ÷ Relation2 ▪ Operation: Produce the tuples in Relation1, that match all tuples in Relation2. Division Operator Examples B1 B2 B3 A A/B1 A/B2 A/B3 Cartesian product / Cross product ▪ Combines information of two tables ▪ It will multiply each row(tuples) of first table(relation) to each row(tuples) of second table(relation). ▪ Symbol : X (Cross) ▪ Notation : Relation1 X Relation2 ▪ Resultant Relation: 1. Relation1 have n1 attribute and Relation2 have n2 attribute then resultant relation will have n1+n2 attribute. 2. Relation1 have n1 tuples and Relation2 have n2 tuples then resultant relation will have n1*n2 tuples. 3. If both relations have some attribute with same name, then it will be distinguished by relation1.attribute and relation2.attribute Cartesian product example Student Faculty Stu_ID Stu_RollNo Name Department Fac_ID Fac_Name Department 1 101 Ram Computer 1 Nitin Computer 2 105 Param IT 2 Chintan IT Student X Faculty Stu_ID Stu_RollNo Name Department Fac_ID Fac_Name Faculty.Deparmtnet 1 101 Ram Computer 1 Nitin Computer 1 101 Ram Computer 2 Chintan IT 2 105 Param IT 1 Nitin Computer 2 105 Param IT 2 Chintan IT Set Operators ▪ Operation: All of these operations take two input relations, which must be union - compatible: 1. Both relations have same (equal) number of columns RollNo Name Branch SPI EmpNo Name Branch 101 Raj CE 8 101 Patel CE 102 Meet CE 7 102 Shah CE 103 Neel ME 9 103 Ghosh EE RollNo Name Branch SPI EmpNo Name Branch Exp 101 Raj CE 8 101 Raj CE 8 102 Meet CE 7 102 Meet CE 1 103 Neel ME 9 103 Ghosh EE 9 Set Operators ▪ Operation: All of these operations take two input relations, which must be union - compatible: 2. Attributes domain must be compatible RollNo Name Branch SPI EmpNo Name Branch Subject 101 Raj CE 8 101 Raj CE DBMS 102 Meet CE 7 102 Meet CE DS 103 Neel ME 9 103 Ghosh EE EEM RollNo Name Branch SPI EmpNo Name Branch Exp 101 Raj CE 8 101 Raj CE 8 102 Meet CE 7 102 Meet CE 1 103 Neel ME 9 103 Ghosh EE 9 Union operator ▪ Symbol: U ▪ Notation: Relation1 U Relation2 ▪ Operation: Combine the records from two or more tables (sets) in to a single table (set), without duplicates. Student U Faculty Raj Student Faculty Suresh Raj Nitin Meet Suresh Raj Nitin Meet Akash Akash Intersect operator ▪ Symbol: ∩ (Intersection) ▪ Notation: Relation1 ∩ Relation2 ▪ Operation: Returns the records which are common from both relations. Student Faculty Student ∩ Faculty Raj Nitin Raj Suresh Raj Meet Akash Minus/Difference Operator ▪ Symbol: − ▪ Notation: Relation1 − Relation2 ▪ Operation: Returns all the records from first (left) relation that are not contained in the second relation. Student Faculty Raj Nitin Student – Faculty Faculty – Student Suresh Raj Suresh Nitin Meet Akash Meet Akash Rename Operator ▪ Symbol: ρ (Rho) ▪ Notation: ρA (X1,X2….Xn) (Relation) ▪ Operation: It is used to rename a relation or attributes. Student Rno Name CPI 101 Raj 8 102 Meet 9 103 Suresh 7 ▪ Find out maximum CPI from student table. ∏CPI (Student) — ∏A.CPI (σ A.CPI,<=,>= etc operators. ▪ Example: Find out the name of staff whose salary is maximum. select staff_name from staff where staff_salary=(select max(staff_salary) from staff); Single row sub query Multiple row sub query ▪ Returns one or more rows ▪ Can be used with IN, NOT IN, ANY, ALL etc operators. ▪ Example: Find out the name of staff who are from “Computer” department using sub query. SELECT * FROM staff WHERE dep_id IN (SELECT dep_id FROM department where dep_id='2'); Multiple row sub query Correlated sub query ▪ If a sub query references columns in the parent query. ▪ This makes it impossible to evaluate the sub query before evaluating the parent query. ▪ Example: Find out the name of staff who earn less salary then average salary. SELECT staff_name FROM staff WHERE staff_salary < (select avg(staff_salary) from staff); Correlated sub query

Related Documents

  • Homework 5: Distributions And Random Variables
  • Sec 3: Partial Fractions
  • Sec 3: Coordinate Geometry
  • Simultaneous Linear Inequality
  • Power Functions, Polynomials, Remainder And Factor Theorem
  • Joint Probability, Poisson Distribution, Conditional Probability
  • Further Trigonometric Functions and Differentiation
  • Trigonometric Functions And R Formula
  • Linear Law, Parabolas And Circles
  • Binomial Theorem And Coordinate Geometry
  • Partial Fractions And Modulus Functions
  • Differentiation And Integration
  • Coordinate Geometry
  • Finance Assignment #1
  • Standard Form
  • Application Of Integration
  • Homework 1: Combinatorial Problems
  • Sec 3: Surd
  • Answer To Statistic Question
  • Answer Number 1 And 2 Statistical Material

Database Basics: Keys, Operations & Subqueries

Database Basics: Keys, Operations & Subqueries - Page 1
Database Basics: Keys, Operations & Subqueries - Page 2
Database Basics: Keys, Operations & Subqueries - Page 3
Database Basics: Keys, Operations & Subqueries - Page 4
Database Basics: Keys, Operations & Subqueries - Page 5
Database Basics: Keys, Operations & Subqueries - Page 6
Database Basics: Keys, Operations & Subqueries - Page 7
Database Basics: Keys, Operations & Subqueries - Page 8
Database Basics: Keys, Operations & Subqueries - Page 9
Database Basics: Keys, Operations & Subqueries - Page 10
Database Basics: Keys, Operations & Subqueries - Page 11
Database Basics: Keys, Operations & Subqueries - Page 12
Database Basics: Keys, Operations & Subqueries - Page 13
Database Basics: Keys, Operations & Subqueries - Page 14
Database Basics: Keys, Operations & Subqueries - Page 15
Database Basics: Keys, Operations & Subqueries - Page 16
Database Basics: Keys, Operations & Subqueries - Page 17
Database Basics: Keys, Operations & Subqueries - Page 18
Database Basics: Keys, Operations & Subqueries - Page 19
Database Basics: Keys, Operations & Subqueries - Page 20
Database Basics: Keys, Operations & Subqueries - Page 21
Database Basics: Keys, Operations & Subqueries - Page 22
Database Basics: Keys, Operations & Subqueries - Page 23
Database Basics: Keys, Operations & Subqueries - Page 24
Database Basics: Keys, Operations & Subqueries - Page 25
Database Basics: Keys, Operations & Subqueries - Page 26
Database Basics: Keys, Operations & Subqueries - Page 27
Database Basics: Keys, Operations & Subqueries - Page 28
Database Basics: Keys, Operations & Subqueries - Page 29
Database Basics: Keys, Operations & Subqueries - Page 30
Database Basics: Keys, Operations & Subqueries - Page 31
Database Basics: Keys, Operations & Subqueries - Page 32
Database Basics: Keys, Operations & Subqueries - Page 33
Database Basics: Keys, Operations & Subqueries - Page 34
Database Basics: Keys, Operations & Subqueries - Page 35
Database Basics: Keys, Operations & Subqueries - Page 36
Database Basics: Keys, Operations & Subqueries - Page 37
Database Basics: Keys, Operations & Subqueries - Page 38
Database Basics: Keys, Operations & Subqueries - Page 39
Database Basics: Keys, Operations & Subqueries - Page 40
Database Basics: Keys, Operations & Subqueries - Page 41
of 41
0/0

Recommended Documents

Z-Table Transform Cheat Sheet: Table of Laplace and Z-transforms
Z-Table Transform Cheat Sheet: Table of Laplace and Z-transforms
College College Mathematics

Cheat Sheet

New Documents from this Course

Normal Distribution in Higher Concepts of Mathematic
Normal Distribution in Higher Concepts of Mathematic
College College Mathematics

Lecture Note

Enrollment and Dependency Analysis in Database Design
Enrollment and Dependency Analysis in Database Design
College College Mathematics

Lecture Note

Student Course Enrollment Analysis: SQL Queries
Student Course Enrollment Analysis: SQL Queries
College College Mathematics

Lecture Note

Calculating Distance Between Coordinates: A Math Tutorial
Calculating Distance Between Coordinates: A Math Tutorial
College College Mathematics

Lecture Note

Partial Fractions
Partial Fractions
College College Mathematics

Lecture Note

Introduction to Differential Equations and Their Solutions
Introduction to Differential Equations and Their Solutions
College College Mathematics

Lecture Note

Introduction to Complex Numbers
Introduction to Complex Numbers
College College Mathematics

Lecture Note

The Determinant (Mathematic)
The Determinant (Mathematic)
College College Mathematics

Lecture Note

Properties of Algebra
Properties of Algebra
College College Mathematics

Lecture Note

Numerical Problems and Equations Overview
Numerical Problems and Equations Overview
College College Mathematics

Assignment

Conversions of Radians and Degrees
Conversions of Radians and Degrees
College College Mathematics

Lecture Note

Fair Use Policy

EduBirdie considers academic integrity to be the essential part of the learning process and does not support any violation of the academic standards. Should you have any questions regarding our Fair Use Policy or become aware of any violations, please do not hesitate to contact us via support@edubirdie.com.

logo

Popular Services

  • Essay writing service
  • Pay someone to do my homework
  • Do my assignment for me
  • Research paper writing services
  • Dissertation writing services
  • Do my homework

Study Resources

  • Essay Examples
  • Blog
  • Study Notes

About Us

  • How it works?
  • Testimonials
  • FAQ
  • Money back guarantee

Contact us

mail icon
  • support@edubirdie.com
phone-icon
  • +3 (595) 691 8356
  • +1 (888) 337 5415
DMCA.com Protection Status

For press

  • Press and media
  • Brand assets
Facebook Twitter Instagram LinkedIn

Local sites

  • Ca.EduBirdie.com- The Best Essay Writing Service for Canadian Students

We accept

2024 © EduBirdie.com. All rights reserved

RADIOPLUS EXPERTS LTD. Louki Akrita, 23 Bellapais Court, Flat/Office 46 1100, Nicosia, Cyprus

Privacy Policy
|
Terms of Use
|
Fair use policy
Subscription rules
|
Referral program Rules
|
Payment policy

Report

Tell us what’s wrong with it:

Thanks, got it!
We will moderate it soon!

Report

Tell us what’s wrong with it:

Almost There!

Two easy ways to download this document

or
Upgrade to premium for unlimited access
Calendar Icon

Free up your schedule!

Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.

Unlock Icon

Take 5 seconds to unlock

Enter your email below and get instant access to your document

This field is required
Please enter a valid email address
This field is required
This field is required

By clicking 'Sign Up', you agree to our Terms and Conditions and Privacy Policy.