A3.3.1 · Database programming
The languages inside SQL
By the end you can
Outline what the data definition, manipulation, control and transaction languages do.
(structured query language) is the language you use to talk to a relational database. It looks like one language, but its statements fall into four groups, each with a different job.
The four groups#
- creates and changes the structure:
CREATEa table, view or index;ALTERa table (add or drop a column);DROPan object; other systems also haveTRUNCATE(empty a table) andRENAME. - works with the data itself:
SELECTto retrieve,INSERTto add,UPDATEto change andDELETEto remove records. - controls access:
GRANTgives a user a privilege (such as reading one table) andREVOKEtakes it away. It is how the database stays secure. - manages transactions:
BEGIN(orSTART TRANSACTION),COMMITto make changes permanent,ROLLBACKto undo them andSAVEPOINTto mark a point to roll back to (A3.3.6).
A useful way to remember it: DDL changes what the shelves look like, DML changes what is on the shelves, DCL decides who may enter the shop, and TCL lets you undo a whole tidy-up.
Author
| AuthorIDPK | Name | Country |
|---|---|---|
| 1 | Maya Okafor | Nigeria |
| 2 | Liam Chen | China |
| 3 | Sofia Rossi | Italy |
| 4 | Arun Patel | India |
| 5 | Noor Haddad | Egypt |
5 rows. AuthorID INT, Name TEXT(40), Country TEXT(20).
ALTER TABLE Customer ADD Email VARCHAR(40);
SELECT Title FROM Book WHERE Genre = 'Fiction';
GRANT SELECT ON Book TO shop_assistant;
ROLLBACK;
INSERT INTO Customer VALUES (6, 'Fay', 'Seoul');
DROP TABLE Review;
0 of 6 matched
Check yourself
The languages of SQL
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
4 questions · 13 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Distinguish between the data definition language (DDL) and the data manipulation language (DML) in SQL.
[4]Distinguish: Make the differences between two things clear.
2.Identify the type of SQL language (DDL, DML, DCL or TCL) that each of these belongs to: (a) CREATE TABLE, (b) UPDATE, (c) GRANT, (d) COMMIT.
[4]Identify: Pick out the answer from the options or the context.
3.Outline the purpose of the data control language.
[2]Outline: A brief account: the main points, without much detail.
4.Explain the difference between DELETE FROM Customer and DROP TABLE Customer.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
In a nutshell
- SQL (structured query language) is the standard language for relational databases. It has parts for different jobs.
- DDL (data definition): CREATE, ALTER, DROP shape the structure. DML (data manipulation): SELECT, INSERT, UPDATE, DELETE work with the data.
- DCL (data control): GRANT and REVOKE control who may do what. TCL (transaction control): BEGIN, COMMIT, ROLLBACK, SAVEPOINT group changes into transactions.
- DELETE removes rows but keeps the table; DROP removes the table itself.
- Some books count only DDL and DML as the two main languages and treat DCL and TCL as extras; learn all four.
