Skip to content

Commit ee55eb8

Browse files
Create DDL.md
1 parent d39a024 commit ee55eb8

File tree

1 file changed

+56
-0
lines changed
  • docs/DBMS/Structured Query Language

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Data Definition Language (DDL)
2+
3+
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.
4+
5+
## Key DDL Commands
6+
7+
### 1. CREATE
8+
9+
- `CREATE TABLE`: Defines a new table in the database.
10+
```sql
11+
CREATE TABLE table_name (
12+
column1 datatype,
13+
column2 datatype,
14+
...
15+
);
16+
- `CREATE INDEX`: Creates an index on a table to improve data retrieval performance.
17+
18+
```sql
19+
CREATE INDEX index_name ON table_name (column1, column2, ...);
20+
```
21+
- `CREATE VIEW`: Defines a virtual table based on the result set of a `SELECT` query.
22+
23+
```sql
24+
CREATE VIEW view_name AS
25+
SELECT column1, column2 FROM table_name WHERE condition;
26+
```
27+
28+
### 2. ALTER
29+
30+
- `ALTER TABLE` : Modifies the structure of an existing table.
31+
- Add a new column
32+
```sql
33+
ALTER TABLE table_name ADD column_name datatype;
34+
```
35+
- Modify column definition
36+
```sql
37+
ALTER TABLE table_name MODIFY column_name datatype;
38+
````
39+
- Drop a column
40+
```sql
41+
ALTER TABLE table_name DROP COLUMN column_name;
42+
```
43+
44+
### 3. DROP
45+
- `DROP TABLE`: Deletes a table and its data from the database.
46+
```sql
47+
DROP TABLE table_name;
48+
```
49+
- `DROP INDEX`: Removes an index from the database.
50+
```sql
51+
DROP INDEX index_name;
52+
```
53+
- `DROP VIEW`: Deletes a view from the database.
54+
```sql
55+
DROP VIEW view_name;
56+
```

0 commit comments

Comments
 (0)