Overview
The Data Definition Language (DDL) in SQL is used to define and modify database schema objects such as tables, indexes, views, and procedures. DDL statements are central to establishing the structure that stores and organizes data.
On this page
Key Concepts
DDL statements are transactional in most modern relational database systems, meaning they can be rolled back if part of a larger transaction.
- Schema: Logical container for database objects.
- Object Ownership: Determines who can modify or drop an object.
- Dependencies: Changes to one object can affect dependent objects (e.g., dropping a column used in a view).
Primary DDL Statements
| Statement | Description |
|---|---|
CREATE TABLE | Defines a new table and its columns. |
ALTER TABLE | Modifies an existing table (add column, change datatype, etc.). |
DROP TABLE | Removes a table and its data. |
CREATE INDEX | Creates an index to improve query performance. |
DROP INDEX | Deletes an existing index. |
CREATE VIEW | Defines a virtual table based on a query. |
DROP VIEW | Removes a view. |
CREATE SCHEMA | Creates a new schema to group objects. |
Security Considerations
DDL operations require elevated permissions. Grant only the necessary rights using roles such as db_ddladmin or custom permissions.
GRANT CREATE TABLE TO [UserA];
DENY DROP ANY SCHEMA TO [UserB];