# DDL Commands

## What are DDL Commands?

DDL or Data Definition Language commands are used to define and manage the structure of database objects like tables, indexes, views etc.

## 📚 Rules for DDL Commands 📚

SQL DDL commands are used to define and modify database schema objects like tables, indexes etc.

### 🗒️ Rules for CREATE Command 🗒️

The CREATE command is used to create a new database object.

* Specify object type (TABLE, INDEX etc.) after CREATE
* Object name must follow standard naming conventions
* Columns, data types, constraints etc. defined within parentheses

```sql
CREATE TABLE users (
  id INT PRIMARY KEY, 
  name VARCHAR(50) NOT NULL
);
```

This creates a new table called `users` with two columns.

### ✏️ Rules for ALTER Command ✏️

The ALTER command modifies an existing database object.

* Specify object name after ALTER
* Add, remove, or modify columns, constraints etc.
* Can rename objects using RENAME TO

```sql
ALTER TABLE users 
ADD email VARCHAR(100);
```

This adds a new column to the existing `users` table.

### ❌ Rules for DROP Command ❌

The DROP command is used to delete objects from the database.

* Specify object type and name after DROP
* Removed object and all associated data are deleted
* Cannot be undone, use with caution

```sql
DROP TABLE users;
```

This permanently deletes the `users` table from the database.

So those are some key rules for the main SQL DDL commands like CREATE, ALTER and DROP. Following SQL standards allows portable DDL across database systems.
