Databases and SQL: Question 8

Syllabus 8.3

Multiple choice AS 1 mark

A database developer runs four different SQL statements while maintaining and using a STOCK database:

A. UPDATE STOCK SET Price = Price * 1.10 WHERE Category = 'Electronics';
B. ALTER TABLE STOCK ADD Category VARCHAR(20);
C. SELECT ProductName, Price FROM STOCK WHERE Price > 50.00;
D. DELETE FROM STOCK WHERE Quantity = 0;

Which one of these four statements is a Data Definition Language (DDL) statement, rather than a Data Manipulation Language (DML) statement?

Choose an answer to check it, then compare with the worked solution below.

Show worked solution Hide worked solution

Worked solution

Why B is correct

Data Definition Language (DDL) statements define or change the structure of a database - creating tables, or altering which fields a table has. Data Manipulation Language (DML) statements work with the data values already stored inside that structure - retrieving, inserting, changing or removing rows.

ALTER TABLE STOCK ADD Category VARCHAR(20); changes what fields the STOCK table has, by adding a brand-new Category field to its structure. This is a change to the table’s definition, not to any data values, so it is DDL.

Why the other options are wrong

  • A (UPDATE) is DML. It does not change STOCK’s structure at all - it changes the value stored in the existing Price field for rows that match the WHERE condition.
  • C (SELECT) is DML. It only retrieves existing data that matches a condition; it does not create, remove or alter any field, and it does not change any stored data either.
  • D (DELETE) is DML. It removes rows of data from STOCK, but the table’s structure (its fields) is completely unaffected - the empty STOCK table, if every row were deleted, would still have exactly the same fields as before.

Final answer

B - ALTER TABLE STOCK ADD Category VARCHAR(20); is DDL because it changes the structure of STOCK (adding a new field), while the other three statements only read or change data values already stored within an unchanged structure.