Lab 1
Lab 1
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.
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;
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)
);
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.
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:
_______________________________________________________________________
_____