Sei sulla pagina 1di 14

Microsoft Windows [Version 6.3.

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.

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 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> use Carti;


Database changed
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;
Query OK, 0 rows affected (0.03 sec)

mysql> DESC book;


+--------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------------------+------+-----+---------+-------+
| isbn | char(13) | NO | PRI | NULL | |
| title | varchar(255) | NO | | NULL | |
| author | varchar(255) | NO | | NULL | |
| stock | smallint(5) unsigned | NO | | 0 | |
| price | float unsigned | YES | | NULL | |
+--------+----------------------+------+-----+---------+-------+
5 rows in set (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> DESC customer;


ERROR 1046 (3D000): No database selected
mysql> use Carti;
Database changed
mysql> DESC customer;
+-----------+-------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | PRI | NULL | |
| firstname | varchar(255) | NO | | NULL | |
| surname | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
| type | enum('basic','premium') | YES | | NULL | |
+-----------+-------------------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED PRIMARY KEY, customer_id


INT UNISGNED NOT NULL, start DATETIME NOTNULL, end DATETIME DEFAULT NULL, FOREI
GN KEY (book_id) REFERENCES book(id), -> FOREIGN KEY (customer_id) REFERENCES cu
stomer(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 'UNISG
NED NOT NULL, start DATETIME NOTNULL, end DATETIME DEFAULT NULL, FOREIGN KE' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOTNULL, end DATETIME DEFAULT NULL, FOREIGN
KEY (book_id) REFERENCES book(id), -> FOREIGN KEY (customer_id) REFERENCES custo
mer(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 'UNISG
NED NOT NULL, start DATETIME NOTNULL, end DATETIME DEFAULT NULL, FOREIGN KE' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN
KEY (book_id) REFERENCES book(id), -> FOREIGN KEY (customer_id) REFERENCES cust
omer(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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN K' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN
KEY (book_id) REFERENCES book(id), FOREIGN KEY (customer_id) REFERENCES custome
r(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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN K' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN
KEY (book_id) REFERENCES book(isbn), FOREIGN KEY (customer_id) REFERENCES custo
mer(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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN K' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL,FOREIGN
KEY (customer_id) 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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL,FOREIGN KE' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL) 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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL) ENGINE=In' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED PRIMARY KEY, customer_id
INT UNISGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL) ENGI
NE=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 'UNISG
NED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL) ENGINE=In' at
line 1
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNSIGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL, FOREIGN
KEY (book_id) REFERENCES book(isbn), FOREIGN KEY (customer_id) REFERENCES custo
mer(id)) ENGINE=InnoDb;
ERROR 1215 (HY000): Cannot add foreign key constraint
mysql> CREATE TABLE borrowed_books(book_id INT UNSIGNED NOT NULL, customer_id IN
T UNSIGNED NOT NULL, start DATETIME NOT NULL, end DATETIME DEFAULT NULL,FOREIGN
KEY (customer_id) REFERENCES customer(id)) 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 varhca(255) not null,
-> author varchar(255) not null,
-> stock smallint unsigned not null default 0,
-> price floar unsigned)
-> 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 'varhc
a(255) not null,
author varchar(255) not null,
stock smallint unsigned no' at line 3
mysql> CREATE TABLE book(
-> 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;
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 'CREAT
E TABLE BOOK(isbn CHAR(13) NOT NULL, title varchar(255) not null, author va' at
line 2
mysql> CREATE TABLE BOOK(isbn CHAR(13) NOT NULL, title varchar(255) not null, au
thor varchar(255) not null, stock small int unsigned not null default 0, price f
loat unsigned) 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 'small
int unsigned not null default 0, price float unsigned) engine=InnoDb' at line 1

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);

Query OK, 0 rows affected (0.05 sec)


Records: 0 Duplicates: 0 Warnings: 0

mysql> show create table borrowed_books \G;


*************************** 1. row ***************************
Table: borrowed_books
Create Table: CREATE TABLE `borrowed_books` (
`book_id` int(10) unsigned NOT NULL,
`customer_id` int(10) unsigned NOT NULL,
`start` datetime NOT NULL,
`end` datetime DEFAULT NULL,
KEY `customer_id` (`customer_id`),
KEY `book_id` (`book_id`),
CONSTRAINT `borrowed_books_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `cus
tomer` (`id`),
CONSTRAINT `borrowed_books_ibfk_2` FOREIGN KEY (`book_id`) REFERENCES `book` (
`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

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)

Microsoft Windows [Version 6.3.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.

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> use database carti;


ERROR 1049 (42000): Unknown database 'database'
mysql> use db carti;
ERROR 1049 (42000): Unknown database 'db'
mysql> use carti;
Database changed
mysql> create table sale_books(
-> sale_id INT UNSIGNED NOT NULL,
-> book_id int unsigned not null,
-> amount smallint unsigned not null default 1,
-> foreign key (sale_id) references sale(id),
-> foreign key(book_id) references book(id)) engine=InnoDb;
Query OK, 0 rows affected (0.01 sec)

mysql> alter table bok add unique key (isbn);


ERROR 1146 (42S02): Table 'carti.bok' doesn't exist
mysql> alter table book add unique key (isbn);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table customer add unique key (email);


Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

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 (id,firstname, surname, email, type) values(NULL,'ja


mes', 'kirk', 'enter@prise', 'basic');
ERROR 1048 (23000): Column 'id' cannot be null
mysql> insert into customer (id,firstname, surname, email, type) values('james',
'kirk', 'enter@prise', 'basic');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into customer (id,firstname, surname, email, type) values(,,'james
', 'kirk', 'enter@prise', 'basic');
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 ','jam
es', 'kirk', 'enter@prise', 'basic')' at line 1
mysql> insert into customer (id,firstname, surname, email, type) values(2,'james
', 'kirk', 'enter@prise', 'basic');
Query OK, 1 row affected (0.01 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> (2, '97897246211081', '1Q84', 'Haruki Murakami', 9, 9.75);


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 '2, '9
7897246211081', '1Q84', 'Haruki Murakami', 9, 9.75)' at line 1
mysql> (NULL, '97897246211081', '1Q84', 'Haruki Murakami', 9, 9.75);
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 'NULL,
'97897246211081', '1Q84', 'Haruki Murakami', 9, 9.75)' at line 1
mysql> INSERT INTO BOOK(ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(2, '9789724621
1081', '1Q84', 'Haruki Murakami', 9, 9.75);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(2, '9789724
6211081', '1Q84', 'Haruki Murakami', 9, 9.75);
ERROR 1406 (22001): Data too long for column 'isbn' at row 1
mysql> INSERT INTO BOOK(ID,ISBN, TITLE, AUTHOR, STOCK, PRICE) VALUES(2, '9789724
611081', '1Q84', 'Haruki Murakami', 9, 9.75);
Query OK, 1 row affected (0.00 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> alter table book where id=5;


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 'where
id=5' at line 1
mysql> alter table book delete row where id=5;
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 'delet
e row where id=5' at line 1
mysql> delete from book where id = 5;
Query OK, 1 row affected (0.01 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)

mysql> insert into borrowed_books(book_id, customer_id, start, end) values (4,1,


'2015-01-10', '2015-01-13'),
-> (4,2'2015-02-01','2015-02-10'),
-> (1,2,'2015-03-12',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 ''2015
-02-01','2015-02-10'),
(1,2,'2015-03-12',null)' at line 2
mysql> insert into borrowed_books(book_id, customer_id, start, end) values (4,1,
'2015-01-10', '2015-01-13');
Query OK, 1 row affected (0.02 sec)

mysql> insert into borrowed_books(book_id, customer_id, start, end) values (4,2,


'2015-02-01', '2015-02-10');
Query OK, 1 row affected (0.00 sec)

mysql> insert into borrowed_books(book_id, customer_id, start, end) values (1,2,


'2015-03-12', NULL);
Query OK, 1 row affected (0.00 sec)

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 VALUES INTO book values(null, '1234567891111','orasul fetelor','el


isabeth gilbert', 12, 40);
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 'VALUE
S INTO book values(null, '1234567891111','orasul fetelor','elisabeth gilber' at
line 1
mysql> INSERT VALUES INTO book values(1, '1234567891111','orasul fetelor','elisa
beth gilbert', 12, 40);
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 'VALUE
S INTO book values(1, '1234567891111','orasul fetelor','elisabeth gilbert',' at
line 1
mysql> INSERT VALUES INTO book values(6, '1234567891111','orasul fetelor','elisa
beth gilbert', 12, 40);
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 'VALUE
S INTO book values(6, '1234567891111','orasul fetelor','elisabeth gilbert',' at
line 1
mysql> INSERT INTO book values(6, '1234567891111','orasul fetelor','elisabeth g
ilbert', 12, 40);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO book values(7, '1234557891111','oamenii fericiti citesc si b
eau cafea','agnesmartin lugand', 14, 45);
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO book values(8, '1234527891111','after','anna todd', 5, 38.2)


;
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO book values(9, '9834527891111','morometii','marin pred', 7,


18.4);
Query OK, 1 row affected (0.00 sec)

mysql> desc customer;


+-----------+-------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------------------+------+-----+---------+-------+
| id | int(10) unsigned | NO | PRI | NULL | |
| firstname | varchar(255) | NO | | NULL | |
| surname | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | UNI | NULL | |
| type | enum('basic','premium') | YES | | NULL | |
+-----------+-------------------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> insert into customer values(9,'valentina', 'barna','barna@valentina.com',


'premium');
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer values(10,'bianca', 'doroftei','bianca@doroftei.com'


,'premium');
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer values(11,'melisa', 'lungo','melisa@lungo.com','basi


c');
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer values(12,'tudor, 'stefanescu','stefanesc@yahoo.com'


,'basic');
'>
'> insert into customer values(12,'tudor, 'stefanescu','stefanesc@yahoo.com'
,'basic');
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 'stefa
nescu','stefanesc@yahoo.com','basic');

insert into customer values(12,'tud' at line 1


mysql> insert into customer values(12,'tudor', 'stefanescu','stefanesc@yahoo.com
','basic');
Query OK, 1 row affected (0.00 sec)Microsoft Windows [Version 6.3.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>
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.

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> use carti;


Database changed
mysql> select firstname, surname, type from customer where id = 1;
+-----------+---------+---------+
| firstname | surname | type |
+-----------+---------+---------+
| han | solo | premium |
+-----------+---------+---------+
1 row in set (0.00 sec)

mysql> select firstname, surname, type from customer;


+-----------+------------+---------+
| firstname | surname | type |
+-----------+------------+---------+
| han | solo | premium |
| james | kirk | basic |
| valentina | barna | premium |
| bianca | doroftei | premium |
| melisa | lungo | basic |
| tudor | stefanescu | basic |
+-----------+------------+---------+
6 rows in set (0.00 sec)

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)

mysql> select * from customer\g;


+----+-----------+------------+---------------------+---------+
| id | firstname | surname | email | type |
+----+-----------+------------+---------------------+---------+
| 1 | han | solo | han@tatooine.com | premium |
| 2 | james | kirk | enter@prise | basic |
| 9 | valentina | barna | barna@valentina.com | premium |
| 10 | bianca | doroftei | bianca@doroftei.com | premium |
| 11 | melisa | lungo | melisa@lungo.com | basic |
| 12 | tudor | stefanescu | stefanesc@yahoo.com | basic |
+----+-----------+------------+---------------------+---------+
6 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> select concat(c.firstname, '', c.surname) as name, b.title, b.author, dat


e_format(bb.start, '%d-%m-%y') as start, date_format(bb.end('%d-%m-%y') as end f
rom borroed_books bb left join customer c on bb.customer_id = c.id left join boo
k b on b.id = vv.book_id where bb.start >= '2015-01-01';
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 'from
borroed_books bb left join customer c on bb.customer_id = c.id left join bo' at
line 1
mysql> select concat(c.firstname, '', c.surname) as name, b.title, b.author, dat
e_format(bb.start, '%d-%m-%y') as start, date_format(bb.end('%d-%m-%y') as end f
rom borrowed_books bb left join customer c on bb.customer_id = c.id left join bo
ok b on b.id = vv.book_id where bb.start >= '2015-01-01';
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 'from
borrowed_books bb left join customer c on bb.customer_id = c.id left join b' at
line 1
mysql> select concat(c.firstname, '', c.surname) as name, b.title, b.author, dat
e_format(bb.start, '%d-%m-%y') as start, date_format(bb.end,'%d-%m-%y') as end f
rom borrowed_books bb left join customer c on bb.customer_id = c.id left join bo
ok b on b.id = vv.book_id where bb.start >= '2015-01-01';
ERROR 1054 (42S22): Unknown column 'vv.book_id' in 'on clause'
mysql> select concat(c.firstname, '', c.surname) as name, b.title, b.author, dat
e_format(bb.start, '%d-%m-%y') as start, date_format(bb.end,'%d-%m-%y') as end f
rom borrowed_books bb left join customer c on bb.customer_id = c.id left join bo
ok b on b.id = bb.book_id where bb.start >= '2015-01-01';
+-----------+---------+---------------+----------+----------+
| name | title | author | start | end |
+-----------+---------+---------------+----------+----------+
| hansolo | Dracula | Bram Stoker | 10-01-15 | 13-01-15 |
| jameskirk | Dracula | Bram Stoker | 01-02-15 | 10-02-15 |
| jameskirk | 1984 | George Orwell | 12-03-15 | NULL |
+-----------+---------+---------------+----------+----------+
3 rows in set (0.00 sec)

mysql> select author, count(*) as amount, group_concat(title separator ',') as t


itles from book group by author order by amount desc, author;
+--------------------+--------+---------------------------------------+
| author | amount | titles |
+--------------------+--------+---------------------------------------+
| George Orwell | 2 | 1984,Animal Farm |
| agnesmartin lugand | 1 | oamenii fericiti citesc si beau cafea |
| anna todd | 1 | after |
| Bram Stoker | 1 | Dracula |
| elisabeth gilbert | 1 | orasul fetelor |
| Haruki Murakami | 1 | 1Q84 |
| Jodi Picoult | 1 | 19 minutes |
| marin pred | 1 | morometii |
+--------------------+--------+---------------------------------------+
8 rows in set (0.00 sec)

mysql> update book set price = 12.75 where id = 2;


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

mysql> update book set price = price*1.16;


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

mysql> alte table borrowed_books drop foreign key borrowed_books_ibfk_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 'alte
table borrowed_books drop foreign key borrowed_books_ibfk_1' at line 1
mysql> alter table borrowed_books drop foreign key borrowed_books_ibfk_1;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table borrowed_books drop foreign key borrowed_books_ibfk_2;


Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

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 author,title from book where stock > 10;


+--------------------+---------------------------------------+
| author | title |
+--------------------+---------------------------------------+
| George Orwell | 1984 |
| elisabeth gilbert | orasul fetelor |
| agnesmartin lugand | oamenii fericiti citesc si beau cafea |
+--------------------+---------------------------------------+
3 rows in set (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> select max(price) as MAXPRICE from book;


+-------------------+
| MAXPRICE |
+-------------------+
| 52.20000076293945 |
+-------------------+
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>

Potrebbero piacerti anche