ITPEC FE Morning April 2023 Question 29
An employees table contains fields in the order shown below.
- •emp_id is an integer value and is used as the primary key of the table.
- •emp_name can store up to 10 characters.
- •salary is a decimal value up to 4 digits.
Which of the following is an appropriate INSERT statement to insert the data to the table? Here, NOT NULL constraint does not exist and the table does not have any records before the insert.
Explanation
Insert 4 and 'Hulk', leaving salary empty — the only statement whose values fit their columns in type and size.
With a column list, values go to the listed columns in that order; without one, they follow the table's column order, emp_id, emp_name, salary. In (a), emp_id gets 4 (an integer, and the table is empty, so the key is unique), emp_name gets 'Hulk' (4 characters, within 10), and salary is omitted, so it becomes NULL, which is allowed because there is no NOT NULL constraint.
Answer (a)
Why not others:
- •(b) — the column list puts
salarysecond, so'Taylor'goes into the decimal column and 1700 intoemp_name: the values are out of order. - •(c) —
'Bartholomew'has 11 characters, one more thanemp_namecan store. - •(d) — with no column list the values follow table order, so
salarygets 15000, five digits where only four are allowed.
Key rule: INSERT matches values by position to the column list if one is given, otherwise to the table definition's order; then check each value against its column's type and size.
Databases · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.