0% found this document useful (0 votes)
11 views8 pages

Test 2 - Teachers

The document is a university test on MySQL fundamentals, consisting of various parts including fill-in-the-blanks, matching keywords to descriptions, true/false questions, and practical tasks. It covers essential MySQL concepts such as table creation, data manipulation, constraints, and advanced topics like triggers and the CASE statement. The test also includes coding challenges that require writing SQL queries to demonstrate understanding of the material.

Uploaded by

MAGOSMAS
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)
11 views8 pages

Test 2 - Teachers

The document is a university test on MySQL fundamentals, consisting of various parts including fill-in-the-blanks, matching keywords to descriptions, true/false questions, and practical tasks. It covers essential MySQL concepts such as table creation, data manipulation, constraints, and advanced topics like triggers and the CASE statement. The test also includes coding challenges that require writing SQL queries to demonstrate understanding of the material.

Uploaded by

MAGOSMAS
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/ 8

University Computer Science Test: MySQL

Fundamentals
Name: ___________________________
Student ID: _____________________
Date: ___________________________

Part I: Fill-in-the-Blanks (1 point each)

1. To create a new table in MySQL, you use the _________ keyword.

2. The keyword used to remove an entire table from a database is _________.

3. To add data into a table, the _________ keyword is used.

4. To view all columns in a table named employees, the correct query begins with
_________.

5. The keyword used to change the structure of an existing table is _________.

Part II: Match the Columns (1 point each)


Match the keyword to its correct description:

Keyword Description

A. PRIMARY KEY 1. Limits the number of rows in a query.

B. LIMIT 2. Ensures unique identification of rows.

C. OFFSET 3. Specifies where a result set starts.

D. TRUNCATE 4. Removes all rows but retains


structure.

Write your answers:


A → ____
B → ____
C → ____
D → ____

Part III: True/False (1 point each)


1. The DISTINCT keyword eliminates duplicate rows in a query.
True / False

2. The WHERE clause can filter rows based on specific conditions.


True / False

3. The ALTER keyword can be used to update data in a table.


True / False

4. TRUNCATE is faster than DELETE for removing all rows in a table.


True / False

5. The CASE statement is used to modify table structures.


True / False

Part IV: Explain Concepts (2 points each)


1. What is the difference between the DROP and TRUNCATE commands?

2. How does the GROUP BY clause differ from ORDER BY?


3. Explain what the CHECK constraint does in a table definition.

4. Why is the UNIQUE constraint important in table design?

5. How is the FOREIGN KEY constraint used in MySQL?

Part V: Practical Tasks (3 points each)

1. Write a query to create a table named students with columns id (integer, primary
key), name (varchar), and birthdate (date).

2. Write a query to retrieve all rows from the students table where birthdate is after
2004-01-01.

3. Write a query to update the birthdate of the student with id = 1 to '2005-05-05'.

4. Write a query to count the total number of students in the students table.
5. Write a query to sort the students table by name in descending order.

Part VI: Advanced Topics (4 points each)


1. Explain the use of triggers in MySQL. Provide a real-world example.

2. Write a query to create a trigger that logs an entry in the log_table whenever a row in
the students table is deleted.

3. Write a query using the CASE statement to categorize employees earning above 50000
as High Income and others as Low Income.

4. Describe the purpose of the DESCRIBE statement and when it is useful.

5. What does the BETWEEN keyword achieve in a query, and why might you use it?

Part VII: Coding Challenges (5 points each)


1. Given this query:

SELECT AVG(salary) FROM employees;


What does the AVG function do?

2) Given this table creation statement:

CREATE TABLE projects (


project_id INT PRIMARY KEY,
project_name VARCHAR(255),
start_date DATE,
end_date DATE,
CONSTRAINT chk_dates CHECK (end_date > start_date)

1. What is the purpose of the CHECK constraint?

2. Write a query to add a column email to the students table.

3. Write a query to find the highest salary from the employees table.

4. Write a query to create a new table departments with columns dept_id (integer,
primary key) and dept_name (unique, varchar).

Solutions
Part I: Fill-in-the-Blanks
1. CREATE
2. DROP
3. INSERT
4. SELECT * FROM employees
5. ALTER
Part II: Match the Columns
A→2
B→1
C→3
D→4

Part III: True/False


1. True
2. True
3. False
4. True
5. False

Part IV: Explain Concepts


1. DROP deletes the entire table and its structure; TRUNCATE removes all rows but keeps
the structure.
2. GROUP BY groups rows for aggregation; ORDER BY sorts rows in a specified order.
3. CHECK enforces a condition on a column.
4. UNIQUE prevents duplicate values in a column.
5. FOREIGN KEY links tables by referencing another table’s primary key.

Part V: Practical Tasks

1) CREATE TABLE students (


id INT PRIMARY KEY,
name VARCHAR(255),
birthdate DATE

2) SELECT * FROM students WHERE birthdate > '2004-01-01';

3) UPDATE students SET birthdate = '2005-05-05' WHERE id = 1;

4) SELECT COUNT(*) FROM students;

5) SELECT * FROM students ORDER BY name DESC;

Part VI: Advanced Topics


1. Triggers automate actions based on table events, e.g., logging deletions.
CREATE TRIGGER log_delete AFTER DELETE ON students
FOR EACH ROW
INSERT INTO log_table (action, log_time)

2. VALUES ('Deleted student', NOW());

SELECT name, CASE


WHEN salary > 50000 THEN 'High Income'
ELSE 'Low Income'
END AS income_category
FROM employees;

3. DESCRIBE shows table structure, including columns and data types.

4. BETWEEN specifies a range, e.g., BETWEEN 100 AND 200 finds values in this range.

Part VII: Coding Challenges


1. AVG calculates the average value of a column.

2. CHECK ensures end_date is always after start_date.

3. ALTER TABLE students ADD COLUMN email VARCHAR(255);

4. SELECT MAX(salary) FROM employees;

5. CREATE TABLE departments (


dept_id INT PRIMARY KEY,
dept_name VARCHAR(255) UNIQUE

CREATE TABLE departments (

dept_id INT PRIMARY KEY,

dept_name VARCHAR(255) UNIQUE

);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy