0% found this document useful (0 votes)
5 views3 pages

Entity Modeling and SQL Exercises

The document outlines various exercises related to entity-relationship modeling and SQL queries. It includes tasks for identifying entity types, occurrences, and attributes, as well as creating conceptual ERDs based on given descriptions. Additionally, it provides SQL exercises for querying employee and customer data from a database using specific conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Entity Modeling and SQL Exercises

The document outlines various exercises related to entity-relationship modeling and SQL queries. It includes tasks for identifying entity types, occurrences, and attributes, as well as creating conceptual ERDs based on given descriptions. Additionally, it provides SQL exercises for querying employee and customer data from a database using specific conditions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week 2 Tutorial

Tutorial 02 Modelling Exercise 01

For each of the items on the list below, determine whether it is an entity type, an entity occurrence or an attribute
and fill in the table given underneath the list.

• If it is an entity type, give examples of possible occurrences for this entity and list potential attributes.
• If it is an entity occurrence, determine what the entity type is and list potential attributes.
• If it is an attribute, determine a possible entity type and give examples of possible occurrences.

1.1. ISBN
1.2. IPhone6
1.3. Customer
1.4. Linux

Entity Type Occurrence Possible Attributes

Tutorial 02 Modelling Exercise 02

For each of the conceptual Entity Relationship Diagrams (ERDs) below explain in detail the multiplicity (i.e.
participation and cardinality) by writing 4 statements to explain the 4 digits on both sides of the relationships.

Question 2.1.
is located in
Lab Computer
0..1 1..*

Question 2.2.
includes
Order Product
0..* 1..*

Question 2.3.
Is allocated to
Laptop Staff
1..3 0..1
Tutorial 02 Modelling Exercise 03

Create a simple conceptual ERD for each of the following descriptions. Make sure you include the entity names,
relationship names, reading directions and multiplicities (i.e. participation and cardinality).

3.1. Each company operates four departments, and each department belongs to one company.

3.2. Each department in part 3.1. employs one or more employees, and each employee works for one department.

3.3. Each of the employees in part 3.2. may or may not have one or more dependants, and each dependant is
associated with one employee.

3.4. Each employee in part 3.3. may or may not have an employment history.

3.5. Represent all the conceptual ERDs described in 3.1., 3.2., 3.3, and 3.4. as a single conceptual ERD.

Tutorial 02 SQL Exercise – Connect to your database (step 6 from week 1 tutorial)

Same as last week, run the SQL commands below to continue building your knowledge of SQL.

[Link] this in SQL window in phpMyadmin:


SELECT job FROM emp; note the output
Now run: SELECT DISTINCT job FROM emp; compare it with previous one.

[Link] this in SQL window in phpMyadmin:


SELECT ename, deptno
FROM emp
WHERE deptno = 30;

This query structure can be represented as:


SELECT column name(s)
FROM table name(s)
WHERE condition(s)
⎯ SELECT identifies the columns of data that will be retrieved, in the order in which they will
appear.
⎯ FROM specifies the tables from which the columns specified in SELECT are taken, together with
any other tables needed to make the links between the data fields complete.
⎯ WHERE first specifies the relations between the tables included in the FROM clause, and then
specifies any particular conditions that the selected data must meet. Relations and conditions may
be linked by Boolean AND, OR or NOT logic

[Link] this in SQL window in phpMyadmin:


SELECT *
FROM emp
WHERE job = 'SALESMAN';
Examine the output and describe in words what the query does.
[Link] this in SQL window in phpMyadmin:
SELECT ename, job
FROM emp
WHERE deptno = 20;
Examine the output and describe in words what the query does.

[Link] this in SQL window in phpMyadmin:


SELECT ename, deptno
FROM emp
WHERE job = ‘MANAGER’
ORDER BY ename;
Examine the output and describe in words what the query does
[Link] this in SQL window in phpMyadmin:

SELECT empno, ename, hiredate, deptno


FROM emp
WHERE hiredate = ‘09-JUN-81’
OR deptno = 20;
Examine the output and describe in words what the query does

[Link] this in SQL window in phpMyadmin:


SELECT *
FROM emp
WHERE job = ‘SALESMAN’
AND sal >= 1500;
Examine the output and describe in words what the query does

Write SQL scripts to retrieve the following and test your script:

1. List the names of all employees in department 10.

2. The customer ids of all customers whose credit limit is between 10000 and 12000.

3. A list of all customer names, ordered alphabetically within each sales area.

4. Full details of the customer whose customer id is ‘GRE301’.

5. The customer id and credit limit of all customers ordered by credit limit, starting with the highest credit
value.

Common questions

Powered by AI

A single conceptual ERD for a company's organizational structure should include: a 'Company' entity with a one-to-many relationship with a 'Department' entity (company operates four departments, each of which belongs to one company). 'Department' has a one-to-many relationship with 'Employee' (department employs one or more employees), and 'Employee' has a one-to-many relationship with 'Dependant' (employee may or may not have dependants). Additionally, 'Employee' could be related back to itself for employment history, considered as an optional one-to-one relationship .

SQL enables targeted data retrieval by specifying conditions. For instance, selecting customers with credit limits between 10000 and 12000 is done via SELECT customer_id FROM customer WHERE credit_limit BETWEEN 10000 AND 12000. This capability allows businesses to segment customers based on financial metrics, optimizing credit management, targeting marketing efforts, and enhancing decision-making processes .

An SQL query without the DISTINCT keyword, like SELECT job FROM emp, retrieves all the 'job' entries from the table 'emp', including duplicates. In contrast, SELECT DISTINCT job FROM emp retrieves only unique job entries by removing duplicates. This differentiation helps in reducing redundancy and focusing on unique values in data retrieval .

Representing multiple relationships in a single conceptual ERD poses challenges like balancing complexity with clarity, ensuring accurate cardinality and participation, and comprehensively addressing inter-entity dependencies. Specifically, depicting a company's structure involves managing one-to-many department relations, employee dependencies, and optional vs. mandatory participation, which complicates normalization and can lead to redundant or missing data if not carefully designed .

In ERDs, participation indicates whether all or only some entity occurrences are involved in a relationship, and cardinality specifies the number of instances an entity can participate. In a relationship where a 'Company' operates 'Departments', each department belongs to one company (one-to-many), showing mandatory participation for departments but optional participation for companies. This affects database design by determining foreign key constraints and integrity rules, ensuring each department's record in a database links to exactly one company .

The WHERE clause in SQL queries evaluates conditions to filter records. It uses Boolean logic operators like AND, OR, and NOT to combine conditions for precise filtering. For example, SELECT * FROM emp WHERE job = 'SALESMAN' AND sal >= 1500 filters employees with job 'SALESMAN' having a salary greater than or equal to 1500, demonstrating the use of AND to meet both conditions. Similarly, OR is used to filter records that meet at least one stated condition .

Entity types define a category of objects with common properties. 'Customer' is an entity type with potential occurrences like 'John Doe' or 'Jane Doe' and attributes such as 'CustomerID', 'Name', and 'Contact'. In contrast, 'IPhone6' represents an entity occurrence of the 'Product' entity type, with attributes like 'SerialNumber', 'Color', and 'MemorySize'. These concepts assist in structuring data models by categorizing data and defining unique identifiers and characteristics for each category and instance .

Ordering in SQL queries, achieved using ORDER BY, sorts the results to enhance data analysis and presentation. For example, SELECT ename, deptno FROM emp WHERE job = 'MANAGER' ORDER BY ename orders manager names alphabetically, aiding quick identification and comparison of managerial staff, thus facilitating better data-driven decisions. It structures data output in a user-friendly manner .

Multiplicity affects schema design by determining how tables relate, influencing foreign key constraints. Best practices include carefully analyzing entity relationships, setting appropriate primary-foreign key mappings, and ensuring each entity's participation and cardinality accurately reflects real-world scenarios. Design must avoid unnecessary complexities and redundancies while considering future scalability, which is crucial for maintaining data integrity and efficient database operation .

The concept of multiplicity in Entity Relationship Diagrams refers to the participation and cardinality. For a lab computer, the multiplicity 0..1 on the side of the lab computer represents that a lab computer may be located in zero or one location, while 1..* on the location side indicates a location must have at least one lab computer. In an order product relationship, 0..* for orders implies an order can include no products or many, while for products 1..* suggests each product is included in one or more orders. For laptop staff, a staff is 1..3 meaning a staff can be allocated up to three laptops, whereas 0..1 for laptop means a laptop may not be allocated or can be allocated to one staff .

You might also like