Skip to content

πŸ“˜ Day 92: Data Definition Language (DDL)

Welcome to Day 92! Today, we'll learn about Data Definition Language (DDL), a subset of SQL used to create and manage database objects.

What is DDL?

DDL is used to define the database schema. It includes commands to create, modify, and delete database objects such as tables, indexes, and users.

Key DDL Commands

CREATE

  • Definition: The CREATE command is used to create new database objects.
  • CREATE DATABASE: Creates a new database.
  • CREATE TABLE: Creates a new table in a database.
  • Syntax:
    CREATE TABLE table_name (
        column1 datatype,
        column2 datatype,
        column3 datatype,
       ....
    );
    

ALTER

  • Definition: The ALTER command is used to modify the structure of an existing database object.
  • ALTER TABLE: Used to add, delete, or modify columns in an existing table.
  • ADD: Adds a new column.
  • DROP COLUMN: Deletes a column.
  • MODIFY COLUMN: Changes the data type of a column.
  • Syntax:
    ALTER TABLE table_name
    ADD column_name datatype;
    

DROP

  • Definition: The DROP command is used to delete existing database objects.
  • DROP DATABASE: Deletes an entire database.
  • DROP TABLE: Deletes a table.
  • Syntax:
    DROP TABLE table_name;
    

TRUNCATE

  • Definition: The TRUNCATE command is used to delete all the data inside a table, but not the table itself.
  • Syntax:
    TRUNCATE TABLE table_name;
    

πŸ’» Exercises: Day 92

Please see the exercises.sql file for today's exercises.


Previous: Day 91 – Day 91: Relational Databases β€’ Next: Day 93 – Day 93: Data Manipulation Language (DML)

You are on lesson 92 of 108.