Roles, queries, and transactions
Roles around a database, queries vs statements, DDL DML DCL, the data dictionary, transactions, ACID, and knowledge bases — with the usual note-taking shortcuts corrected.
Roles, SQL, and transactions
If you connect roles + SQL commands + transactions + ACID correctly, the rest of SQL gets much easier.
Along the way we flag where lecture notes oversimplify or are not scientifically precise — so you are ready for the exam and do not learn the standard terms wrong.
1. Build the big picture first
In the previous lesson we had:
User / Application → DBMS → DatabaseNow the questions are:
- Who decides what data we should have?
- Who manages the database?
- How does an application ask the DBMS for something?
- What happens when several operations must run together?
This lesson answers exactly those questions.
2. Who works with the database?
Imagine a university system.
Students, teachers, the registrar, and finance all use it — but they do not share one role.
| Role | Full name | Simple job |
|---|---|---|
| End User | End user | Uses the system |
| DA | Data Administrator | Sets data policy and needs |
| DBA | Database Administrator | Manages the database technically |
| DB Developer / Programmer | Database programmer | Implements code, queries, and needed structures |
3. What is an end user?
End user uses the system but does not need to know SQL or database design.
A registrar clicks “enroll student” and may never see what runs behind that button:
INSERT INTO students ...So the end user works with the system, not necessarily with the database directly.
Examples: a student, a bank teller, a registrar, a shop clerk.
4. What is a DA?
DA = Data Administrator
This role focuses on data policy and management at the organization level.
A university must decide:
- What student information do we keep?
- Do we also need medical data?
- Who may see grades?
- How many years should we retain records?
student_id
name
national_code
major
phoneThese are organizational decisions more than technical ones.
The DA says what data we have and under what policy it is managed.
In real organizations the DA/DBA boundary is not always the same, and a separate DA job title may not exist.
For the course model, remember:
DA = data policy maker
5. What is a DBA?
DBA = Database Administrator — the technical manager of the database.
Suppose the organization decided: “A student must not see another student’s grade.” That is an organizational need. Someone must implement it technically.
A DBA may own:
- User management
- Permissions
- Backup
- Recovery
- Performance
- Security
- Monitoring
- Database maintenance
The DA decides data policy; the DBA manages the database environment technically.
6. What is a DBP?
The notes say DBP = Database Programmer. In today’s market you more often see Database Developer or SQL Developer.
They write queries, build procedures, work with tables, and develop the database side of the application.
SELECT *
FROM students
WHERE major = 'Computer';Or they design a stored procedure to place an order.
Mental model:
DA
↓ data policy
DBA
↓ technical database management
Database Developer
↓ implementation and queries
End User
↓ uses the systemIn a real project the jobs often overlap.
7. What is a query?
This part matters a lot.
A query is a request to retrieve or inspect information from the database.
Example: show every purchase made by Ali.
SELECT *
FROM purchases
WHERE customer_name = 'Ali';That means: from the purchases table, return rows whose customer_name is Ali.
8. Is every SQL command a query?
In everyday programming we often call every SQL statement a query. More precisely:
SELECT * FROM students;is clearly a query — it asks a question of the data. But:
CREATE TABLE students (...);is more an SQL statement than a query in the narrow sense.
The broader term is SQL statement.
9. Why is SQL declarative?
SQL is mainly a declarative language.
You tell the DBMS what you want, not exactly how to find it.
SELECT *
FROM students
WHERE city = 'Tehran';You did not say “start at the first record, then read memory…”. You only said you want students in Tehran.
The DBMS chooses how to run it. That choice is usually made by a query optimizer.
10. What is a host language?
Suppose the app is written in C#. That program may run SQL inside it.
C# is the main application language; SQL is used to talk to the database.
Older sources call C# or Java the host language.
“SQL is the guest” is a teaching metaphor, not a term you must memorize.
11. Now DDL, DML, and DCL
This part is often exam material. A useful metaphor:
Treat the database as a building.
- DDL builds the building.
- DML changes what is inside.
- DCL decides who may enter and act.
12. What is DDL?
DDL = Data Definition Language. It works with database structure.
CREATE TABLE students (
id INT,
name VARCHAR(100)
);That creates the table.
ALTER changes an existing structure:
ALTER TABLE students
ADD city VARCHAR(50);The table is still students, but it gained a column.
DROP removes a database object:
DROP TABLE students;The table itself is gone.
For now, remember CREATE, ALTER, DROP as DDL.
13. What is DML?
DML = Data Manipulation Language. We are not building table structure; we work with the rows inside.
Insert:
INSERT INTO students (id, name)
VALUES (1, 'Sara');Update:
UPDATE students
SET city = 'Isfahan'
WHERE id = 1;Delete data:
DELETE FROM students
WHERE id = 1;And reading data:
SELECT *
FROM students;Many courses teach SELECT as DML. Some taxonomies split it out as DQL = Data Query Language.
If your instructor said SELECT → DML, answer that way in that class — and know the DQL split also exists.
14. DELETE vs DROP
A classic exam question. Suppose students is a table.
If you say:
DELETE FROM students;the rows are removed, but the table remains. But:
DROP TABLE students;the table itself is removed.
DELETE → Data
DROP → Structure15. What is DCL?
DCL = Data Control Language — control of access.
Give Ali SELECT permission:
GRANT SELECT
ON students
TO ali;To take it back:
REVOKE SELECT
ON students
FROM ali;GRANT → give permission
REVOKE → take permission away16. A table worth memorizing
| Group | Main job | Examples |
|---|---|---|
| DDL | Structure | CREATE, ALTER, DROP |
| DML | Data | INSERT, UPDATE, DELETE, usually SELECT |
| DCL | Permission | GRANT, REVOKE |
A memory hook:
- DDL → Design
- DML → Modify data
- DCL → Control
Not etymologically exact, but useful for recall.
17. Data dictionary and metadata
The DBMS must know which tables exist, which columns they have, each column’s type, which users exist, and which permissions they hold.
That information about the database is metadata.
students.name → VARCHAR(100) is about structure. “Sara” is data; the fact that name is VARCHAR(100) is metadata.
The DBMS keeps this metadata in a data dictionary or system catalog.
The data dictionary is the set of metadata about database structure and objects.
For example: table name, column name, data type, constraints, indexes, users, privileges — and more, depending on the DBMS.
18. What is a transaction?
This is the most important part of the lesson.
A transaction is a set of operations the system treats as one logical unit of work.
Classic example: transfer 1,000,000. Two main operations:
Account A → -1,000,000
Account B → +1,000,000These two operations are not independent. They must happen together.
19. Where is the problem?
Suppose the first step ran:
A - 1,000,000Then power failed, and this never ran:
B + 1,000,000Money left A but never reached B. The system is now wrong.
So these two operations are one transaction: both succeed, or neither does.
20. What is COMMIT?
If every operation in the transaction succeeded:
COMMIT;Conceptually: make the changes final.
A = -1M
B = +1M
COMMITThe transaction has finished successfully.
21. What is ROLLBACK?
If something goes wrong:
ROLLBACK;Undo the changes made by this transaction.
A = -1M
ERROR!
ROLLBACKA returns to its previous state.
Some notes say ABORT. Abort means the transaction failed or was cancelled. In SQL the command you usually use is ROLLBACK.
COMMIT → make final
ROLLBACK → undo22. Now ACID
The four main transaction properties are remembered as ACID:
- A → Atomicity
- C → Consistency
- I → Isolation
- D → Durability
Do not only memorize them — understand them.
23. A — Atomicity
Atomicity = all or nothing
A transaction cannot be left half-done.
In a transfer, debit ✔ and credit ✘ is not acceptable.
Either both succeed, or neither does.
All or nothing
24. C — Consistency
Consistency means a transaction must take the database from one valid state to another valid state.
Example rule: balance >= 0
If an account has 500,000, a 1,000,000 transfer must not leave balance = -500,000 when the rules forbid it.
A transaction must not break the database’s valid rules.
25. I — Isolation
Isolation keeps concurrent transactions from interfering incorrectly.
Two people withdraw from the same account at once. Balance is 1,000,000. A wants 700,000 and B wants 700,000 at the same time.
If the DBMS does not control concurrency, both may see 1,000,000 and both withdraw. That is a concurrency problem.
Isolation stops concurrent transactions from leaving a wrong combined result.
26. Does isolation always mean locking?
No. This is a place many notes oversimplify.
Locking is one technique. DBMS products can also use MVCC — Multi-Version Concurrency Control.
Isolation is the result we want; locking is one technique for getting there.
27. D — Durability
Durability means if the DBMS said the commit succeeded, the change must not vanish a few seconds later — even after a crash.
Does durability mean mirroring? No. Notes that say that are imprecise.
Mirrors or replication can help, but they are not the definition. A DBMS can guarantee durability with a transaction log, write-ahead logging, recovery, and persistent storage.
Durability: a committed change must survive a crash.
28. Learn ACID with one full transfer
Suppose:
A = 5,000,000
B = 2,000,000We transfer 1,000,000. Afterward:
A = 4,000,000
B = 3,000,000- Atomicity — A must not be debited alone.
- Consistency — database rules must still hold.
- Isolation — other transactions must not see a half-finished state.
- Durability — after COMMIT, a restart must not erase the transfer.
If this example is clear, you essentially understand ACID.
29. Are integrity and consistency the same?
They are not identical, though they are closely related.
Data integrity is the broader idea that data stays correct and valid.
Consistency in ACID says a transaction must preserve the database’s constraints and rules.
So consistency is one of the things that helps keep the database valid.
30. “Internal and external integrity” in the notes
You may see “internal vs external integrity” in a university handout. It is not a standard split used the same way in all database texts.
For a solid foundation, focus on the well-known integrity kinds:
- Entity integrity
- Referential integrity
- Domain integrity
- User-defined constraints
Grade between 0 and 20: domain constraint. A registration needs a real student: referential integrity. A unique primary key: entity integrity.
These become much more important later.
31. Does every task go straight to the OS?
The note that “every task goes to the OS but a transaction goes to the DBMS” is oversimplified. Do not memorize it.
The application usually talks to the DBMS. The DBMS itself talks to the operating system for disk, memory, file I/O, and more.
A better model:
Application
↓
DBMS
↓
Operating System
↓
Storage32. What is a knowledge base?
A database is mainly for storing and managing structured data. For example:
Teacher: Ali
Skills:
CCNA
CCNPThose are facts.
A knowledge base may also keep rules, semantic relations, and inference structure. For example:
CCNP → Advanced Networking Skill
Advanced Networking Skill
→ Eligible for Advanced Network CourseThe system can infer from what it already knows.
The claim that a knowledge base “must use AI and NLP” is false. A knowledge base may be used in AI, but it does not require AI or NLP. Expert systems used knowledge bases long before language models.
33. Database vs knowledge base
Simply:
- Database: What data do we have?
- Knowledge Base: What do we know, and what relationships or rules exist?
A database might store:
Sara
age = 22
major = ComputerA knowledge base may add rules and semantic relations on top of those facts.
34. The whole lesson on one map
Roles and the data path:
Organization
│
▼
DA
data policy and needs
│
▼
DBA
technical database management
│
▼
Database Developer
SQL / implementation
│
▼
DBMS
│
▼
DatabaseThe end user uses an application:
End User
↓
Application
↓
DBMS
↓
DatabaseAnd to talk to the DBMS:
SQL
├── DDL → Structure
├── DML → Data
└── DCL → PermissionsAnd when several operations are one unit of work:
Transaction
↓
ACID35. Know this table well for the exam
| Question | Answer |
|---|---|
| Who uses the system? | End user |
| Who sets data policy? | DA |
| Who manages the database technically? | DBA |
| Who writes queries and implements the DB? | Database developer / DBP |
| What is CREATE? | DDL |
| What is ALTER? | DDL |
| What is DROP? | DDL |
| What is INSERT? | DML |
| What is UPDATE? | DML |
| What is DELETE? | DML |
| What is SELECT? | Usually DML; sometimes DQL |
| What is GRANT? | DCL |
| What is REVOKE? | DCL |
| What is information about database structure? | Metadata |
| Where is metadata kept? | Data dictionary / system catalog |
| Finalize a transaction? | COMMIT |
| Undo a transaction? | ROLLBACK |
| All or nothing? | Atomicity |
| Preserve database rules? | Consistency |
| Control concurrent transactions? | Isolation |
| Keep the result after commit? | Durability |
Next session is the relational model, tables, and keys: entity, attribute, primary key, foreign key, and relationship types. After that we move to ER diagrams.