Skip to content

Chapter 3 of 8

Defining Database Structure with DDL

Data Definition Language, or DDL, is the part of SQL used to define and manage the structure of a database, including tables, indexes, and views. The three commands at the heart of DDL are CREATE, ALTER, and DROP. They let a developer build new structures, modify existing ones, and remove structures that are no longer needed.

The CREATE TABLE statement defines a brand-new table by specifying its columns, their data types, and any constraints. For example, CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50)); creates a table with two columns and a primary key on the id. Once a table exists, its structure can evolve using ALTER TABLE, which adds or drops columns and constraints. An example is ALTER TABLE users ADD email VARCHAR(100);, which appends a new email column to the users table.

When a table is no longer needed, the DROP TABLE command permanently removes it along with all of its data. The command DROP TABLE temp_table; is final, so it should be used with care. Together, CREATE, ALTER, and DROP give administrators full control over the database schema, from initial creation through ongoing maintenance.

All chapters
  1. 1Database Fundamentals and SQL
  2. 2Tables, Keys, and Data Types
  3. 3Defining Database Structure with DDL
  4. 4Querying and Modifying Data with DML
  5. 5Aggregates, Joins, and Subqueries
  6. 6Indexes, Views, and Advanced Features
  7. 7Transactions, ACID, and Normalization
  8. 8SQL versus NoSQL and Database Security

Drill it

Reading is not remembering. These come from the SQL And Databases deck:

Q

What is a database?

A database is an organized collection of structured data stored and accessed electronically from a computer system. Databases allow efficient storage, retrieval...

Q

What is a Relational Database Management System (RDBMS)?

An RDBMS is a software system that manages relational databases, organizing data into tables with rows and columns related by keys. It supports SQL for querying...

Q

What are the main types of databases?

Databases are broadly classified into relational (SQL-based, like MySQL) and non-relational (NoSQL, like MongoDB for documents or Cassandra for wide-column stor...

Q

What is SQL?

SQL stands for Structured Query Language, a standard language for managing and manipulating relational databases. It includes sublanguages like DDL for schema d...