Skip to content

Create DDL.md #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions docs/DBMS/Structured Query Language/DDL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Data Definition Language (DDL)

Data Definition Language (DDL) is a subset of SQL used to define, modify, and delete database objects such as tables, indexes, views, and constraints. DDL statements enable users to create and manage the structure of the database schema.

## Key DDL Commands

### 1. CREATE

- `CREATE TABLE`: Defines a new table in the database.
```sql
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
- `CREATE INDEX`: Creates an index on a table to improve data retrieval performance.

```sql
CREATE INDEX index_name ON table_name (column1, column2, ...);
```
- `CREATE VIEW`: Defines a virtual table based on the result set of a `SELECT` query.

```sql
CREATE VIEW view_name AS
SELECT column1, column2 FROM table_name WHERE condition;
```

### 2. ALTER

- `ALTER TABLE` : Modifies the structure of an existing table.
- Add a new column
```sql
ALTER TABLE table_name ADD column_name datatype;
```
- Modify column definition
```sql
ALTER TABLE table_name MODIFY column_name datatype;
````
- Drop a column
```sql
ALTER TABLE table_name DROP COLUMN column_name;
```

### 3. DROP
- `DROP TABLE`: Deletes a table and its data from the database.
```sql
DROP TABLE table_name;
```
- `DROP INDEX`: Removes an index from the database.
```sql
DROP INDEX index_name;
```
- `DROP VIEW`: Deletes a view from the database.
```sql
DROP VIEW view_name;
```
Loading