Q.Create table STUDENT.
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 →Example 9.1 asks you to create the STUDENT table for the StudentAttendance database using the exact schema already worked out in Table 9.3 — RollNumber, SName, SDateofBirth, GUID — with only the primary key declared inline.
Why This Table, These Columns
This example is not a generic "design any student table" exercise — it is the payoff of the planning done earlier in the chapter. Section 9.4.2 walked through why each attribute of STUDENT gets the data type it has: RollNumber is INT because a class has at most 100 students (3 digits suffice); SName is VARCHAR(20) for a variable-length name; SDateofBirth is DATE; and GUID — the guardian's 12-digit Aadhaar number — is CHAR(12), a fixed-length code with no arithmetic ever performed on it. Table 9.3 lays these out formally, including that RollNumber is the PRIMARY KEY and GUID is eventually a FOREIGN KEY.
The SQL Solution
For simplicity, this first CREATE TABLE statement leaves out constraints other than the primary key — NOT NULL and the foreign key relationship on GUID are added afterwards using ALTER TABLE, in Section 9.4.4:
mysql> CREATE TABLE STUDENT(
-> RollNumber INT,
-> SName VARCHAR(20),
-> SDateofBirth DATE,
-> GUID CHAR(12),
-> PRIMARY KEY (RollNumber));
Query OK, 0 rows affected (0.91 sec)
Key Lines Explained
RollNumber INT— a whole number, large enough for roll numbers 1–100.SName VARCHAR(20)— variable-length text, noNOT NULLyet (added later in 9.4.4(F)).SDateofBirth DATE— a calendar date in'YYYY-MM-DD'format.GUID CHAR(12)— a fixed 12-character code; becomes aFOREIGN KEYtoGUARDIANonly later, in 9.4.4(B). …
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.