Exercice BDR et SQL

Exercice d’apprentissage du SQL
Author

Ludovic Deneuville

Objective

In this practical work, you will:

  • create a database: start a PostgreSQL service
  • connect to this database: use a CloudBeaver service
  • insert data using an SQL script
  • write SQL queries to answer the questions

1 Setup

1.1 Start the services

    • username: user-
    • password: paste your password
TipWhat is what?
  • PostgreSQL: Database
  • CloudBeaver: Software used to communicate with a database

It is possible to connect directly to a database, but it is much easier to use a tool such as CloudBeaver.

1.2 Create a connection

Normally, if you start both services in the correct order, when launching CloudBeaver, the PostgreSQL database is detected and the connection is automatically created.

Has the connection been created?

  • If yes, it appears on the left in CloudBeaver (connection list)
  • If no, create the connection
NoteCreate a connection
    • it contains the information needed to connect to the database
    • Hostname: postgresql-<...>
    • Port: 5432
    • Database: defaultdb
    • Username: user-<username>
    • Password: <password>

Once the connection has been created, open it:

    • a small green dot appears next to it

Finally, open an SQL editor to write queries:

    • At the top in the blue banner, otherwise select this profile

1.3 Insert data

    • Orange icon with a scroll containing an arrow 📜

If you did not get any error message, check that the tables were created:

Tip
  • Scroll containing an arrow (ALT+X) ➡️ execute all queries in the editor
  • Orange arrow (CTRL+ENTER) ➡️ execute the current query (where the mouse cursor is located)

1.4 Alternatives

Other tools can be used to complete the exercise:

2 Data description

We have a list of players and tournaments. Players can participate in different tournaments.

A tournament is supervised by an arbiter. An arbiter is a player who has obtained an arbiter grade.

In a tournament, games are played at a certain time control (Classical, Rapid, Blitz).

classDiagram
  class arbitre_grade {
    id_arbitre_grade: INT(PK)
    nom: VARCHAR
  }

  class joueur {
    id_joueur: INT(PK)
    pseudo: VARCHAR
    nom: VARCHAR
    prenom: VARCHAR
    elo: INT
    mail: VARCHAR
    id_arbitre_grade: INT(FK -> arbitre_grade)
  }

  class cadence {
    id_cadence: INT(PK)
    nom: VARCHAR
  }

  class tournoi {
    id_tournoi: INT(PK)
    id_arbitre: INT(FK -> joueur)
    nom: VARCHAR
    debut: DATE
    fin: DATE
    nb_rondes: INT
    id_cadence: INT(FK -> cadence)
  }

  class participant {
    id_tournoi: INT(FK -> tournoi)
    id_joueur: INT(FK -> joueur)
  }

  arbitre_grade -- joueur
  cadence -- tournoi
  tournoi -- participant
  joueur -- participant

3 Questions

3.1 Discovering tables

    • 💡 see the UPPER method

3.2 Updating data

    • Why does this not work? What should be done to delete this player?
    • 💡 see IS NOT NULL

3.3 Joins

3.4 Aggregations

Link to the solution