UPI Study › Courses › Database Programming › Free lessons › Lesson 1.5 Free with a free account
DDL, DML, and DCL in MySQL: What They Do and When to Use Them
Database Programming · Chapter 1: Getting Started with Databases and SQL SetupSection 1.5 · lesson 5 of 768 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Database Programming.
Lesson complete
Earn the 3 college credits for Database Programming
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: SQL Command Essentials: The Must-Know Statements →← Querying Databases: Definitions and Essential ToolsNext lesson: SQL Command Essentials: The Must-Know Statements →
A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →
In this lesson
How MySQL statement groups differ in effect and transaction behavior.
- Classify MySQL statements as DDL, DML, query, DCL, or transaction control
- Explain how autocommit and implicit commits set MySQL transaction boundaries
- Distinguish DELETE, TRUNCATE TABLE, and DROP TABLE by their effects
- Identify exceptions such as temporary tables and atomic DDL
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (940 words). Read along, or search it.
Opening Question
Will Rollback Undo Everything
Leo changes order data in MySQL, adds a column, and then requests rollback. Can he assume the earlier changes will disappear? The answer depends on transaction boundaries, not how reassuring the word rollback sounds. First, classify the job each command performs. The command names on these boards are recognition examples. They are MySQL concepts, with no simulated terminal results.
Sublanguage Map
Five Jobs for SQL Statements
A sublanguage is a group of statements with related jobs. We use labels for structure, row changes, reading, permissions, and transaction control. These labels are a teaching map, rather than an exhaustive official partition. MySQL's manual groups some statements differently. Think of Lantern Books: build shelves, stock them, browse them, hand out keys, and confirm a sale. Each task has a different effect.
DDL
Defining and Changing Structure
Data Definition Language defines or changes structure: databases, tables, columns, views, and indexes. Create, alter, and drop are familiar command names. Rename table changes an object's name. MySQL also classifies truncate table as definition work, although it empties the stored rows. DDL can inspect, transform, or destroy existing data. Adding a column or removing a table is not merely changing a diagram. For ordinary persistent MySQL DDL, treat a completed change as outside the rollback protection of your surrounding data transaction. We will qualify that rule shortly.
DML
Adding, Changing, and Removing Rows
Data Manipulation Language adds, changes, or removes rows. Insert, update, delete, and MySQL's replace belong to this working group. Changing Asha's city is row manipulation. Adding a city column is definition work; the difference is the object of the change. A table can keep its column definitions, while the values and row count change. Transactions can protect these related changes on transactional tables. Use a transactional engine, such as InnoDB, when relying on rollback. The label DML alone cannot make a nontransactional table undo its work.
Reading Data
SELECT and Data Query Language
Data Query Language is our label for reading data, mainly through ordinary select queries. The result answers a question about records. MySQL's reference manual places select under Data Manipulation Statements. That labeling difference does not change the query's meaning. Our simple select examples read rows without modifying them. Other statement forms and features require their own behavior checks. Classify the exact operation, rather than assuming every statement beginning with the same keyword has identical side effects.
DCL
GRANT, REVOKE, and User Accounts
Data Control Language concerns privileges: who may do what. Grant gives a privilege, and revoke withdraws it. Creating an account is a related but distinct task. Create user establishes an account; grant assigns permissions to an account. MySQL files account commands under account management. Grant, revoke, and ordinary account-management commands cause implicit commits. A wrong privilege needs a corrective permission statement. A later rollback does not simply cancel a successful grant.
TCL
Transaction Boundaries and Savepoints
Transaction Control Language defines transaction boundaries. Start transaction begins a unit; commit saves its changes, and rollback discards pending transactional changes. A savepoint marks a position within a transaction. Rolling back to it can discard later work, while leaving earlier pending work in place. After commit, a later rollback cannot reach the saved transaction. You need another deliberate change or a recovery procedure. In MySQL, beginning another transaction commits an existing one; it does not create a nested transaction. Keep the intended boundary explicit.
Implicit Commits
ALTER TABLE Commits Pending Changes
MySQL normally enables autocommit. A successful standalone data-changing statement on transactional tables commits automatically, unless an explicit transaction changes that boundary. An implicit commit is different: certain statements end an open transaction without an explicit commit command. Ordinary persistent DDL and account commands commonly do this. Return to Leo's sequence. Start transaction, change rows, then run alter table: the alter triggers a commit of the pending row changes. The later rollback cannot undo those committed changes. This is MySQL behavior; SQLite's transactional DDL must not be used to demonstrate the opposite claim.
Exceptions
Temporary Tables and Atomic DDL
There are important exceptions. MySQL create temporary table and drop temporary table do not implicitly commit, but their effects still cannot be rolled back. Creating a temporary table, then rolling back, leaves that temporary table in existence. Do not extend the ordinary DDL shortcut blindly. Supported atomic DDL operations, with appropriate engines, finish completely or leave no partial operation after failure. That is statement-level atomicity. A successfully completed DDL operation is still not undone by your later rollback. Atomic completion and user-controlled undo answer different questions.
Removal Commands
DELETE, TRUNCATE, and DROP Compared
Delete removes chosen rows, or all rows without a filter. It leaves the table structure, and can be rolled back before commit on transactional tables. MySQL truncate table removes all rows, while leaving the table available. It is DDL, with implicit-commit behavior and no ordinary rollback rescue. Drop table removes the table itself and its data. That is a different structural effect from an empty table. Likewise, alter changes structure while update changes values. Classifying by effect is more reliable than noticing that both verbs suggest change.
Quick Check
Two START TRANSACTION Statements
On transactional MySQL tables, a script starts a transaction, changes a price, then starts another transaction, changes stock, and rolls back. Which changes remain? Treat each start as an actual transaction-control statement. Pause, and decide.
Answer Explained
Only the Price Change Remains
Only the first row change remains. Starting the second transaction commits the pending price change; rollback then discards the later stock change. Both cannot remain, because the stock change was still pending. Neither cannot remain, because the price change had already committed. The second start did not create a nested transaction. Follow the boundaries, rather than assuming the script forms one undoable unit.
Key Takeaways
Classify by Effect and Boundary
Classify the purpose: structure, row changes, reading, permissions, or transaction control. Distinguish a command's teaching group from its actual behavior in the target database. Use transactional storage and explicit boundaries when pending changes must remain undoable. Check implicit commits and exceptions before mixing structure or account changes into a MySQL workflow.
About Database Programming at UPI Study
Database Programming (Computer Science 381) is a self-paced online course of 76 video lessons in 12 chapters, from database applications, SQL setup, schema planning and normalization to keys and constraints, data types, filtering and sorting, joins, subqueries, views, indexes, ROLLUP and PIVOT, regular expressions and database security. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every credit course with PRO →
Why take it here
Why students take Database Programming with UPI Study
Where the credit goes
Universities that work with NCCRS
Database Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About DDL, DML, and DCL in MySQL: What They Do and When to Use Them
What is the difference between DDL, DML, and DCL in SQL?
What is an implicit commit in MySQL?
Is SELECT a DML or a DQL statement?
Does CREATE TEMPORARY TABLE cause an implicit commit in MySQL?
About the Database Programming course
How many college credits is Database Programming?
How much does Database Programming cost and what is included?
Which universities accept UPI Study credits?
How long does Database Programming take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Database Programming.
76 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →