Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Exemple LMD

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 13
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> drop database lmd;
ERROR 1008 (HY000): Can't drop database 'lmd'; database doesn't exist
mysql> drop database if exists lmd;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> create database lmd;


Query OK, 1 row affected (0.00 sec)

mysql> select database();


+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)

mysql> use lmd;


Database changed
mysql> create table etudiant(
-> idEtd int primary key auto_increment,
-> nom varchar(255) not null,
-> prenom varchar(255) default 'mohammed'
-> ,
-> age int check(age > 18))engine=innodb;
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;


+---------------+
| Tables_in_lmd |
+---------------+
| etudiant |
+---------------+
1 row in set (0.00 sec)

mysql> desc etudiant;


+--------+--------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+----------+----------------+
| idEtd | int | NO | PRI | NULL | auto_increment |
| nom | varchar(255) | NO | | NULL | |
| prenom | varchar(255) | YES | | mohammed | |
| age | int | YES | | NULL | |
+--------+--------------+------+-----+----------+----------------+
4 rows in set (0.00 sec)
mysql> insert into etudiant set idetd=1,nom='frst1',prenom='scnd1',age=20;
Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 1 | frst1 | scnd1 | 20 |
+-------+-------+--------+------+
1 row in set (0.00 sec)

mysql> insert into etudiant set idetd=1,nom='frst1',prenom='scnd1',age=10;


ERROR 3819 (HY000): Check constraint 'etudiant_chk_1' is violated.
mysql> insert into etudiant set idetd=1,nom='frst2',prenom='scnd2',age=24;
ERROR 1062 (23000): Duplicate entry '1' for key 'etudiant.PRIMARY'
mysql> insert into etudiant set idetd=2,nom='frst2',prenom='scnd2',age=24;
Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
+-------+-------+--------+------+
2 rows in set (0.00 sec)

mysql> insert into etudiant set nom='frst3',prenom='scnd3',age=22;


Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
+-------+-------+--------+------+
3 rows in set (0.00 sec)

mysql> desc etudiant;


+--------+--------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+----------+----------------+
| idEtd | int | NO | PRI | NULL | auto_increment |
| nom | varchar(255) | NO | | NULL | |
| prenom | varchar(255) | YES | | mohammed | |
| age | int | YES | | NULL | |
+--------+--------------+------+-----+----------+----------------+
4 rows in set (0.00 sec)

mysql> insert into etudiant set nom='frst4',prenom='scnd4';


Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
+-------+-------+--------+------+
4 rows in set (0.00 sec)

mysql> insert into etudiant set nom='frst5';


