1. The document describes creating tables in MySQL to store employee, department, and project data.
2. It provides the table structures and sample data to insert into each table.
3. It lists SQL queries to create the tables, insert data, and retrieve data from the tables.
1. The document describes creating tables in MySQL to store employee, department, and project data.
2. It provides the table structures and sample data to insert into each table.
3. It lists SQL queries to create the tables, insert data, and retrieve data from the tables.
1. The document describes creating tables in MySQL to store employee, department, and project data.
2. It provides the table structures and sample data to insert into each table.
3. It lists SQL queries to create the tables, insert data, and retrieve data from the tables.
1 Research Ho Chi Minh P1 E1 1000000 E4 2 Finance Hanoi P2 E3 1200000 E3 3 Maintenance Da Nang P3 E5 1530000 E4 4 Store Dai An P4 E1 850000 E3 5 Production Da Lat P5 E2 2500000 E2 P6 E4 280000 E4 P7 E5 1800000 E7 P8 E7 2250000 E9 P9 E6 700000 E6 P10 E8 120000 E1 Employee
Emp_No Emp_Name City Salary Dept_No Join_Date
E1 Dat Ho Chi Minh 10000 1 10/02/2015 E2 Phương Da Nang 18000 2 06/08/2015 E2 Phương Da Nang 18000 2 06/08/2015 E3 Tân Da Nang 7000 1 09/05/2016 E4 Việt Hanoi 8000 2 13/10/2016 E5 Dat Ho Chi Minh 7000 1 05/12/2016 E5 Dat Ho Chi Minh 7000 1 05/12/2016 E6 Duc Dai An 12000 5 07/02/2015 E7 Quân Da Lat 8500 3 20/08/2016 E8 Nhung Ho Chi Minh 15000 4 12/03/2015 E9 Khôi Hanoi 12000 5 03/12/2016 E10 Tân Da Nang 9000 4 15/08/2016 E11 Lợi Ho Chi Minh 8500 5 17/05/2015
3. Write SQL queries for following operations:
a. Show all the databases names present into your system. show databases; b. Create a new database name as “Lab1”. create database lab1. c. Use the database “Lab1”. use lab1; d. Show all the tables names present into your database “Lab1”. show tables; e. Create “Employee” table. create table employee (emp_no varchar (15), emp_name varchar (20), city varchar (20), salary int, dept_no integer (3), join_date date); f. Create “Department” table. create table department (dept_no int, dept_name varchar (15), dept_loc varchar (20)); g. Create “Project” table. create table project (project_no varchar (15), emp_no varchar (15), project_cost int, project_head varchar (15)); h. Describe the “Employee” table description. desc employee; i. Describe the “Department” table description. desc department; j. Describe the “Project” table description. desc project; k. Insert values into “Employee” table. insert into employee values (‘E1’, ‘Dat’, ‘Ho Chi Minh’, 10000, 1, ‘2015-02-10’); l. Insert values into “Department” table. insert into department (dept_no, dept_name, dept_loc) values (1, ‘Research’, ‘Ho Chi Minh’); m. Insert values into “Project” table. insert into project values (‘P1’, ‘E1’, 1000000, ‘E4’); n. Display all data of “Employee” table. select * from employee; o. Display all data of “Department” table. select * from Department; p. Display all data of “Project” table. select * from project; q. Find all employee names from “Employee” table who lives in Ho Chi Minh City. select emp_name from employee where city = ‘Ho Chi Minh’; r. Find all employee names from “Employee” table who lives in Hanoi. select emp_name from employee where city = ‘Hanoi; s. Display all employee names from “Employee” table without duplicate values. select distinct emp_name from employee; t. Create a new table name as “EmpSalary” from “Employee” table whose attributes are employee name, employee number and employee salary. create table empsalary as select emp_no, emp_name, emp_salary from employee; u. Insert data “E12” as employee number and “50000” as salary in “EmpSalary” table. See the previous insert into example… v. Show all data from “EmpSalary” table. select * from empsalary; w. Find all the employee’s name from “Employee” table whose salary is greater than 10000. select emp_name from employee where salary > 10000; x. Find the employee’s name from “Employee” table whose city is “Ho Chi Minh” and salary is less than equal to 10000. select emp_name from employee where city = ‘Ho Chi Minh’ and salary <= 10000; y. Find all the employee’s name from “Employee” table who lives in either “Hanoi” or “Dai An”. select emp_name from employee where city = ‘Ho Chi Minh’ or city = ‘Dai An’; z. Find all the employee’s name from “Employee” table who are not lives in “Ho Chi Minh”. Way 1: select emp_name from employee where city <> ‘Ho Chi Minh’; Way 2: select emp_name from employee where city != ‘Ho Chi Minh’; Way 3: select emp_name from employee where not city = ‘Ho Chi Minh’; aa. Display only all employee names and their salary from “Employee” table. select emp_name, salary from employee; bb. From “Employee” table, select all those employee’s name and city of who born 31st December 2015. select emp_name, city from employee where date_of_birth = ‘2015-12-31’;