Question

Give an example of 3 relations illustrating primary keys and foreign keys. Consider the following relations:...

  1. Give an example of 3 relations illustrating primary keys and foreign keys.
  2. Consider the following relations:

    Student(sID, surName, firstName, campus, email)

    Course(dept, cNum, name)

    
Offering(oID, dept, cNum, term, instructor)


    Took(sID, oID, grade)

    Such as:

    Offering[dept, cNum] ⊆ Course[dept, cNum]

    Took[sID] ⊆ Student[sID]


    Took[oID] ⊆ Offering[oID]

    Answer the following query using relational algebra

  3. -Give the Student number of all students who have taken the course number “343” by the department “CS”.

- Find sID of all students who have earned some grade over 80 and some grade below 50.

- Find the Terms when the course number “369” by the department “CS” was not offered.

- Find the Department and course number of courses that have never been offered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: I am mentioning complete question again since there are no question Numbers

SOLUTION 1 FOR -> Give the Student number of all students who have taken the course number “343” by the department “CS”.

SELECT surName || firstName AS Name
FROM Student s,Offering O, Took t
WHERE O.dept=="CS" AND O.cNum==343 AND O.oID==t.oID AND s.sID==t.sID

EXPLANATION:

1. We have dept and cnum in offering and student details in student table and the details of who has taken the course in took table so we need to join those tables to get the data

2. We need to first check for dept and course filtering in the offerings so we will get the offering ID

3. map this data with the Took table with the offering Id (oID) we will get the   student Ids from this (sID) we now can join the student table with the student id and get the name

4. here I have concated the surname and first name to get the name

OUTPUT:

SQL Statement: SELECT surName|firstName AS Name FROM Student s, Offering 0, Took t WHERE 0.dept==CS AND O.cNum==343 AND O.O

SOLUTION 2 FOR-> Find sID of all students who have earned some grade over 80 and some grade below 50.

SELECT sID
FROM Took
WHERE grade>80


INTERSECT


SELECT sID
FROM Took
WHERE grade<50

EXPLANATION:

1 INTERSECT-> intersect will return only the common items in the two querys data

2. here by using 1st query i am finding the sids of students who have grade >80

3. By using seconf 2nd query i am findingg the sids of students whose garde is < 50

4 Now by applying intersect we will the sIDs whic are common in both the querys

OUTPUT:

SQL Statement: SELECT SID FROM Took WHERE grade>80 INTERSECT SELECT SID FROM Took WHERE grade 50 Edit the SQL Statement, and

SOLUTION 3:For ->Find the Terms when the course number “369” by the department “CS” was not offered.

SELECT term
from Offering
where term NOT IN (
SELECT term
from Offering
WHERE dept=="CS" AND cNum==369)

EXPLANATION:

1 . We need to first find out all terms in which the course 369 is offered by 369

2. Check all the terms that are available in the Offering then we need to project that term where the course is not offered like if Term is not in the Offering of previously fetched data of the terms of 369 CS then we need to project that Term

3. SImply it is like check for all the available terms in the Offering then check for the terms of 369 CS if any term is missing for CS 369 to all terms project them

OUTPUT:

SQL Statement: SELECT term from Offering where term NOT IN ( SELECT term from Offering WHERE dept==CS AND Num==369) Edit th

SOLUTION 4: FOR-> Find the Department and course number of courses that have never been offered

SELECT C.dept,C.cNum
FROM Course C,Offering O
WHERE C.dept==O.dept and C.cNum==O.cNum

EXPLANATION:

1. We have all the courses in the Course Table and Offerings in the Offering table so we need to join those table

2. We need to join them based dept and course Number if the course is offered then it will be in the offering table and projected

3 For Improvement of the presentation of the data, we can also do group by dept,cNum so that the course offered by a department will be group and presented well

OUTPUT:

SQL Statement: SELECT C.dept,C.cNum FROM Course C, Offering o WHERE C.dept==0.dept and C.cNum==0.cNum Edit the SQL Statement,

