You are on page 1of 6

Enter password: ********

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


Your MySQL connection id is 10
Server version: 5.5.62 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 DATABASE businessfield;


Query OK, 1 row affected (0.00 sec)

mysql> USE businessfield;


Database changed
mysql> CREATE TABLE regions(
-> region_id INT(11) auto_increment Not NULL,
-> region_name VARCHAR(30),
-> primary key(region_id)
-> );
Query OK, 0 rows affected (0.06 sec)

mysql> SHOW TABLES;


+-------------------------+
| Tables_in_businessfield |
+-------------------------+
| regions |
+-------------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE countries(


-> country_id INT(11) auto_increment Not NULL,
-> country_name VARCHAR(30),
-> region_id INT(11),
-> primary key(country_id),
-> foreign key(region_id)REFERENCES regions(region_id)
-> );
Query OK, 0 rows affected (0.07 sec)

mysql> CREATE TABLE locations(


-> location_id INT(11) auto_increment Not NULL,
-> location_name VARCHAR(30),
-> ;
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 3
mysql> CREATE TABLE locations(
-> location_id INT(11) auto_increment Not NULL,
-> street_address VARCHAR(30),
-> postal_code INT(11) auto_increment Not NULL,
-> city VARCHAR(30),
-> state_province VARCHAR(30),
-> country_id INT(11),
-> primary key(location_id),
-> foreign key(country_id)REFERENCES countries(country_id)
-> );
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be
defined as a key
mysql> CREATE TABLE locations(
-> location_id INT(11) auto_increment Not NULL,
-> location_name VARCHAR(30),
-> country_id INT(11),
-> primary key(location_id),
-> foreign key(country_id)REFERENCES countries(country_id)
-> );
Query OK, 0 rows affected (0.10 sec)

mysql> CREATE TABLE departments(


-> department_id INT(11) auto_increment Not NULL,
-> depertments_name VARCHAR(30),
-> location_id INT(11),
-> primary key(department_id),
-> foreign key(location_id)REFERENCES locations(location_id)
-> );
Query OK, 0 rows affected (0.20 sec)

mysql> CREATE TABLE jobs(


-> job_id INT(11) auto_increment Not NULL,
-> job_title VARCHAR(30),
-> min_salary INT(11),
-> max_salary INT(11),
-> primary key(job_id)
-> );
Query OK, 0 rows affected (0.06 sec)

mysql> CREATE TABLE employees(


-> employee_id INT(11) auto_increment Not NULL,
-> first_name VARCHAR(30),
-> last_name VARCHAR(30),
-> email VARCHAR(30),
-> phone_number INT(11),
-> hire_date INT(11),
-> salary INT(11),
-> manager_id INT(11),
-> job_id INT(11),
-> department_id INT(11),
-> primary key(employee_id),
-> foreign key(job_id)REFERENCES jobs(job_id),
-> foreign key(department_id)REFERENCES departments(department_id)
-> );
Query OK, 0 rows affected (0.16 sec)

mysql> CREATE TABLE dependents(


-> dependent_id INT(11) auto_increment Not NULL,
-> first_name VARCHAR(30),
-> last_name VARCHAR(30),
-> relationship VARCHAR(30),
-> employee_id INT(11),
-> primary key(dependent_id),
-> foreign key(employee_id)REFERENCES employees(employee_id)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> SHOW TABLES;
+-------------------------+
| Tables_in_businessfield |
+-------------------------+
| countries |
| departments |
| dependents |
| employees |
| jobs |
| locations |
| regions |
+-------------------------+
7 rows in set (0.00 sec)

mysql> DESC locations;


+---------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+----------------+
| location_id | int(11) | NO | PRI | NULL | auto_increment |
| location_name | varchar(30) | YES | | NULL | |
| country_id | int(11) | YES | MUL | NULL | |
+---------------+-------------+------+-----+---------+----------------+
3 rows in set (0.03 sec)

mysql> DESC employees;


+---------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+----------------+
| employee_id | int(11) | NO | PRI | NULL | auto_increment |
| first_name | varchar(30) | YES | | NULL | |
| last_name | varchar(30) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| phone_number | int(11) | YES | | NULL | |
| hire_date | int(11) | YES | | NULL | |
| salary | int(11) | YES | | NULL | |
| manager_id | int(11) | YES | | NULL | |
| job_id | int(11) | YES | MUL | NULL | |
| department_id | int(11) | YES | MUL | NULL | |
+---------------+-------------+------+-----+---------+----------------+
10 rows in set (0.01 sec)

mysql> DROP TABLE locations;


ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
mysql> ALTER TABLE locations;
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW TABLES;


+-------------------------+
| Tables_in_businessfield |
+-------------------------+
| countries |
| departments |
| dependents |
| employees |
| jobs |
| locations |
| regions |
+-------------------------+
7 rows in set (0.01 sec)

mysql> DESC locations;


+---------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+----------------+
| location_id | int(11) | NO | PRI | NULL | auto_increment |
| location_name | varchar(30) | YES | | NULL | |
| country_id | int(11) | YES | MUL | NULL | |
+---------------+-------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)

mysql> DESC regions;


+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| region_id | int(11) | NO | PRI | NULL | auto_increment |
| region_name | varchar(30) | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
2 rows in set (0.02 sec)

mysql> INSERT INTO regions


-> (region_name)
-> values
-> ('Europe'),
-> ('America'),
-> ('Asia'),
-> ('Ethiopia');
Query OK, 4 rows affected (0.07 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT*from regions;


+-----------+-------------+
| region_id | region_name |
+-----------+-------------+
| 1 | Europe |
| 2 | America |
| 3 | Asia |
| 4 | Ethiopia |
+-----------+-------------+
4 rows in set (0.00 sec)

mysql> INSERT INTO countries


-> (country_id,region_id)
-> values
-> ('Argentina',2),
-> ('Australia',3),
-> ('Belgium',1),
-> ('Brazil',2);
ERROR 1366 (HY000): Incorrect integer value: 'Argentina' for column 'country_id' at row 1
mysql>
mysql> INSERT INTO countries
-> (country_name,region_id)
-> ('Argentina',2),
-> ('Australia',3),
-> ('Belgium',1),
-> ('Brazil',2);
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 ''Argentina',2),
('Australia',3),
('Belgium',1),
('Brazil',2)' at line 3
mysql> INSERT INTO countries
-> (country_name,region_id)
-> values
-> ('Argentina',2),
-> ('Australia',3),
-> ('Belgium',1),
-> ('Brazil',2);
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT*from countries;


+------------+--------------+-----------+
| country_id | country_name | region_id |
+------------+--------------+-----------+
| 1 | Argentina | 2|
| 2 | Australia | 3|
| 3 | Belgium | 1|
| 4 | Brazil | 2|
+------------+--------------+-----------+
4 rows in set (0.00 sec)

mysql> SELECT country_name from countries;


+--------------+
| country_name |
+--------------+
| Argentina |
| Australia |
| Belgium |
| Brazil |
+--------------+
4 rows in set (0.00 sec)

mysql> SELECT region_id from countries;


+-----------+
| region_id |
+-----------+
| 1|
| 2|
| 2|
| 3|
+-----------+
4 rows in set (0.01 sec)

mysql> SELECT DISTINCT region_id from countries;


+-----------+
| region_id |
+-----------+
| 1|
| 2|
| 3|
+-----------+
3 rows in set (0.02 sec)

mysql> INSERT INTO jobs


-> (job_title,min_salary,max_salary)
-> values
-> ('public accountant',4200,9000),
-> ('Accounting manager',8200,1600),
-> ('Admin assistant',3000,6000),
-> ('president',20000,40000),
-> ('Admin vice president',15000,3000);
Query OK, 5 rows affected (0.04 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> SELECT*from jobs;


+--------+----------------------+------------+------------+
| job_id | job_title | min_salary | max_salary |
+--------+----------------------+------------+------------+
| 1 | public accountant | 4200 | 9000 |
| 2 | Accounting manager | 8200 | 1600 |
| 3 | Admin assistant | 3000 | 6000 |
| 4 | president | 20000 | 40000 |
| 5 | Admin vice president | 15000 | 3000 |
+--------+----------------------+------------+------------+
5 rows in set (0.00 sec)

mysql> SELECT job_id,job_title,min_salary*12 from jobs;


+--------+----------------------+---------------+
| job_id | job_title | min_salary*12 |
+--------+----------------------+---------------+
| 1 | public accountant | 50400 |
| 2 | Accounting manager | 98400 |
| 3 | Admin assistant | 36000 |
| 4 | president | 240000 |
| 5 | Admin vice president | 180000 |
+--------+----------------------+---------------+
5 rows in set (0.03 sec)

mysql> SELECT job_id,job_title,min_salary*12 as annual_min_salary from jobs;


+--------+----------------------+-------------------+
| job_id | job_title | annual_min_salary |
+--------+----------------------+-------------------+
| 1 | public accountant | 50400 |
| 2 | Accounting manager | 98400 |
| 3 | Admin assistant | 36000 |
| 4 | president | 240000 |
| 5 | Admin vice president | 180000 |
+--------+----------------------+-------------------+
5 rows in set (0.01 sec)

mysql>

You might also like