Home › Theme A › A3 › A3.3 › A3.3.1

A3.3.1 SQL's sub-languages: DDL, DML and more

SL + HLCommand term: Outline

1. Watch a database change

Press Next to run SQL statements one at a time. Two boxes show the database: its structure (what DDL changes) and its data (what DML changes). The box that changes lights up.

2. SQL sandbox: run the statements yourself

Click a statement to run it on the Student database. Try them in the wrong order to see the error messages.

Log: nothing run yet.

3. Flip-card deck

Click to flip. Say the answer before you flip.

4. Pick the statement

Table: Student(StudentID, Name, Grade). Choose the statement that does the job. Streaks of 3+ score double.

Round 0/10Score 0Streak 0Best 0
Press start!

5. 45-second speed round: DDL or DML?

A command or a job appears. Which type of SQL is it?

Time 45sScore 0Streak 0Best 0
Press start!

Learning objectives

By the end of this page you should be able to:

  1. Outline the purpose of data definition language (DDL).
  2. Outline the purpose of data manipulation language (DML).
  3. Identify whether a given SQL statement is DDL or DML.
  4. Outline the statements CREATE, ALTER and DROP, and SELECT, INSERT, UPDATE and DELETE.
  5. Distinguish between commands that are often confused, such as DROP and DELETE, or ALTER and UPDATE.

SQL: one language, different jobs

SQL (Structured Query Language) is the standard language for working with relational databases. Its statements fall into groups by purpose. At this level you must know two.

DDL: data definition languageDML: data manipulation language
PurposeDefine and change the structure (schema) of the databaseAdd, change, remove and retrieve the data stored in the tables
What it works onTables, columns, data types, keys, constraintsRecords (rows) and their values
Main statementsCREATE TABLE, ALTER TABLE, DROP TABLEINSERT INTO, UPDATE ... SET, DELETE FROM, SELECT
ExampleALTER TABLE Student ADD Email VARCHAR(50);UPDATE Student SET Grade = 7 WHERE StudentID = 2;
EffectChanges what the database is: the table layout. Often takes effect at once.Changes what the database holds: the records. Table layout stays the same.
Used byDatabase designers and administratorsProgrammers, applications and users

Memory aid: Data Definition = Design the tables. Data Manipulation = Move the data around.

The statements

  • CREATE TABLE builds a new table: its columns, data types and keys.
  • ALTER TABLE changes an existing table, e.g. ADD or DROP COLUMN.
  • DROP TABLE deletes the whole table: structure and data.
  • INSERT INTO ... VALUES adds a new record.
  • UPDATE ... SET ... WHERE changes values in existing records. Without WHERE it changes every row.
  • DELETE FROM ... WHERE removes records but keeps the table. Without WHERE it removes all rows.
  • SELECT retrieves data without changing it. In this course it is treated as DML (some textbooks call queries DQL).

Common confusions

  • DELETE vs DROP: DELETE FROM Student; empties the table (DML). DROP TABLE Student; removes the table itself (DDL).
  • ALTER vs UPDATE: ALTER changes the columns (DDL). UPDATE changes values in rows (DML).
  • Order matters: CREATE the table before you INSERT into it, and ALTER in a column before you store values in it.

Other types exist, for example control of permissions (DCL) and transactions (TCL, covered at HL in A3.3.6). The syllabus focus here is DDL and DML. Queries across tables with joins come in A3.3.2.

Use the 中文 button at the top to show or hide the Chinese terms.

Term中文Meaning

Choose an answer. You get instant feedback.

Score: 0 /

Write your answer first, then reveal the markscheme. These are exam-style practice questions written for this site.

1. Outline the purpose of data definition language (DDL). [2]

DDL is used to define / create / modify / remove the structure of a database (tables, columns, data types) [1]; for example CREATE TABLE, ALTER TABLE or DROP TABLE [1].

2. Outline the purpose of data manipulation language (DML). [2]

DML is used to add, change, delete and retrieve the data (records) stored in the tables [1]; for example INSERT INTO, UPDATE, DELETE or SELECT [1].

3. State whether each SQL statement is DDL or DML: (a) CREATE TABLE, (b) UPDATE, (c) DROP TABLE, (d) INSERT INTO. [4]

(a) DDL [1]; (b) DML [1]; (c) DDL [1]; (d) DML [1].

4. Outline two differences between DDL and DML. [4]

Award [2] for each difference outlined, up to [4]. DDL defines / changes the structure of the database [1] whereas DML works with the data inside the tables [1]. DDL statements (CREATE, ALTER, DROP) change tables and columns [1] whereas DML statements (INSERT, UPDATE, DELETE, SELECT) change or retrieve records and leave the table layout unchanged [1]. DDL is mainly used by designers / administrators [1] whereas DML is used by applications and users day to day [1]. Accept: DDL changes usually take effect immediately / cannot easily be undone, while DML changes can often be undone (rolled back) within a transaction [2].

5. A school uses a table Student(StudentID, Name, Grade). Write SQL statements to (a) add a new column Email of type VARCHAR(50) to the table [2], (b) change the grade of the student named Ben to 7. [3]

(a) ALTER TABLE Student [1] ADD Email VARCHAR(50); [1]. (b) UPDATE Student [1] SET Grade = 7 [1] WHERE Name = 'Ben'; [1]. Accept minor syntax variations between database systems.

6. A teacher runs DELETE FROM Student; and a colleague runs DROP TABLE Student;. Explain the difference in effect. [3]

DELETE FROM removes all the records but the table structure remains [1]; it is a DML statement, so new records can still be inserted [1]. DROP TABLE removes the whole table, including its structure and data [1]; it is a DDL statement, and the table no longer exists (it would have to be created again) [1]. Maximum [3].