Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\vale>C:\wamp64\bin\mysql\mysql5.7.23\bin
'C:\wamp64\bin\mysql\mysql5.7.23\bin' is not recognized as an internal or extern
al command,
operable program or batch file.
C:\Users\vale>cd C:\wamp64\bin\mysql\mysql5.7.23\bin
C:\wamp64\bin\mysql\mysql5.7.23\bin>mysql.exe -p -u root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE TABLE book(isbn CHAR(13) PRIMARY KEY, title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL, stock SMALLINT UNSIGNED NOT NULL DEFAULT 0, price
FLOAT UNSIGNED) ENGINE = innoDb;
ERROR 1046 (3D000): No database selected
mysql> CREATE TABLE book(isbn CHAR(13) PRIMARY KEY, title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL, stock SMALLINT UNSIGNED NOT NULL DEFAULT 0, price
FLOAT UNSIGNED) ENGINE = InnoDb;
ERROR 1046 (3D000): No database selected
mysql> create database Carti;
Query OK, 1 row affected (0.00 sec)
mysql> create table customer( id INT UNSIGNED NOT NULL, firstname VARCHAR(255) N
OT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENUM('
basic', 'premium') ENGINE = InnoDb;
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 'ENGIN
E = InnoDb' at line 1
mysql> create table customer( id INT UNSIGNED PRIMARY KEY, firstname VARCHAR(255
) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENU
M('basic', 'premium') ENGINE = InnoDb;
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 'ENGIN
E = InnoDb' at line 1
mysql> create table customer( id INT UNSIGNED PRIMARY KEY, firstname VARCHAR(255
) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENU
M('basic', 'premium') ENGINE = InnoDb;
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 'ENGIN
E = InnoDb' at line 1
mysql> create table customer( id INT UNSIGNED PRIMARY KEY, firstname VARCHAR(255
) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENU
M('basic', 'premium') ENGINE=InnoDb;
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 'ENGIN
E=InnoDb' at line 1
mysql> create table customer( id INT UNSIGNED PRIMARY KEY, firstname VARCHAR(255
) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENU
M('basic', 'premium');
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 '' at
line 1
mysql> create table customer( id INT UNSIGNED PRIMARY KEY, firstname VARCHAR(255
) NOT NULL, surname VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, type ENU
M('basic', 'premium')) ENGINE=InnoDb;
Query OK, 0 rows affected (0.02 sec)
mysql> ALTER TABLE book ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
FIRST;
ERROR 1068 (42000): Multiple primary key defined
mysql> alter table add id int unsigned not null auto_increment;
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 'add i
d int unsigned not null auto_increment' at line 1
mysql> alter table add id int unsigned not null auto_increment;
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 'add i
d int unsigned not null auto_increment' at line 1
mysql> alter table add id int unsigned not null auto_increment first;
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 'add i
d int unsigned not null auto_increment first' at line 1
mysql> ALTER TABLE BOOK
-> ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT
-> FIRST;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto colum
n and it must be defined as a key
mysql> DROP TABLE BOOK
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE BOOK(isbn CHAR(13) NOT NULL, title varchar(255) not null, au
thor varchar(255) not null, stock smallint unsigned not null default 0, price fl
oat unsigned) engine=InnoDb;
Query OK, 0 rows affected (0.03 sec)
mysql> alter table book add id int unsigned not null auto_increment primary key
first;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table borrowed_books add foreign key (bookd_id) references book(id)
;
ERROR 1072 (42000): Key column 'bookd_id' doesn't exist in table
mysql> alter table borrowed_books add foreign key (book_id) references book(id);
ERROR:
No query specified
mysql> CREATE TABLE sale(id int unsigned not null auto_increment primary key, cu
stomer_id int unsigned not null, date datetime not null, foreign key (customer_i
d) references customer(id) engine=InnoDb;
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 'engin
e=InnoDb' at line 1
mysql> CREATE TABLE sale(id int unsigned not null auto_increment primary key, cu
stomer_id int unsigned not null, date datetime not null, foreign key (customer_i
d) references customer(id)) engine=InnoDb;
Query OK, 0 rows affected (0.02 sec)
C:\Users\vale>C:\wamp64\bin\mysql\mysql5.7.23\bin
'C:\wamp64\bin\mysql\mysql5.7.23\bin' is not recognized as an internal or extern
al command,
operable program or batch file.
C:\Users\vale>cd C:\wamp64\bin\mysql\mysql5.7.23\bin
C:\wamp64\bin\mysql\mysql5.7.23\bin>mysql.exe -p -u root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> insert into customer (firstname, surname, email, type) values('han', 'sol
o', 'han@tatooine.com', 'premium');
ERROR 1364 (HY000): Field 'id' doesn't have a default value
mysql> insert into customer (id,firstname, surname, email, type) values(1,'han',
'solo', 'han@tatooine.com', 'premium');
Query OK, 1 row affected (0.00 sec)
mysql> insert into customer (firstname, surname, email, type) values('mr', 'spoc
k', 'enter@prise', 'basic');
ERROR 1364 (HY000): Field 'id' doesn't have a default value
mysql> insert into customer (id,firstname, surname, email, type) values(3,'mr',
'spock', 'enter@prise', 'basic');
ERROR 1062 (23000): Duplicate entry 'enter@prise' for key 'email'
mysql> desc book;
+--------+----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| isbn | char(13) | NO | UNI | NULL | |
| title | varchar(255) | NO | | NULL | |
| author | varchar(255) | NO | | NULL | |
| stock | smallint(5) unsigned | NO | | 0 | |
| price | float unsigned | YES | | NULL | |
+--------+----------------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
mysql> insert into book(id, isbn, title, author, stock, price) values
-> (1, '9780882339726', '1984', 'George Orwell', 12, 7.50);
Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(3, '9780736
692427', 'Animal Farm', 'George Orwell', 8, 3.50);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(4, '9780756
692427', 'Dracula', 'Bram Stoker', 30,10.15);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(5, '9780756
692457', 'Dracula', 'Bram Stoker', 30,10.15);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(5, '9780756
692457', '19 minutes', 'Jodi Picoult', 0,10);
Query OK, 1 row affected (0.00 sec)
mysql> insert into borrowed_books(book_id, customer_id, start, end) values (1,1,
'2014-12-12', '2014-12-28');
Query OK, 1 row affected (0.00 sec)
C:\Users\vale>C:\wamp64\bin\mysql\mysql5.7.23\bin
'C:\wamp64\bin\mysql\mysql5.7.23\bin' is not recognized as an internal or extern
al command,
operable program or batch file.
C:\Users\vale>cd C:\wamp64\bin\mysql\mysql5.7.23\bin
C:\wamp64\bin\mysql\mysql5.7.23\bin>
C:\wamp64\bin\mysql\mysql5.7.23\bin>
C:\wamp64\bin\mysql\mysql5.7.23\bin>mysql.exe -p -u root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select title, author, price from book where title like '1%';
+------------+-----------------+-------+
| title | author | price |
+------------+-----------------+-------+
| 1984 | George Orwell | 7.5 |
| 1Q84 | Haruki Murakami | 9.75 |
| 19 minutes | Jodi Picoult | 10 |
+------------+-----------------+-------+
3 rows in set (0.00 sec)
mysql> select title, author, price from book where title like '1%' and stock>0;
+-------+-----------------+-------+
| title | author | price |
+-------+-----------------+-------+
| 1984 | George Orwell | 7.5 |
| 1Q84 | Haruki Murakami | 9.75 |
+-------+-----------------+-------+
2 rows in set (0.00 sec)
ERROR:
No query specified
mysql> select count(*) from borrowed_books where customer_id = 1 and end is not
null;
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
mysql> select id, title, author, isbn from book order by title limit 4;
+----+------------+-----------------+---------------+
| id | title | author | isbn |
+----+------------+-----------------+---------------+
| 5 | 19 minutes | Jodi Picoult | 9780756692457 |
| 1 | 1984 | George Orwell | 9780882339726 |
| 2 | 1Q84 | Haruki Murakami | 9789724611081 |
| 8 | after | anna todd | 1234527891111 |
+----+------------+-----------------+---------------+
4 rows in set (0.00 sec)
mysql> alter table borrowed_books add foreign key (book_id) references book(id)
on delete cascade on update cascade, add foreign ley (customer_id) references cu
stomer(id) on delete cascade on update cascade;
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 'ley (
customer_id) references customer(id) on delete cascade on update cascade' at lin
e 1
mysql> alter table borrowed_books add foreign key (book_id) references book(id)
on delete cascade on update cascade, add foreign key (customer_id) references cu
stomer(id) on delete cascade on update cascade;
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> delete from book where id = 4;
Query OK, 1 row affected (0.01 sec)
mysql> select author and title from book where stock > 10;
+------------------+
| author and title |
+------------------+
| 0 |
| 0 |
| 0 |
+------------------+
3 rows in set, 3 warnings (0.00 sec)
mysql> select customer_id, book_id from borrowed_books where start > '2015-01-01
';
+-------------+---------+
| customer_id | book_id |
+-------------+---------+
| 2 | 1 |
+-------------+---------+
1 row in set (0.00 sec)
mysql>
mysql> mysql.exe -p -u root
-> ;
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 'mysql
.exe -p -u root' at line 1
mysql> select concat(c.firstname,'', c.surname) as name from borrowed books wher
e type='premium';
ERROR 1146 (42S02): Table 'carti.borrowed' doesn't exist
mysql> select concat(c.firstname,'', c.surname) as name from borrowed_books wher
e type='premium';
ERROR 1054 (42S22): Unknown column 'c.firstname' in 'field list'
mysql> select concat(firstname,'', surname) as name from borrowed_books where ty
pe='premium';
ERROR 1054 (42S22): Unknown column 'firstname' in 'field list'
mysql> select concat(c.firstname,'',c.surname) as name from customer left join c
ustomer c on borrowed_books.customer_id where type='premium';
ERROR 1052 (23000): Column 'type' in where clause is ambiguous
mysql>