vault backup: 2026-07-23 09:10:20
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
|
||||
|
||||
### CREATE TABLE
|
||||
```
|
||||
CREATE TABLE table_name (
|
||||
column_name1 data_type1 constraints1,
|
||||
...
|
||||
)
|
||||
```
|
||||
names = Namen
|
||||
type = Datentyp INTEGER, CHAR(n), DATE...
|
||||
constraints = NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY...
|
||||
FOREIGN KEY A REFERENCES B(A)
|
||||
|
||||
### ALTER TABLE
|
||||
|
||||
```
|
||||
ALTER TABLE table_name #vor allen Befehlen
|
||||
---
|
||||
ADD column_name data_type [constraint];
|
||||
---
|
||||
DROP COLUMN column_name;
|
||||
---
|
||||
ALTER COLUMN column_name new_data_type;
|
||||
---
|
||||
ADD CONSTRAINT constraint_name constraint_type (column_name);
|
||||
---
|
||||
DROP CONSTRAINT constraint_name;
|
||||
```
|
||||
|
||||
DROP TABLE (IF EXISTS) table_name : löscht Tabelle + Daten
|
||||
|
||||
### CREATE VIEW
|
||||
Erstellt Relation mit der gearbeitet werden kann
|
||||
Bsp.:
|
||||
```
|
||||
CREATE VIEW Langzeit_Studierende AS
|
||||
SELECT * FROM Student WHERE Semester >= 10;
|
||||
```
|
||||
DROP VIEW Name zum löschen
|
||||
|
||||
### Indexe
|
||||
Effizienteres Suchen in Tabellen
|
||||
```
|
||||
CREATE [UNIQUE] INDEX <name>
|
||||
ON <Relationsname> (<Attributname> [<Ordnung>]{, <Attributname>
|
||||
[<Ordnung>]})
|
||||
```
|
||||
UNIQUE für eindeutigen Index optional
|
||||
Relationsname = Tabelle
|
||||
Attributname = Spalte
|
||||
Ordnung = ASC / DESC
|
||||
Bsp.:
|
||||
```
|
||||
CREATE UNIQUE INDEX idx_student_semester
|
||||
ON Student (Semester ASC);
|
||||
```
|
||||
|
||||
DROP INDEX Name zum löschen
|
||||
@@ -8,62 +8,19 @@ Duplikate möglich!!!
|
||||
1. CREATE TABLE: zum Erstellen einer neuen Tabelle
|
||||
2. ALTER TABLE: zum Ändern einer bestehenden Tabelle
|
||||
3. DROP TABLE: zum Löschen einer Tabelle
|
||||
[[DDL Data Definition Language SQL]]
|
||||
|
||||
## SQL Data Manipulation Language DML
|
||||
1. INSERT
|
||||
2. UPDATE
|
||||
3. DELETE
|
||||
|
||||
### CREATE TABLE
|
||||
### INSERT
|
||||
```
|
||||
CREATE TABLE table_name (
|
||||
column_name1 data_type1 constraints1,
|
||||
...
|
||||
)
|
||||
```
|
||||
names = Namen
|
||||
type = Datentyp INTEGER, CHAR(n), DATE...
|
||||
constraints = NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY...
|
||||
FOREIGN KEY A REFERENCES B(A)
|
||||
|
||||
### ALTER TABLE
|
||||
|
||||
```
|
||||
ALTER TABLE table_name #vor allen Befehlen
|
||||
---
|
||||
ADD column_name data_type [constraint];
|
||||
---
|
||||
DROP COLUMN column_name;
|
||||
---
|
||||
ALTER COLUMN column_name new_data_type;
|
||||
---
|
||||
ADD CONSTRAINT constraint_name constraint_type (column_name);
|
||||
---
|
||||
DROP CONSTRAINT constraint_name;
|
||||
INSERT INTO <tabelle> (spalte1, spalte2, ...) VALUES (wert1, wert2, ...);
|
||||
```
|
||||
|
||||
DROP TABLE (IF EXISTS) table_name : löscht Tabelle + Daten
|
||||
|
||||
### CREATE VIEW
|
||||
Erstellt Relation mit der gearbeitet werden kann
|
||||
Bsp.:
|
||||
### UPDATE
|
||||
```
|
||||
CREATE VIEW Langzeit_Studierende AS
|
||||
SELECT * FROM Student WHERE Semester >= 10;
|
||||
UPDATE <tabelle> SET spalte1 = wert1, spalte2 = wert2, ... WHERE <bedingung>;
|
||||
```
|
||||
DROP VIEW Name zum löschen
|
||||
|
||||
### Indexe
|
||||
Effizienteres Suchen in Tabellen
|
||||
```
|
||||
CREATE [UNIQUE] INDEX <name>
|
||||
ON <Relationsname> (<Attributname> [<Ordnung>]{, <Attributname>
|
||||
[<Ordnung>]})
|
||||
```
|
||||
UNIQUE für eindeutigen Index optional
|
||||
Relationsname = Tabelle
|
||||
Attributname = Spalte
|
||||
Ordnung = ASC / DESC
|
||||
Bsp.:
|
||||
```
|
||||
CREATE UNIQUE INDEX idx_student_semester
|
||||
ON Student (Semester ASC);
|
||||
```
|
||||
|
||||
DROP INDEX Name zum löschen
|
||||
|
||||
Reference in New Issue
Block a user