UPI Study › Courses › Database Programming › Free lessons › Lesson 3.1 Free with a free account
Data Definition Language (DDL): Concepts and Examples
Database Programming · Chapter 3: Data Definition Language and Schema DesignSection 3.1 · lesson 15 of 769 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: A Complete Guide to DDL Commands →← SQL Constraints: Enforcing Rules on Your DataNext lesson: A Complete Guide to DDL Commands →
A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →
In this lesson
Build, inspect, and test database structure with CREATE, ALTER, and DROP.
- Distinguish DDL statements that change structure from DML statements that change data
- Create a table with a primary key, required columns, unique rules, and defaults
- Inspect structure through the system catalog and INFORMATION_SCHEMA views
- Compare how SQLite, MySQL, and SQL Server handle DDL inside transactions
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 (1,055 words). Read along, or search it.
Opening Problem
An Email Column That Does Not Exist
Maya Rao, owner of Lantern Books, wants customer emails stored beside customer names. Leo Park, the developer, can change one address. But what if the database has no email column at all? Changing a value cannot create its container. The difference decides whether Leo needs a data statement, or a change to the database structure. These fictional examples let us build, inspect, and test a disposable database.
Database Objects
Tables, Views, and Indexes
Data Definition Language, shortened to DDL, defines database structure. CREATE builds an object, ALTER changes it, and DROP removes it. A database groups related objects. A table holds rows under named columns, with rules attached to those columns. A view stores a query definition, giving readers a tablelike interface. An ordinary view does not keep a separate copy of every result row. An index supplies an additional lookup structure. Searches can improve, at a storage and maintenance cost. Objects are containers and helpers, rather than sequential stages.
Structure Versus Data
Adding a Column Versus Updating a Value
Compare these two statements. Adding an email column changes the design, even before any customer receives an address. Updating one customer's city changes a stored value. The column already exists, so that operation belongs to Data Manipulation Language, or DML. INSERT adds rows, UPDATE changes rows, and DELETE removes rows. SELECT reads results; some classifications call it a separate query language. Two other commands commonly grouped with DDL are RENAME and TRUNCATE. Renaming changes an object's name; truncating empties a table while keeping its structure. Product syntax varies. Identify the operation before choosing its spelling.
Server Setup
Creating and Selecting the Shop Database
On MySQL or SQL Server, create a database named shop, then select it with USE before creating tables. These are server syntax listings, not commands for SQLite. SQL Server tools separate database setup into batches with GO. A semicolon terminates a SQL statement. GO is a tool instruction, rather than part of the SQL language. SQLite instead opens a database file through its shell command. Our executable demonstrations use an in-memory database that disappears when the command finishes. Our practice is isolated from the shared shop database.
CREATE TABLE
A Disposable Customer Table with Email
Here is a disposable customer table, using the shared shop's customer identifier and names. We add email as a lesson-specific design extension. The opening line names the table. Parentheses contain column definitions; commas separate them, and a semicolon finishes the statement. The primary key identifies a customer uniquely. Required names use NOT NULL, while city may be absent. Email is required and unique. A missing email fails the required-value rule; a repeated email fails the uniqueness rule. Points receives a default of zero when an insert leaves that column out. A default supplies a value; it does not prohibit an explicitly supplied null. SQLite accepts these type names, but does not enforce the declared VARCHAR length. MySQL counts that length in characters; SQL Server VARCHAR counts bytes.
Data Dictionary
Reading the SQLite System Catalog
The database records its design in metadata, often called the data dictionary or system catalog. Read it rather than trusting a handwritten diagram. SQLite exposes object definitions through sqlite schema. This query asks which named objects exist, rather than which customer rows they contain. The earlier run listed the customer table. A separate column inspection can show names, declared types, defaults, and required-value flags. Structural changes update metadata. Inspect it through supported commands.
Server Metadata
INFORMATION_SCHEMA Views and System Catalogs
MySQL and SQL Server offer INFORMATION_SCHEMA views for inspecting tables and columns. Filter by database or schema to avoid confusing same-named objects. The column view reports a column's name, type, and nullability. Ordering by ordinal position reconstructs the table's column order. MySQL also provides SHOW TABLES and DESCRIBE. SQL Server offers system catalog views such as sys tables, and the help procedure sp help. Each product can describe its own running structure.
Test Row
Verifying Defaults and Nulls with Asha
Now test the design with Asha Verma, the shop's first customer. This file creates a small disposable subset of the table. The insert supplies the required identifier, name, and email. It leaves out city and points. The result shows an absent city as the word NULL, using a shell display setting. Points becomes zero through its default. Empty text is a value. Null means absence. Leo has verified a representative row, rather than just successful table creation.
DDL and Transactions
Implicit Commits and Atomic DDL
A transaction groups work for a decision. COMMIT makes pending changes permanent; ROLLBACK undoes work still pending in that transaction. Ordinary MySQL table DDL can implicitly commit, including earlier data changes. A later rollback cannot restore that earlier pending state. Atomic DDL means a supported statement succeeds or fails as a unit. It does not mean a user can roll back successfully completed MySQL DDL. SQL Server supports rollback for ordinary table DDL inside explicit transactions. Database creation has different restrictions, so do not generalize from tables to every object. Test SQLite directly, keeping its behavior separate from MySQL.
Quick Check
A Rolled-Back Notes Table
Amina Diallo, the database administrator, reviews this fresh SQLite migration. It creates a notes table inside an explicit transaction, then rolls back. The final query counts tables named notes in the catalog. Predict the final count, rather than the number of statements in the file. Will it return one, zero, or an error? Pause, and decide. Zero tables remain. SQLite rolls back the table creation, so the catalog contains no notes table. Run the file to confirm the count. The deciding relationship is between BEGIN, CREATE TABLE, and ROLLBACK. One would describe a surviving table, which is not SQLite's result here. The count query itself is valid, even when its filter matches nothing. Do not transfer this outcome to ordinary MySQL table creation. Its implicit commit changes the transaction boundary.
Cleanup
Repeated Creation and DROP Statements
Creating customers again without a guard fails because the name already exists. That failed attempt does not replace the original table. DROP TABLE removes a table and its rows. DROP DATABASE removes the database; these server commands are shown only as a non-run listing. In SQL Server, switch away from shop before dropping it. In MySQL, ordinary DROP is not recoverable through a later rollback. Closing our in-memory connection discards the practice database.
Key Takeaways
Change Structure, Then Verify It
Leo's email problem needed a structural change before any address could be stored. DDL builds and reshapes those containers. Read the system catalog to verify what actually exists. Then insert a representative row and inspect defaults, nulls, and constraints. Before changing structure, check the product's transaction behavior. A rollback is useful only when the work remains inside its undo boundary. Review real structural changes, and keep recoverable backups.
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 Data Definition Language (DDL): Concepts and Examples
What is Data Definition Language (DDL) in SQL?
How can you see a table's structure in SQL?
Can you roll back a CREATE TABLE statement?
Is GO a SQL statement?
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 →