Database Query using SQL — Question 22
Back to all questionsConsider the tables given below and answer the questions that follow:
Table: EVENT
| EventId | Event | NumPerformers | CelebrityID |
|---|---|---|---|
| 101 | Birthday | 10 | C102 |
| 102 | Promotion Party | 20 | C103 |
| 103 | Engagement | 12 | C102 |
| 104 | Wedding | 15 | C104 |
Table: CELEBRITY
| CelebrityID | CelebrityName | Phone | FeeCharged |
|---|---|---|---|
| C101 | Faiz Khan | 99101XXXXX | 200000 |
| C102 | Sanjay Kumar | 89346XXXXX | 250000 |
| C103 | Neera Khan Kapoor | 98116XXXXX | 300000 |
| C104 | Reena Bhatia | 70877XXXXX | 100000 |
(a) Name the Primary keys in both the tables and the Foreign key in 'Event' table. Can NumPerformers (Number of performers) be set as the Primary key? Give reason.
(b) How many rows will be present in the Cartesian join of the above-mentioned two tables?
(c) Write the commands in SQL:
- To display EventId, Event name, CelebrityId for only those events that have more than 10 performers.
- To display CelebrityId and names of celebrities who have "Khan" anywhere in their names.
- To display names of celebrities and fee charged for those celebrities who charge more than 200000.
(a) In the EVENT table, the primary key is EventId, and in the CELEBRITY table, the primary key is CelebrityID. The foreign key in the EVENT table is CelebrityID, which references the CelebrityID in the CELEBRITY table.
NumPerformers cannot be set as the primary key because primary keys must uniquely identify each row in the table. NumPerformers can have duplicate values for different events, as multiple events can have the same number of performers.
(b) The EVENT table has 4 rows and the CELEBRITY table has 4 rows. So, the Cartesian join will have: 4 × 4 = 16 rows.
(c)
1.
SELECT EVENTID, EVENT, CELEBRITYID
FROM EVENT
WHERE NUMPERFORMERS > 10;+---------+-----------------+-------------+
| EVENTID | EVENT | CELEBRITYID |
+---------+-----------------+-------------+
| 102 | PROMOTION PARTY | C103 |
| 103 | ENGAGEMENT | C102 |
| 104 | WEDDING | C104 |
+---------+-----------------+-------------+
2.
SELECT CELEBRITYID, CELEBRITYNAME
FROM CELEBRITY
WHERE CELEBRITYNAME LIKE '%Khan%';+-------------+-------------------+
| CELEBRITYID | CELEBRITYNAME |
+-------------+-------------------+
| C101 | FAIZ KHAN |
| C103 | NEERA KHAN KAPOOR |
+-------------+-------------------+
3.
SELECT CELEBRITYNAME, FEECHARGED
FROM CELEBRITY
WHERE FEECHARGED > 200000;+-------------------+------------+
| CELEBRITYNAME | FEECHARGED |
+-------------------+------------+
| SANJAY KUMAR | 250000 |
| NEERA KHAN KAPOOR | 300000 |
+-------------------+------------+