Worked Examples · Example 8
Q.Write an SQL statement to create a table named 'Customer' with the fields CustID (whole number, primary key), Name (text up to 40 characters), City (text up to 20 characters) and Phone (text up to 15 characters).
Maharashtra MsbshseTextbookSubjectiveImportance★★★★★est
79% · 11/14 Questions
✓ Free question
To create a new table we use the CREATE TABLE statement, listing each field followed by its data type. A whole number uses INTEGER, and text of up to n characters uses VARCHAR(n). The field that uniquely identifies each record is marked PRIMARY KEY. (A phone number is stored as text, not a number, because it may contain leading zeros, spaces or a + sign and is never used for arithmetic.)
Applying this to the requirement:
CustID— whole number and primary key →CustID INTEGER PRIMARY KEYName— text up to 40 characters →Name VARCHAR(40)City— text up to 20 characters →City VARCHAR(20)Phone— text up to 15 characters →Phone VARCHAR(15)
The complete statement is:
CREATE TABLE Customer (
CustID INTEGER PRIMARY KEY,
Name VARCHAR(40),
City VARCHAR(20),
Phone VARCHAR(15)
);
This creates an empty Customer table with the four required fields, ready for records to be inserted.
✓Final answer
CREATE TABLE Customer (
CustID INTEGER PRIMARY KEY,
Name VARCHAR(40),
City VARCHAR(20),
Phone VARCHAR(15)
);
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.