Master Computers and Technology with Fun Quizzes & Brain Teasers!
Consider a social network database about people and their relationships. The database has two relations: Person ( pid, name ) Relationship ( pid1, rel, pid2 ) The key fields are underlined: Person.pid is the key for Person, and Relationship.pid1 and Relationship.pid2 are foreign keys to Person. rel is a string representing the relationship type, and it can only be friend or enemy. So, a tuple (1,friend,2), means that the person with id 1 considers the person with id 2 a friend. Note that the relationship is not symmetric: if Alice is friend with Bob, it does not imply that Bob is friend with Alice.Q1: Create a view called mutual that contains pairs of people who share mutual feelings for each other (i.e., they consider each other friends or enemies). The schema of your view should be mutual(name1,name2). Note that your view should not repeat the same pair of people in different order (e.g., (Alice,Bob) and (Bob,Alice)); your view should only keep the pair, such that the name with the lowest pid appears first. Submit your statement in file Q1.sql.Q2: Create a user called matchmaker, and give this user read access to your mutual view from Q1