Overview of SQL Language Types
Structured Query Language (SQL) is a powerful tool used to interact with relational databases. It is divided into several language types, each serving a specific purpose:
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- Data Control Language (DCL)
- Transaction Control Language (TCL)
This section focuses on DDL and DML, the two most fundamental components of SQL.
Data Definition Language (DDL)
Data Definition Language (DDL) is used to define and manage the structure of a database. It includes commands that create, modify, and delete database objects such as tables, indexes, and schemas.
Analogy- Think of DDL as the blueprint of a building.
- It defines the structure and layout, but not the contents.
Key DDL Commands
- CREATE: Used to create database objects.
- CREATE TABLE Customer ( CustomerID INT PRIMARY KEY, CustomerEmail VARCHAR(255) );
- ALTER: Modifies the structure of an existing object.
- ALTER TABLE Customer ADD COLUMN CustomerAddress VARCHAR(255);
- DROP: Deletes an object from the database.
- DROP TABLE Customer;
- TRUNCATE: Removes all records from a table but keeps the structure intact.
- TRUNCATE TABLE Customer;
- RENAME: Changes the name of a database object.
- RENAME TABLE Customer TO Client;
DDL commands are autocommitted, meaning changes are immediately saved and cannot be rolled back.