vault backup: 2026-07-23 10:55:26
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
|
||||
Reference in New Issue
Block a user