Query OK, 1 row affected (0.00 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
+-------+-------+----------+------+
5 rows in set (0.00 sec)

mysql> insert into etudiant set prenom='frst4',nom='scnd4';


Query OK, 1 row affected (0.00 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
+-------+-------+----------+------+
6 rows in set (0.00 sec)

mysql> insert into etudiant(idetd,nom,prenom,age) values(8,'frst6','scnd5',23);


Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
+-------+-------+----------+------+
7 rows in set (0.00 sec)

mysql> insert into etudiant values(8,'frst6','scnd5',23);


ERROR 1062 (23000): Duplicate entry '8' for key 'etudiant.PRIMARY'
mysql> insert into etudiant values('frst6','scnd5',23);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into etudiant(nom,prenom,age) values('frst6','scnd5',23);
Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
+-------+-------+----------+------+
8 rows in set (0.00 sec)

mysql> insert into etudiant values(0,'frst6','scnd5',23);


Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
+-------+-------+----------+------+
9 rows in set (0.00 sec)

mysql> insert into etudiant values


-> (0,'aa','aa',67),
-> (0,'qq','qq',99);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
+-------+-------+----------+------+
11 rows in set (0.00 sec)
mysql> desc etudiant;
+--------+--------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+----------+----------------+
| idEtd | int | NO | PRI | NULL | auto_increment |
| nom | varchar(255) | NO | | NULL | |
| prenom | varchar(255) | YES | | mohammed | |
| age | int | YES | | NULL | |
+--------+--------------+------+-----+----------+----------------+
4 rows in set (0.00 sec)

mysql> insert into etudiant values('frst6','scnd5',23);


ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into etudiant(nom,prenom,age) values('frst6','scnd5',23);
Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | NULL |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | frst6 | scnd5 | 23 |
+-------+-------+----------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set age=25 where nom='frst4';


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from etudiant;


+-------+-------+----------+------+
| idEtd | nom | prenom | age |
+-------+-------+----------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | 25 |
| 5 | frst5 | mohammed | NULL |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | frst6 | scnd5 | 23 |
+-------+-------+----------+------+
12 rows in set (0.00 sec)
mysql> update etudiant set nom='uuu',prenom='iii',age=99 where idetd=5;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 1 | frst1 | scnd1 | 20 |
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | 25 |
| 5 | uuu | iii | 99 |
| 6 | scnd4 | frst4 | NULL |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | frst6 | scnd5 | 23 |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set idetd=7 where idetd=1;


Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 2 | frst2 | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | frst4 | scnd4 | 25 |
| 5 | uuu | iii | 99 |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | 20 |
| 8 | frst6 | scnd5 | 23 |
| 9 | frst6 | scnd5 | 23 |
| 10 | frst6 | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | frst6 | scnd5 | 23 |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set nom='ESTG' where age>=23 and age<=25;


Query OK, 6 rows affected (0.01 sec)
Rows matched: 6 Changed: 6 Warnings: 0

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 2 | ESTG | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | ESTG | scnd4 | 25 |
| 5 | uuu | iii | 99 |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | 20 |
| 8 | ESTG | scnd5 | 23 |
| 9 | ESTG | scnd5 | 23 |
| 10 | ESTG | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | ESTG | scnd5 | 23 |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set age=65 where nom='ETSG';


Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 2 | ESTG | scnd2 | 24 |
| 3 | frst3 | scnd3 | 22 |
| 4 | ESTG | scnd4 | 25 |
| 5 | uuu | iii | 99 |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | 20 |
| 8 | ESTG | scnd5 | 23 |
| 9 | ESTG | scnd5 | 23 |
| 10 | ESTG | scnd5 | 23 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | ESTG | scnd5 | 23 |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set age=65 where nom='ESTG';


Query OK, 6 rows affected (0.01 sec)
Rows matched: 6 Changed: 6 Warnings: 0

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 2 | ESTG | scnd2 | 65 |
| 3 | frst3 | scnd3 | 22 |
| 4 | ESTG | scnd4 | 65 |
| 5 | uuu | iii | 99 |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | 20 |
| 8 | ESTG | scnd5 | 65 |
| 9 | ESTG | scnd5 | 65 |
| 10 | ESTG | scnd5 | 65 |
| 11 | aa | aa | 67 |
| 12 | qq | qq | 99 |
| 13 | ESTG | scnd5 | 65 |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> update etudiant set age=null;


Query OK, 11 rows affected (0.01 sec)
Rows matched: 12 Changed: 11 Warnings: 0
mysql> select * from etudiant;
+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 2 | ESTG | scnd2 | NULL |
| 3 | frst3 | scnd3 | NULL |
| 4 | ESTG | scnd4 | NULL |
| 5 | uuu | iii | NULL |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | NULL |
| 8 | ESTG | scnd5 | NULL |
| 9 | ESTG | scnd5 | NULL |
| 10 | ESTG | scnd5 | NULL |
| 11 | aa | aa | NULL |
| 12 | qq | qq | NULL |
| 13 | ESTG | scnd5 | NULL |
+-------+-------+--------+------+
12 rows in set (0.00 sec)

mysql> delete from etudiant where idetd=2;


Query OK, 1 row affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 3 | frst3 | scnd3 | NULL |
| 4 | ESTG | scnd4 | NULL |
| 5 | uuu | iii | NULL |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | NULL |
| 8 | ESTG | scnd5 | NULL |
| 9 | ESTG | scnd5 | NULL |
| 10 | ESTG | scnd5 | NULL |
| 11 | aa | aa | NULL |
| 12 | qq | qq | NULL |
| 13 | ESTG | scnd5 | NULL |
+-------+-------+--------+------+
11 rows in set (0.00 sec)

mysql> delete from etudiant where nom='ESTG';


Query OK, 5 rows affected (0.01 sec)

mysql> select * from etudiant;


+-------+-------+--------+------+
| idEtd | nom | prenom | age |
+-------+-------+--------+------+
| 3 | frst3 | scnd3 | NULL |
| 5 | uuu | iii | NULL |
| 6 | scnd4 | frst4 | NULL |
| 7 | frst1 | scnd1 | NULL |
| 11 | aa | aa | NULL |
| 12 | qq | qq | NULL |
+-------+-------+--------+------+
6 rows in set (0.00 sec)

mysql> delete from etudiant;


Query OK, 6 rows affected (0.01 sec)
mysql> select * from etudiant;
Empty set (0.00 sec)

mysql>

You might also like