Q.Choose appropriate answer with respect to the following code snippet.
CREATE TABLE student (
name CHAR(30),
student_id INT,
gender CHAR(1),
PRIMARY KEY (student_id)
);
SelecT * fROM student;
INSERT INTO student
VALUES ("Suhana",109,'F'),
VALUES ("Rivaan",102,'M'),
VALUES ("Atharv",103,'M'),
VALUES ("Rishika",105,'F'),
VALUES ("Garvit",104,'M'),
VALUES ("Shaurya",109,'M');
DELETE student
WHERE student_id=109;
Five short MCQs on one CREATE TABLE snippet. The keys: degree = number of columns (3); name is a column; SQL keywords are case-insensitive so the odd-looking SelecT * fROM runs and shows headers + rows; the multi-row INSERT repeats the keyword VALUES so it errors; and the DELETE is missing FROM, so it errors and no row is deleted.
The snippet under discussion:
CREATE TABLE student (
name CHAR(30),
student_id INT,
gender CHAR(1),
PRIMARY KEY (student_id)
);
a) Degree of the student table
The degree of a relation is its number of attributes (columns). Here there are exactly three: name, student_id, gender — the PRIMARY KEY (student_id) line is a constraint, not a fourth column.
- (i) 30 is just the size of
CHAR(30); (ii) 1 confuses degree with the single key column; (iv) 4 wrongly counts the constraint line. - Correct: (iii) 3.
b) What does name represent?
name is declared inside CREATE TABLE with a data type (CHAR(30)), which is precisely how a column is defined.
- (i) the table is
student; (ii) rows only come into existence viaINSERT; (iv) a database is created byCREATE DATABASE. - Correct: (iii) a column.
c) SelecT * fROM student;
SQL keywords are case-insensitive, so this strange capitalisation is perfectly legal — option (iii) "error" is out. SELECT * retrieves every column of every row, and the client displays the result as a table with the column names as headers above the contents:
SelecT * fROM student;
| name | student_id | gender |
|---|---|---|
| ... | ... | ... |
So the most precise option is the one that mentions both the column names and the contents — (i) is incomplete, (iv) is the opposite of what happens.
- Correct: (ii) Displays column names and contents of table 'student'.
d) The multi-row INSERT
INSERT INTO student
VALUES ("Suhana",109,'F'),
VALUES ("Rivaan",102,'M'),
...
The keyword VALUES may appear only once; the row tuples after it are separated by commas alone. Repeating VALUES before every row is a syntax error, so the statement fails immediately. (Even after fixing the syntax it would still fail: student_id 109 appears twice — "Suhana" and "Shaurya" — violating the primary key with ERROR 1062: Duplicate entry '109'.) The correct multi-row form, for reference:
INSERT INTO student VALUES
('Suhana', 109, 'F'),
('Rivaan', 102, 'M'),
('Atharv', 103, 'M'),
('Rishika', 105, 'F'),
('Garvit', 104, 'M');
- (ii)/(iv) claim success, which the syntax rules out; (iii) is a distractor — SQL syntax validity does not "depend on compiler".
- Correct: (i) Error.
e) DELETE student WHERE student_id=109;
The statement is missing the keyword FROM — the valid form is DELETE FROM student WHERE .... As written it is a syntax error, the statement never executes, and therefore no row is deleted.
- (i)/(iv) assume the query runs; (ii) describes what the corrected query would do — and even then, since
student_idis the primary key, at most one row can hold 109. - Correct: (iii) No row will be deleted.
a) (iii) 3 — degree = number of columns.
b) (iii) a column — declared with type CHAR(30).
c) (ii) Displays column names and contents — keywords are case-insensitive; the result shows headers plus rows.
d) (i) Error — VALUES must appear only once (and 109 is duplicated anyway).
e) (iii) No row will be deleted — FROM is missing, so the statement errors out.
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.