Q29
1 markShort AnswerSection B

(a) Write an SQL command to create the above table (W_Code should be the primary key).

OR

(b) Can U_Price be the primary key of the above table ? Justify your answer.

Structured Query Language (SQL)
SQL — CREATE TABLE and Primary Key
Official Answer

(a) CREATE TABLE command:

``sql

CREATE TABLE W_STOCK (

W_Code CHAR(5) PRIMARY KEY,

W_Description VARCHAR(20),

B_Qty INTEGER,

U_Price FLOAT

);

``


(b) Can U_Price be the primary key?

No, U_Price cannot be the primary key. A primary key must contain unique, non-null values for every record so that each row can be identified without ambiguity. Since the unit price of an item is a general attribute, it is entirely possible for two or more different items in the stock to have the same unit price, which would violate the uniqueness requirement of a primary key.

CREATE TABLEPRIMARY KEYSQLCHARVARCHARINTEGERFLOATuniqueness constraint

Marking Scheme

  • 11 mark: fully correct CREATE TABLE statement with all four columns, correct data types, and PRIMARY KEY on W_Code — OR correct 'No' with valid justification (U_Price values can repeat across items, violating uniqueness) for part (b).

Hint

A primary key column must always hold unique, non-null values — ask whether real-world duplicates are possible for that column.

Quick Oral Answer

I create the W_STOCK table using CREATE TABLE with W_Code CHAR(5) as PRIMARY KEY since it uniquely identifies each item, while U_Price cannot be a primary key because different items can share the same price, violating the uniqueness rule.

Analysis & Explanation

This question tests both SQL syntax for table creation and conceptual understanding of what qualifies as a primary key.


Concept — CREATE TABLE

The CREATE TABLE statement must list every column with its correct data type exactly as specified (CHAR(5), VARCHAR(20), INTEGER, FLOAT), and the PRIMARY KEY constraint is attached to the column meant to uniquely identify each row — here, W_Code.


Concept — choosing a primary key

A valid primary key candidate must guarantee uniqueness and non-null values across all future records. WCode is designed as a unique item code, making it ideal. UPrice, however, is a numeric attribute that many different items could legitimately share (e.g., two different products both priced at ₹15.00), so it fails the uniqueness test and cannot serve as a primary key.


Exam trap

Students often forget to specify column sizes for CHAR/VARCHAR exactly as given, or place the PRIMARY KEY constraint on the wrong column. For part (b), a common error is answering only 'No' without justification — CBSE requires the reasoning about uniqueness/duplication to earn the mark.

Common Mistakes

  1. 1Omitting column sizes, e.g. writing CHAR instead of CHAR(5) or VARCHAR instead of VARCHAR(20).
  2. 2Placing the PRIMARY KEY constraint on the wrong column, such as U_Price or B_Qty, instead of W_Code.
  3. 3For part (b), simply answering 'No' without explaining that U_Price values are not guaranteed to be unique across records.

Interesting Facts

A PRIMARY KEY constraint in SQL automatically implies both NOT NULL and UNIQUE constraints together — it is essentially shorthand for both rules combined on one or more columns.

CHAR(5) always reserves exactly 5 characters of storage (padding shorter values with spaces), while VARCHAR(20) reserves only as much space as the actual string needs, up to 20 characters — an important storage-efficiency distinction tested frequently in CBSE.

Spotted a mistake or something unclear?

Tell us — we fix reported answers fast.

Frequently Asked Questions

Why must W_Code be the primary key instead of U_Price?

W_Code is designed to be a unique identifier for each stock item, whereas U_Price, being just a numeric price, can repeat across different items, so it cannot guarantee the uniqueness required of a primary key.

What is the difference between CHAR(5) and VARCHAR(20) in the CREATE TABLE command?

CHAR(5) is a fixed-length field that always occupies 5 characters (padding with spaces if needed), while VARCHAR(20) is variable-length and stores only as many characters as actually used, up to a maximum of 20.