Skip to content
Question 74 of 95

Q.Consider the table Projects given below: Table: Projects P_id Pname Language Startdate Enddate P001 School Management System Python 2023-01-12 2023-04-03 P002 Hotel Management System C++ 2022-12-01 2023-02-02 P003 Blood Bank Python 2023-02-11 2023-03-02 P004 Payroll Management System Python 2023-03-12 2023-06-02 Based on the given table, write SQL queries for the following:

(i) Add the constraint, primary key to column P_id in the existing table Projects.
(ii) To change the language to Python of the project whose id is P002.
(iii) To delete the table Projects from MySQL database along with its data.
Uttar Pradesh UpmspCBSE Class XII Board 2024Subjective· 3mImportance★★★★★
78% · 74/95 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The queries demonstrate adding a primary key constraint to an existing table, updating a specific record, and permanently dropping a table with all its data.

Understanding the Task

You have a table called Projects that stores information about software development projects—their unique identifier, name, programming language, and timeline. The table exists, it holds data, and now you need to modify its structure and contents using SQL commands.

The first task asks you to retrofit a primary key constraint onto the P_id column. In an ideal world, you'd declare the primary key when creating the table, but sometimes tables are built without proper constraints and need correction later. A primary key ensures that every project has a unique, non-null identifier—no two projects can share the same P_id, and no project can exist without one.

The second task is a straightforward data update: the Hotel Management System project (P002) was initially developed in C++, but you need to change that language field to Python. This is a targeted modification of a single cell in one row.

The third task is more drastic—you want to remove the entire Projects table from the database, structure and data together. This is irreversible; once executed, the table and all four project records vanish.

The SQL Queries

(i) Adding a primary key constraint

ALTER TABLE Projects
ADD PRIMARY KEY (P_id);

The ALTER TABLE statement modifies the structure of an existing table. Here, ADD PRIMARY KEY (P_id) tells MySQL to enforce uniqueness and non-null rules on the P_id column. If any duplicate or null values already exist in P_id, MySQL will reject this command—you'd need to clean the data first.

Note

If P_id were already defined with a primary key during table creation (CREATE TABLE Projects (P_id CHAR(4) PRIMARY KEY, ...)), this step would be unnecessary. The ALTER TABLE approach is a corrective measure.

(ii) Updating the language for project P002

UPDATE Projects
SET Language = 'Python'
WHERE P_id = 'P002';

The UPDATE statement changes existing data. SET Language = 'Python' specifies the new value, and WHERE P_id = 'P002' ensures only the Hotel Management System row is affected. Without the WHERE clause, every project's language would become Python—a common and dangerous mistake.

Watch out

Always double-check your WHERE condition in an UPDATE or DELETE statement. Omitting it will modify or erase every row in the table. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.