0% found this document useful (0 votes)
57 views

Lab 1

4456 mysql

Uploaded by

Daigo Wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Lab 1

4456 mysql

Uploaded by

Daigo Wong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ITP4456 Database Applications Lab 1

HONG KONG INSTITUTE OF VOCATIONAL EDUCATION


Lab1 Relational DDL 60 mins

Module Intended Learning Outcome:


On completion of the module, students are expected to be able to:
 Perform database operations to implement data models and manipulate data in the
applications.

Lesson Intended Learning Outcome:


On completion of this lab, students are expected to be able to:
 Use a database client to interface with the DBMS and send queries.
 Handle database operations using SQL commands (like CREATE and INSERT).

TASK:

1. Following the instructions specific to your campus, create and connect to MySQL database
with the given username and password. Make sure that MySQL service is running.

2. Click ‘Query’ and click ‘New Tab to Current Server’ to create new Query tab. SQL
statements are commands that request the DBMS to performance some operations.

The SQL commands for this exercise are:


CREATE TABLE INSERT INTO
SELECT DROP TABLE

3. Use the following SQL command to create a new database. Click Ctrl + Enter to execute the
current query. You should see a green tick on the Output panel which indicate the query
has been executed successfully.
CREATE DATABASE hr;

4. Right click the left panel and click ‘Refresh All’. You should find the ‘hr’ database which is
just created.

5. Instead of checking the SCHEMAS panel, use the following query to list out all databases in
the DBMS. Make sure you have clicked the correct query you want to execute before
clicking Ctrl + Enter. Or you may simply remove any executed query.
SHOW DATABASES;

6. Use the USE command to select ‘hr’ as our default database.


USE hr;

©2021 VTC Page 1 of 3


ITP4456 Database Applications Lab 1

7. The following SQL is for creating the table EMPLOYEE. Enter the statement and before
going on to the next line, make sure you have the line typed exactly.
CREATE TABLE employee (
empid SMALLINT NOT NULL,
lname VARCHAR(30) NOT NULL,
fname VARCHAR(30) NOT NULL,
dob DATETIME,
salary DECIMAL,
PRIMARY KEY (empid)
);

8. Check if the table is created successfully.


SHOW TABLES;

9. Use the following command to review the table structure.


DESCRIBE employee;
or
DESC employee;

10. The table has been created but no data record yet. The following SELECT statement will
display all records in the table
SELECT * FROM employee;

11. Insert the following five records into the Employee table.
INSERT INTO employee VALUES (105, 'Lau', 'Andy', '1979-07-14', 32000);
INSERT INTO employee VALUES (247, 'Lai', 'Leon', '1978-02-02', 41000);
INSERT INTO employee VALUES (318, 'Cheung', 'Jacky', '1977-05-09', 38000);
INSERT INTO employee VALUES (404, 'Kwok', 'Aaron', '1979-03-01', 43000);
INSERT INTO employee VALUES (525, 'Mui', 'Anita', '1978-08-05', 36500);

12. Insert a record with your own name and birthday with any employee id and salary.

Ans: INSERT INTO employee VALUES (103, 'Wong', 'Daigo', '1997-04-25',


27000);________________________________________________________________
____________

13. Display all the records in the table.


SELECT * FROM employee;

14. Display all the employee names and their salaries?


SELECT lname, fname, salary FROM employee;

15. Display all the employee with last name ‘Lai’ ?


SELECT * FROM employee WHERE lname = 'Lai';

©2021 VTC Page 2 of 3


ITP4456 Database Applications Lab 1

16. Provide the command for inserting the record (empid = 111, lname = Chan, fname = Jacky,
dob = ’1954-08-03’ and salary = 85000) into employee table.

Ans:
_______________________________________________________________________
_____

17. Give the SQL to list the first name and birthday of employee with last name ‘Cheung’ ?

Ans:
_______________________________________________________________________
_____

18. Write a SQL to create a “student” table with the following 4 columns and primary key of
std_id.
std_id last_name first_name course
9 digits 20 letters 20 letters 8 digits

Ans:
_______________________________________________________________________
_____

19. Remove the student table.


DROP TABLE student;

©2021 VTC Page 3 of 3

You might also like