Skip to content

Instantly share code, notes, and snippets.

@Devcodpanda
Created May 25, 2020 16:19

Revisions

  1. Devcodpanda created this gist May 25, 2020.
    63 changes: 63 additions & 0 deletions Introduction aux bases de données
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    ➜ ~ nano db.sql
    ➜ ~ mysql -u root -D wild_db_quest -p
    Enter password:
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    ...

    mysql> DESCRIBE wizard;
    +-------------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------+--------------+------+-----+---------+----------------+
    | id | int | NO | PRI | NULL | auto_increment |
    | firstname | varchar(100) | NO | | NULL | |
    | lastname | varchar(100) | NO | | NULL | |
    | birthday | date | NO | | NULL | |
    | birth_place | varchar(255) | YES | | NULL | |
    | biography | text | YES | | NULL | |
    +-------------+--------------+------+-----+---------+----------------+
    6 rows in set (0.00 sec)

    mysql> ALTER TABLE wizard ADD is_muggle BOOLEAN;
    Query OK, 0 rows affected (0.03 sec)
    Records: 0 Duplicates: 0 Warnings: 0

    mysql> CREATE TABLE school ( id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, capacity INT, country CHARVAR(255) NOT NULL);
    Query OK, 0 rows affected (0.02 sec)

    mysql> DESCRIBE school;
    +----------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +----------+--------------+------+-----+---------+----------------+
    | id | int | NO | PRI | NULL | auto_increment |
    | name | varchar(100) | NO | | NULL | |
    | capacity | int | YES | | NULL | |
    | country | varchar(255) | NO | | NULL | |
    +----------+--------------+------+-----+---------+----------------+
    4 rows in set (0.01 sec)

    mysql> DESCRIBE wizard
    -> ;
    +-------------+--------------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------------+--------------+------+-----+---------+----------------+
    | id | int | NO | PRI | NULL | auto_increment |
    | firstname | varchar(100) | NO | | NULL | |
    | lastname | varchar(100) | NO | | NULL | |
    | birthday | date | NO | | NULL | |
    | birth_place | varchar(255) | YES | | NULL | |
    | biography | text | YES | | NULL | |
    | is_muggle | tinyint(1) | YES | | NULL | |
    +-------------+--------------+------+-----+---------+----------------+
    7 rows in set (0.00 sec)

    mysql> SHOW TABLES;
    +-------------------------+
    | Tables_in_wild_db_quest |
    +-------------------------+
    | school |
    | wizard |
    +-------------------------+
    2 rows in set (0.00 sec)

    mysql>