Question:medium

(i) Write an SQL statement to create a table named PRODUCTS with the following specifications:

Column NameData TypeKey
PIDIntegerPrimary Key
PNameVarchar of size 30
PCatChar of size 15
PriceDecimal Number

(ii) Write an SQL query to increase the price of all items by 100, whose product category is Grocery, in the table PRODUCTS.

Show Hint

Use CREATE TABLE with INT PRIMARY KEY, VARCHAR(30), CHAR(15) and DECIMAL. Then use UPDATE with SET Price = Price + 100 and WHERE PCat = 'Grocery'.
Updated On: Oct 20, 2026
Show Solution

Solution and Explanation

Step 1: Pick the right SQL command for each part:
A new table is built with CREATE TABLE. Changing stored values is done with UPDATE. So part (i) uses CREATE TABLE and part (ii) uses UPDATE.

Step 2: Build part (i) column by column:
PID: Integer, Primary Key, so write PID INT PRIMARY KEY.
PName: Varchar of size 30, so write PName VARCHAR(30).
PCat: Char of size 15, so write PCat CHAR(15).
Price: a decimal number, so write Price DECIMAL(8,2). FLOAT would also be accepted.
Join the columns with commas inside one pair of brackets:
CREATE TABLE PRODUCTS (PID INT PRIMARY KEY, PName VARCHAR(30), PCat CHAR(15), Price DECIMAL(8,2));


Step 3: Build part (ii) from the condition:
The condition is that the category is Grocery, so the filter is WHERE PCat = 'Grocery'. The text value goes in single quotes.
The change is to add 100 to the price, so the new value is Price + 100.
Put the pieces in the order UPDATE, SET, WHERE:
UPDATE PRODUCTS SET Price = Price + 100 WHERE PCat = 'Grocery';

This statement was run on a test table. Only the Grocery row changed, from 500 to 600.

Final Answer:
The CREATE TABLE statement from Step 2 and the UPDATE statement from Step 3 answer parts (i) and (ii).
Was this answer helpful?
0