Question:medium

Consider the table LIBRARY as given below.

BookIdTitleGenrePrice
101Python BasicsTechnology278
201The Silent PatientFiction340
301Data ScienceTechnology291
401OceansMarine LifeNULL

(I) Which attribute(s) can be considered as the Candidate keys(s)? Justify your answer.

(II) Write an SQL query to insert a new record with the following values: BookId: 501, Title: AI for ALL, Genre: Technology, Price: 589

(III) Write an SQL query to add a new column Author that is a character data type of size 20.

Show Hint

A candidate key never repeats and never holds NULL. Use INSERT INTO for the new row and ALTER TABLE ... ADD for the new column.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Part (I) - go column by column:
We look for a column with no repeated value and no NULL.
BookId: 101, 201, 301, 401. Nothing repeats, nothing is NULL. This column passes.
Title: four different names here, but two books may share a title in a real library, so it is not a safe key.
Genre: Technology appears for two books. It fails.
Price: one cell is NULL and prices can repeat. It fails.
So the candidate key is BookId. A candidate key is a column that can uniquely identify every row.

Step 2: Part (II) - the insert query:
The new book has an Id, a title, a genre and a price. We give the values in the same order as the table columns.
Title and Genre are text, so they go in single quotes.
INSERT INTO LIBRARY VALUES (501, 'AI for ALL', 'Technology', 589);

The table then has five rows.

Step 3: Part (III) - the alter query:
Adding a column changes the design of the table, so DML commands like UPDATE cannot do it. We use ALTER TABLE with ADD.
The name is Author. The type is a character type of size 20.
ALTER TABLE LIBRARY ADD Author VARCHAR(20);

CHAR(20) is also accepted. All old rows show NULL under Author.

Final Answer:
(I) Candidate key: BookId.
(II) INSERT INTO LIBRARY VALUES (501, 'AI for ALL', 'Technology', 589);
(III) ALTER TABLE LIBRARY ADD Author VARCHAR(20);
Was this answer helpful?
0