> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/database/sql-databases/sql-fundamentals/sql-commands/ddl-data-definition-language.md).

# DDL (Data Definition Language)

It is used to define the structure of the database schema, including creating, altering, and dropping schema objects like tables, views, indexes, and users.

{% hint style="info" %}
DDL does not include creating the database itself in oracle context. DDL commands are specifically used to define the structure of objects within an existing database. It is included in some database management systems (DBMS), such as MySQL and PostgreSQL.
{% endhint %}

## CREATE

Creates a new database object.

* Syntax

```
CREATE [schema_name.]object_type [object_name] ([object_definition]);
```

* Example

```
CREATE TABLE Customers (
  CustomerID NUMBER PRIMARY KEY,
  CustomerName VARCHAR2(50) NOT NULL,
  Email VARCHAR2(100) UNIQUE,
  Phone VARCHAR2(20)
);
```

## ALTER

Modifies the structure of an existing database object.

* Syntax

```
ALTER [schema_name.]object_type [object_name] [alter_definition];
```

* Example

```
ALTER TABLE Customers ADD Age NUMBER;
ALTER TABLE Orders MODIFY COLUMN OrderDate DATE FORMAT 'YYYY-MM-DD';
```

## DROP

Removes a database object from the schema.

* Syntax

```
DROP [schema_name.]object_type [object_name];
```

* Example

```
DROP TABLE Orders;
```

## TRUNCATE

Removes all rows from a table, but preserves the table structure. This is a faster alternative to DROP and then CREATE, but <mark style="background-color:red;">cannot be rolled back</mark>.

* Syntax

```
TRUNCATE TABLE [schema_name.]table_name;
```

* Example

```
TRUNCATE TABLE Orders;
```

## COMMENT

Adds a comment to a database object to provide descriptive information

* Syntax

```
COMMENT ON [schema_name.]object_type [object_name] IS 'comment_text';
```

* Example

```
COMMENT ON TABLE Customers IS 'Stores customer information';
```

## RENAME

Renames a database object.

* Syntax

```
RENAME [schema_name.]object_type [old_name] TO [new_name];
```

* Example

```
RENAME TABLE Users TO Application_Users;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/database/sql-databases/sql-fundamentals/sql-commands/ddl-data-definition-language.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
