Philipp G
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Cheatsheet Good links: https://devhints.io/mysql https://www.w3schools.com/mysql ## Browsing ```sql SHOW DATABASES; USE name; SHOW TABLES; SHOW GRANTS FOR customers; SELECT * FROM tablename; -- Zeight Tabelleninhalte an SELECT * FROM dbname.tablename ``` SHOW für Liste von verfügbaren Datenbanken/Tabellen, SELECT für Inhalte einer Tabelle ## Users and Privileges ![](https://i.imgur.com/l278j6d.png) Rechte entfernen mit REVOKE anstatt GRANT! ```sql CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; -- Localhost bedutet hier das 'user' sich nur von localhost aus mit dem DROP USER 'user'@'host'; ``` ## Create/Delete databases ```sql CREATE DATABASE DatabaseName; CREATE DATABASE DatabaseName CHARACTER SET utf8; USE DatabaseName; DROP DATABASE DatabaseName; ``` DATE INSERT INTO .. () VALUES (1412-12-12, ) ## Datatypes ```sql INT DOUBLE TIME -- Format 'hh:mm:ss' YEAR -- Format 'yyyy' DATE -- Format 'YYYY-MM-DD' DATETIME -- Format 'YYYY-MM-DD hh:mm:ss' CHAR VARCHAR(size) TEXT BLOB ``` CREATE TABLE users (id INT, name VARCHAR(20)); ## Tables field = Spaltenname ```sql CREATE TABLE table (field1 type1, field2 type2); CREATE TABLE table (field1 type1, field2 type2, PRIMARY KEY (field1)); CREATE TABLE table (field1 type1, field2 type2, PRIMARY KEY (field1,field2)); ``` Mit constraints ```sql CREATE TABLE table (field1 type1 constraint1, field2 type2 constraint2); ``` ```sql CREATE TABLE IF NOT EXISTS table; ``` ```sql INSERT INTO table1 (field1, field2) VALUES (value1, value2); ``` ```sql DROP TABLE table; DROP TABLE IF EXISTS table; DROP TABLE table1, table2, ... ``` ```sql UPDATE table1 SET field1=new_value1 WHERE condition; UPDATE table1, table2 SET field1=new_value1, field2=new_value2, ... WHERE table1.id1 = table2.id2 AND condition; DELETE FROM table1 WHERE condition = DELETE FROM table1, table2 WHERE table1.id1 = table2.id2 AND condition ``` ## Select ```sql SELECT * FROM table; SELECT * FROM table1, table2; SELECT field1, field2 FROM table1, table2; SELECT ... FROM ... WHERE condition SELECT ... FROM ... WHERE condition ORDER BY field1, field2; SELECT ... FROM ... WHERE condition ORDER BY field1, field2 DESC; SELECT ... FROM ... WHERE condition LIMIT 10; ``` Conditions: LIKE '%irgendetwas%' % matcht beliebigen text IN z.B 'London' ist IN ('Paris', 'London') =,!= < > <= => OR AND Verknüpfung von Conditions: (cond1) AND/OR (cond2) ... AND/OR (condN) ## JOIN ![](https://i.imgur.com/LMKejZn.png) ## Special keys ```sql CREATE TABLE table (..., PRIMARY KEY (field1)) CREATE TABLE table (..., PRIMARY KEY (field1, field2)) --Beispiel CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, PRIMARY KEY (ID) ); ``` ```sql CREATE TABLE Orders ( OrderID int NOT NULL, OrderNumber int NOT NULL, PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES Persons(PersonID) ); ``` Constraints: NOT NULL UNIQUE PRIMARY KEY = NOT NULL + UNIQUE FOREIGN KEY - ForeignKey der Kindstabelle muss in Elterntablle vorhanden sein - Eintrag in Elterntabelle kann nur gelöscht werden, wenn PrimaryKey nicht in Kindstabelle als ForeignKey vorkomt. ## ER Diagram (Entity-Relation) ![](https://i.imgur.com/wZEjpXW.png) # Lernziele ``` use CompanyDB; /* Geben Sie Anzahl Mitarbeiter aus, welche in der Abteilung 'Sales' arbeiten. */ select count(*) from employees; -- 107 /* Geben Sie alle Mitarbeiter mit Nach- und Vornamen, deren Vorname David ist. */ SELECT LAST_NAME, FIRST_NAME from employees where FIRST_NAME ='david'; /* Geben Sie alle Mitarbeiter mit Namen, Vornamen und Telefonnummer, deren Telefonnummer mit 079 beginnt, sortiert aufsteigend nach Nachnamen. */ select LAST_NAME,FIRST_NAME,PHONE_NUMBER from employees where PHONE_NUMBER like '%079%' order by LAST_NAME asc; /* Ermitteln Sie den Mitarbeiter (Frau oder Mann), welcher am längsten in der Firma angestellt ist. Geben Sie als Resultat die ID, Nachnamen und Vornamen aus. */ SELECT min(HIRE_DATE), EMPLOYEE_ID,LAST_NAME,FIRST_NAME,HIRE_DATE from employees; -- oder select EMPLOYEE_ID,LAST_NAME,FIRST_NAME, HIRE_DATE from employees order by HIRE_DATE asc; /* Geben Sie alle Mitarbeiter aus, welche in der Abteilung 'Finance' arbeiten. Als Resultat soll der Nachnamen und Vorname, absteigend sortiert nach Nachnamen ausgegeben werden. */ select e.LAST_NAME, e.FIRST_NAME, d.DEPARTMENT_NAME from employees e inner join departments d on e.DEPARTMENT_ID = d.DEPARTMENT_ID where d.DEPARTMENT_NAME = 'Finance' order by LAST_NAME desc ; /* Geben Sie alle Mitarbeiter aus, welche in der Abteilung 'IT', 'Marketing' und 'Human Resources' arbeiten. Als Resultat soll der Nachnamen, Vorname und Abteilung, aufsteigend sortiert nach Abteilung-ID ausgegeben werden. */ select e.LAST_NAME, e.FIRST_NAME, d.DEPARTMENT_NAME from employees e inner join departments d on e.DEPARTMENT_ID = d.DEPARTMENT_ID where d.DEPARTMENT_NAME IN ('IT', 'Marketing', 'Human Resources') order by d.DEPARTMENT_ID asc ; -- oder select e.LAST_NAME, e.FIRST_NAME, d.DEPARTMENT_NAME from employees e inner join departments d on e.DEPARTMENT_ID = d.DEPARTMENT_ID where d.DEPARTMENT_NAME = 'IT' or d.DEPARTMENT_NAME = 'Marketing' or d.DEPARTMENT_NAME = 'Human Resources' order by d.DEPARTMENT_ID asc; /* Fripp Adam ist ein Manager aus der Abteilung 'Shipping'. Für bevorstehende Lohngespräche mit seinen Mitarbeitern benötigt er eine Liste seiner Mitarbeiter (aus derselben Abteilung). Als Resultat soll der Nachnamen, Vorname, Gehalt und das Lohnband mit Min-/Max-Gehalt absteigend sortiert nach Gehalt ausgegeben werden. */ select LAST_NAME, FIRST_NAME, EMPLOYEE_ID from employees where FIRST_NAME='Adam' and LAST_NAME='Fripp'; select LAST_NAME, FIRST_NAME, SALARY, MIN_SALARY,MAX_SALARY from employees e inner join jobs j on e.JOB_ID = j.JOB_ID inner join departments d on e.DEPARTMENT_ID = d.DEPARTMENT_ID where DEPARTMENT_NAME='shipping' and e.MANAGER_ID = 121 order by e.SALARY desc ; ``` ## Verbindung zu Mysql 1. Ich kann den Datenbank Server starten und stoppen. 2. Ich kann überprüfen ob der Datenbank-Server gestartet ist. Systemeinstellung -> MySQL ## Einfaches Datenbankmanagment von Mysql 1. Ich kann eine Datenbank importieren 2. Ich kann eine Leere Datenbank erstellen und löschen 3. Ich kann einen Benutzer für den Zugriff auf die Datenbank erstellen 4. Ich kann Zugriffsrechte einem Benutzer zuweisen oder entfernen ## Datenbank mit einer Tabelle einrichten 1. Ich kann mit SQl-statments eine leere Datenbank erstellen und löschen 2. Ich kann mit SQL-statments eine leere Datenbank-Tabelle erstellen oder löschen 3. Ich kann mit SQL-statments Daten in eine leere Datenbank-Tabelle korrekt einfügen ## Mit SQL Daten abfragen ## Daten mit SQL mutieren ## Constraints

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully