DDL, DML, and DCL in MySQL: What They Do and When to Use Them

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

← 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 →

Earn 3 college credits for Database ProgrammingRecommended for credit by NCCRS · Computer Science 381 · self-paced · one payment, lifetime access

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.

Compare: Database Fundamentals vs Database Programming

Why take it here

Why students take Database Programming with UPI Study

Write the SQL behind every appDatabase Programming teaches SQL in MySQL and SQL Server side by side: designing and normalizing tables, keys and constraints, data types, inserting, updating and deleting rows, filtering, grouping, joins, subqueries, views, indexes, transactions, and protecting data from SQL injection. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
DDL defines structure, DML changes rows, and DCL controls privileges. Data Definition Language includes CREATE, ALTER, DROP, and RENAME TABLE. Data Manipulation Language includes INSERT, UPDATE, and DELETE, plus REPLACE in MySQL. Data Control Language uses GRANT and REVOKE to decide who may do what. Adding a city column to a table is DDL, while changing one customer's city is DML.
What is an implicit commit in MySQL?
An implicit commit happens when a statement ends the open transaction and saves its pending changes without an explicit COMMIT. In MySQL, ordinary DDL such as ALTER TABLE, account statements such as GRANT and CREATE USER, and starting a new transaction each cause one. If a script updates rows and then runs ALTER TABLE, a later ROLLBACK cannot undo those row changes, because they were already committed.
Is SELECT a DML or a DQL statement?
It depends on the classification: some teaching maps call SELECT Data Query Language, while the MySQL reference manual lists it under Data Manipulation Statements. The label does not change what the query does. An ordinary SELECT reads rows and returns a result without modifying them. Classify each statement by its actual effect, because other statement forms that begin with the same keyword can behave differently.
Does CREATE TEMPORARY TABLE cause an implicit commit in MySQL?
No, in MySQL, CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE do not implicitly commit the open transaction. Their effects still cannot be rolled back, so a temporary table created inside a transaction remains after ROLLBACK. This is an important exception to the usual DDL rule. Other operations on temporary tables, such as ALTER TABLE or CREATE INDEX, can still cause a commit.

About the Database Programming course

How many college credits is Database Programming?
Database Programming (Computer Science 381) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Database Programming cost and what is included?
$250, paid once, with lifetime access: all 76 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Database Programming take?
It is self-paced with no deadlines. The 76 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Database Programming
3 credits · NCCRS
Enroll →