Add a comment
Know the answer?
Add Answer to:
Give an example of 3 relations illustrating primary keys and foreign keys. Consider the following relations:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello please don't answer with your handwriting thank you Give an example of 3 relations illustrating...

    Hello please don't answer with your handwriting thank you Give an example of 3 relations illustrating primary keys and foreign keys f 3 relations illustrating primary keys and foreign keys Use your example for a simple Relational algebra query

  • Consider the following relations for a database that keeps track of student enrollment in courses and...

    Consider the following relations for a database that keeps track of student enrollment in courses and books adopted for each course. -------------------------------------------------------------------------------------------------------- STUDENT(Ssn,Name,Major,Bdate) COURSE(Course#,Cname,Dept) ENROLL(Ssn,Course#,Quarter,Grade) TEXTBOOK(Book_isbn,Book_title,Publisher,Author) BOOK_ASSOC(Course#,Quarter,Book_isbn) ------------------------------------------------------------------------------------------------------------------------------- Having that a relation can have zero or more foreign keys and each foreign key can refer to different referenced relations. Specify the foreign keys for this schema.

  • Consider the below schema of the university database (keys are in bold and underline): Students(stuID: Integer,...

    Consider the below schema of the university database (keys are in bold and underline): Students(stuID: Integer, stuName: String, gender: String, age: Integer, gpa: Float) Departments(deptName: String, numPhDs: Integer) ProfessorWorks(profID: Integer, profName: String, deptName: String) CoursesOffer(cNo: String, cTitle: String, deptName: String) Majors(deptName:  String, stuID: Integer, degreeProgram: String; attendYear: String, attendSemester: String) Sections(cNo: String, academicYear: String, semester: String, sectNo: Integer, profID: Integer) Enrolls(stuID: Integer, cNo: String, academicYear: String, semester: String, sectNo: Integer, grade: String) Write the following queries in Relational algebra. Print...

  • Consider the following relations for course-enrollment database in a university: STUDENT(S-ID,S-Name, Department, Birth-date) COURSE(C-ID, C-Name, Department)...

    Consider the following relations for course-enrollment database in a university: STUDENT(S-ID,S-Name, Department, Birth-date) COURSE(C-ID, C-Name, Department) ENROLL(S-ID, C-ID, Grade) TEXTBOOK(B-ISBN, B-Title, Publisher, Author) BOOK-ADOPTION(C-ID, B-ISBN) (a) Draw the database relational schema and show the primary keys and referential integrity constraints on the schema. (b) How many superkeys does the relation TEXTBOOK have? List ALL of them. (c) Now assume each COURSE has distinct C-Name. (i) If C-ID is a primary key, what are the candidate keys and the unique keys...

  • 10- Specify the following queries in SQL on the database schema of Figure 2. a. Retrieve...

    10- Specify the following queries in SQL on the database schema of Figure 2. a. Retrieve the names of all senior students majoring in ‘CS’ (Computer Science). b. Retrieve the names of all courses taught by Professor King in 2004 and 2005. c. For each section taught by Professor King, retrieve the course number, semester, year, and number of students who took the section. d. Retrieve the name and transcript of each senior student (Class =4) majoring in CS. A...

  • Consider the Schema diagram for a university database a. Find the IDs of all students who...

    Consider the Schema diagram for a university database a. Find the IDs of all students who have taken all of the CMPSC courses. Use the division operation. b. Do the same operation as in problem a, using only fundamental operations. student takes ID course id sec id semester 1er 4112 dept_name tot cred grade advisor section course_id sec id semester year building TOOM_10 time_slof_id course course id title dept name credits department dept name building budget time slot time slot...

  • 31. (15 pts) Consider the following relations and relationship: Student (studentID, name, address, gender, major) Course...

    31. (15 pts) Consider the following relations and relationship: Student (studentID, name, address, gender, major) Course (courselD, title, hour, department) Enrollment (StudentID, courselD, date Write the SQL statements to perf orm the following operations: List all the students' information for those majoring in "Computer Science". (2 pts) List the majors, and the numbers of the students in every major. (2 pts) List the departments, and the total number of hours of the courses offered by every department. (2 pts) List...

  • -Consider the following table definition, where the primary keys are underlined. Give an expression in relational...

    -Consider the following table definition, where the primary keys are underlined. Give an expression in relational algebra for each of the following queries. Athlete (aID integer, aName string, ranking integer, age integer) Event (eID string, eName string, eLocation string) Competes (aID integer, eID string, sport string, year integer) 3. Find the names of the events an athlete named Dennis competed in (aName = ‘Dennis’) 4. Find the names of the athletes who have competed in at least one Event 5....

  • Consider the following table definition, where the primary keys are underlined. Give an expression in relational...

    Consider the following table definition, where the primary keys are underlined. Give an expression in relational algebra for each of the following queries. Athlete (aID integer, aName string, ranking integer, age integer) Event (eID string, eName string, eLocation string) Competes (aID integer, eID string, sport string, year integer) 1. Find the names of athletes who have competed in event 1Sk8P (eiD = ‘1Sk8P’) 2. Find the names of athletes who have competed in the event XGames (eName = ‘XGames’) 3....

  • Someone please answer all of these. I need these badly. The submission date is knocking at...

    Someone please answer all of these. I need these badly. The submission date is knocking at the door. Experiment 1: SQL data definition and data insertion 46 hours) 1. CREATE TABLE. The database schema consists of the three relations, whose schemas are: S (Spa, Sname. Sgender, Sage, Sdert? // students(SID, name, gender, age, department) SC (Spa, Cne. Grade) //Course(SID, CID, grade) C (One Cname Crno. Ceredit) l/courses (CID, course name, prerequisite courses, credit) 2. DROP TABLE, ALTER TABLE, CREATE INDEX,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT