Sei sulla pagina 1di 5

Microsoft Windows [Versione 6.1.

7601]
Copyright (c) 2009 Microsoft Corporation. Tutti i diritti riservati.
C:\Windows\system32>mysql -h localhost -p
Enter password: **********
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: Y
ES)
C:\Windows\system32>mysql -h localhost -u root -p
Enter password: **********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
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> create database Biblioteca;
Query OK, 1 row affected (0.03 sec)
mysql> use database Biblioteca;
ERROR 1049 (42000): Unknown database 'database'
mysql> use Biblioteca;
Database changed
mysql> create table Autori
-> (idAutore int auto_increment primary key, nome varchar(20) not null, cogn
ome varchar(20) not null, eta int unsigned not null);
Query OK, 0 rows affected (0.18 sec)
mysql> create table Generi
-> (codice int auto_increment primary key, nome varchar(20) not null);
Query OK, 0 rows affected (0.20 sec)
mysql> create table Libri
-> (ISBN int(13) primary key, titolo varchar(20) not null, data_pubblicazion
e date not null, genere int references Generi(codice) not null, autore int refer
ences Autori(idAutore) not null);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'not n
ull, autore int references Autori(idAutore) not null)' at line 2
mysql> create table Libri
-> (ISBN int(13) primary key, titolo varchar(20) not null, data_pubblicazion
e date not null, genere int not null references Generi(codice), autore int not n
ull references Autori(idAutore));
Query OK, 0 rows affected (0.23 sec)
mysql> show tables;
+----------------------+
| Tables_in_biblioteca |
+----------------------+
| autori
|
| generi
|
| libri
|
+----------------------+
3 rows in set (0.00 sec)

mysql> desc libri;


+--------------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+-------+
| ISBN
| int(13)
| NO | PRI | NULL
|
|
| titolo
| varchar(20) | NO |
| NULL
|
|
| data_pubblicazione | date
| NO |
| NULL
|
|
| genere
| int(11)
| NO |
| NULL
|
|
| autore
| int(11)
| NO |
| NULL
|
|
+--------------------+-------------+------+-----+---------+-------+
5 rows in set (0.11 sec)
mysql> desc autori;
+----------+------------------+------+-----+---------+----------------+
| Field
| Type
| Null | Key | Default | Extra
|
+----------+------------------+------+-----+---------+----------------+
| idAutore | int(11)
| NO | PRI | NULL
| auto_increment |
| nome
| varchar(20)
| NO |
| NULL
|
|
| cognome | varchar(20)
| NO |
| NULL
|
|
| eta
| int(10) unsigned | NO |
| NULL
|
|
+----------+------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
mysql> desc generi;
+--------+-------------+------+-----+---------+----------------+
| Field | Type
| Null | Key | Default | Extra
|
+--------+-------------+------+-----+---------+----------------+
| codice | int(11)
| NO | PRI | NULL
| auto_increment |
| nome | varchar(20) | NO |
| NULL
|
|
+--------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> insert into autori
-> (nome, cognome, eta) values (cosimo, prete, 20),(rosita, galiandro, 21),(
biagio, colturi, 20), (deborah, lisi, 35), (francesco, monte, 24);
ERROR 1054 (42S22): Unknown column 'cosimo' in 'field list'
mysql> (nome, cognome, eta) values ('cosimo', 'prete', 20),('rosita', 'galiandro
', 21),('biagio', 'colturi', 20), ('deborah', 'lisi', 35), ('francesco', 'monte'
, 24);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'nome,
cognome, eta) values ('cosimo', 'prete', 20),('rosita', 'galiandro', 21),(' at
line 1
mysql> insert into autori
-> (nome, cognome, eta) values ('cosimo', 'prete', 20),('rosita', 'galiandro
', 21),('biagio', 'colturi', 20), ('deborah', 'lisi', 35), ('francesco', 'monte'
, 24);
Query OK, 5 rows affected (0.10 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> inser into autori(nome, cognome, eta) values ('giuseppe','rossi',-1);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'inser
into autori(nome, cognome, eta) values ('giuseppe','rossi',-1)' at line 1
mysql> insert into autori(nome, cognome, eta) values ('giuseppe','rossi',-1);
ERROR 1264 (22003): Out of range value for column 'eta' at row 1
mysql> select * from autori;
+----------+-----------+-----------+-----+
| idAutore | nome
| cognome | eta |

+----------+-----------+-----------+-----+
|
1 | cosimo
| prete
| 20 |
|
2 | rosita
| galiandro | 21 |
|
3 | biagio
| colturi | 20 |
|
4 | deborah | lisi
| 35 |
|
5 | francesco | monte
| 24 |
+----------+-----------+-----------+-----+
5 rows in set (0.00 sec)
mysql> insert into generi(nome) value ('avventura'),('comico'),('romantico'),('h
orror'),('fantascienza');
Query OK, 5 rows affected (0.09 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from generi;
+--------+--------------+
| codice | nome
|
+--------+--------------+
|
1 | avventura
|
|
2 | comico
|
|
3 | romantico
|
|
4 | horror
|
|
5 | fantascienza |
+--------+--------------+
5 rows in set (0.00 sec)
mysql> insert into libri(ISBN,titolo, data_pubblicazione, genere, autore) values
(123456011,'cuore','1993-3-15',1,3),(24353453,'troy','1992-4-23',3,5),(24253654
,'analisi','1999-3-5',2,3),(43763743,'basiDiDati','2012-3-6',4,5),(345894,'discr
eta','2003-3-6',5,5);
Query OK, 5 rows affected (0.03 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select cognome,nome
-> from autori
-> order by cognome,nome;
+-----------+-----------+
| cognome | nome
|
+-----------+-----------+
| colturi | biagio
|
| galiandro | rosita
|
| lisi
| deborah |
| monte
| francesco |
| prete
| cosimo
|
+-----------+-----------+
5 rows in set (0.00 sec)
mysql> select nome,cognome
-> from autori
-> where eta>30;
+---------+---------+
| nome
| cognome |
+---------+---------+
| deborah | lisi
|
+---------+---------+
1 row in set (0.00 sec)
mysql> select cognome
-> from autori
-> where eta between 30 AND 40;

+---------+
| cognome |
+---------+
| lisi
|
+---------+
1 row in set (0.00 sec)
mysql> select cognome
-> from autori
-> where nome LIKE 'F%';
+---------+
| cognome |
+---------+
| monte |
+---------+
1 row in set (0.00 sec)
mysql> select count(*) as NumeroLibri
-> from libri
-> group by autore;
+-------------+
| NumeroLibri |
+-------------+
|
2 |
|
3 |
+-------------+
2 rows in set (0.00 sec)
mysql> select autore, count(*) as NumeroLibri
-> from libri
-> group by autore;
+--------+-------------+
| autore | NumeroLibri |
+--------+-------------+
|
3 |
2 |
|
5 |
3 |
+--------+-------------+
2 rows in set (0.00 sec)
mysql> select genere, count(*) as NumeroLibriGenere
-> from libri
-> group by genere;
+--------+-------------------+
| genere | NumeroLibriGenere |
+--------+-------------------+
|
1 |
1 |
|
2 |
1 |
|
3 |
1 |
|
4 |
1 |
|
5 |
1 |
+--------+-------------------+
5 rows in set (0.00 sec)
mysql> select * from libri;
+-----------+------------+--------------------+--------+--------+
| ISBN
| titolo
| data_pubblicazione | genere | autore |
+-----------+------------+--------------------+--------+--------+
|
345894 | discreta | 2003-03-06
|
5 |
5 |
| 24253654 | analisi
| 1999-03-05
|
2 |
3 |
| 24353453 | troy
| 1992-04-23
|
3 |
5 |

| 43763743 | basiDiDati | 2012-03-06


|
4 |
5 |
| 123456011 | cuore
| 1993-03-15
|
1 |
3 |
+-----------+------------+--------------------+--------+--------+
5 rows in set (0.00 sec)
mysql> select avg(eta) as eta_media from autori;
+-----------+
| eta_media |
+-----------+
| 24.0000 |
+-----------+
1 row in set (0.00 sec)
mysql> select genere from libri
-> group by genere
-> having count(*) >2;
Empty set (0.00 sec)
mysql> select genere, count(*) as NumeroLibriGenere
-> from libri
-> group by genere
-> having NumeroLibriGenere>2;
Empty set (0.00 sec)
mysql> select autore from libri
-> group by autore
-> having count(*)=3;
+--------+
| autore |
+--------+
|
5 |
+--------+
1 row in set (0.00 sec)
mysql>