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

Garden Database Assignment Overview

This document contains an assignment involving SQL queries on a database about a family garden. The database contains tables with information about garden locations, gardeners, plants, plantings, and harvests. The assignment asks students to identify an entity and relationship from the tables, write SQL statements to create a table, insert a new record, delete a record, and calculate a total from the tables.

Uploaded by

Mazen H
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)
18 views3 pages

Garden Database Assignment Overview

This document contains an assignment involving SQL queries on a database about a family garden. The database contains tables with information about garden locations, gardeners, plants, plantings, and harvests. The assignment asks students to identify an entity and relationship from the tables, write SQL statements to create a table, insert a new record, delete a record, and calculate a total from the tables.

Uploaded by

Mazen H
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

1/24/24, 8:10 AM Assignment 4 Database System and Information Retrieval

STID 3014

ASSIGNMENT 4

Please use the following GARDEN database to answer all questions below:

Location Gardener
-------- --------
LocationID Name Sunlight Water | GardenerID Name Age
---------- ---- -------- ----- | ---------- ---- ---
0 East .28 .80 | 0 Mother 36
1 North .17 .84 | 1 Father 38
2 West .38 .48 | 2 Tim 15
3 South .45 .66 | 3 Erin 12

Plant
-----
PlantID Name Sunlight Water Weight
------- ---- -------- ----- -----
0 Carrot .26 .82 .08
1 Beet .44 .80 .04
2 Corn .44 .76 .26
3 Tomato .42 .80 .16
4 Radish .28 .84 .02

Planted
-------
PlantFK GardenerFK LocationFK Date Seeds
------- ----------- ---------- --------- -----
0 0 0 04-18-2005 28
0 1 1 04-14-2005 14
1 0 2 04-18-2005 36
2 1 3 04-14-2005 20
2 2 2 04-19-2005 12
3 3 3 04-25-2005 38
4 2 0 04-30-2005 30

Picked
------
PlantFK GardenerFK LocationFK Date Amount Weight
------- ---------- ---------- --------- ------ ------
0 2 0 08-18-2005 28 2.32
0 3 1 08-16-2005 12 1.02
2 1 3 08-22-2005 52 12.96
2 2 2 08-28-2005 18 4.58
3 3 3 08-22-2005 15 3.84
4 2 0 07-16-2005 23 0.52

Some notes on terms:

 The database is for a simple garden kept by a small family


 They plant their garden in the spring and pick their garden in summer
 The sunlight attribute refers to the percentage of a 24-hour day that the location gets
sunlight and the plant optimally wants sunlight.
 The water attribute refers to the percentage of average rainfall that makes it to the root level
for a location or is optimal for a plant.
 The plant (average expected) and picked (actual) weight is in kilograms

about:blank 1/3
1/24/24, 8:10 AM Assignment 4 Database System and Information Retrieval

 The picked amount is the number of items (one carrot, one beet, an ear of corn, one tomato,
and one radish) picked.

a) Based on the given tables, identify ONE (1) entity and ONE (1) relationship.
(2 marks)
Entity : Plant
Relationship : Planted

b) Write a valid SQL statement to create the location table.


(3 marks)

CREATE TABLE Location (LocationID INTEGER, Name VARCHAR(20), Sunlight


DECIMAL(2.2), Water DECIMAL(2,2))

c) Write a valid SQL statement to add a new plant to the plant table.
(2 marks)

INSERT INTO Plant (PlantID, Name, Sunlight, Water, Weight) VALUES (5, 'Spinach',
.45, .74, .19)

d) For some reason, the beet crop did not succeed in producing edible beets. The family wants
to eliminate beets from their garden forever. Write a valid SQL statement to delete the beet
plant from the plant table.
(1 mark)

DELETE FROM Plant WHERE PlantID= 1

e) Write a valid SQL statement that calculates the total weight of all corns that were picked
from the garden.
(2 marks)

about:blank 2/3
1/24/24, 8:10 AM Assignment 4 Database System and Information Retrieval

about:blank 3/3

Common questions

Powered by AI

Maintaining data consistency across interrelated tables is challenging due to potential cascade effects of updates or deletions. Foreign keys help preserve referential integrity, but consistency requires careful transaction design, possibly involving triggers or cascading actions to ensure all related data remains synchronized across 'Planted', 'Picked', and other related tables .

The SQL DELETE statement is used to permanently remove rows from a database table. In this context, to conform with business rules such as removing a plant type like 'Beet', DELETE FROM Plant WHERE PlantID= 1 can be used. This ensures that no new entries related to this plant can be added, aligning with the family's decision to eliminate beets from their garden .

Date attributes in the 'Planted' and 'Picked' tables are vital for analyzing agricultural cycles, allowing the family to track the duration of growth periods, harvest times, and seasonal effectiveness. Understanding these cycles helps optimize planting schedules, predict future yields, and adjust strategies to improve overall garden management .

Deleting a specific plant type, such as 'Beet', from the plant table could potentially violate referential integrity constraints if there are related entries in other tables like 'Planted' or 'Picked' that reference the plant's primary key. If such dependencies exist, cascading deletions or additional constraint-handling measures are necessary to maintain database integrity .

Sunlight and water attributes are crucial for modeling plant growth in the database as they represent the percentage of environmental conditions each plant receives or requires. These attributes guide the gardener in planting decisions, ensuring optimal conditions for each plant type, thus maximizing yield and efficiency in the garden's production .

Structuring the 'Planted' table with foreign keys for 'PlantFK', 'GardenerFK', and 'LocationFK' ensures referential integrity and allows for efficient joins and retrieval of comprehensive datasets about the planting activities. This enhances database normalization, reduces redundancy, and improves query performance .

The entities identified in the garden database schema are 'Plant' and 'Location'. The relationship identified is 'Planted', which connects the 'Plant' entity to the 'Gardener' and 'Location' entities through foreign keys .

SQL Command: SELECT SUM(Weight) FROM Picked WHERE PlantFK = 2;. Insights from this data can reveal production success over time, aiding in assessing crop viability, adjusting resource allocation, and optimizing future planting decisions based on yield outcomes .

By analyzing data trends in the 'Picked' table, the family can identify patterns in crop yields, optimal harvesting times, and the effectiveness of resource allocation. This information can aid in making evidence-based adjustments to planting techniques, crop selection, and resource management, ultimately enhancing garden productivity and sustainability .

SQL Statement: SELECT * FROM Plant WHERE Sunlight < 0.40;. This query helps in selecting plants that are optimal for specific areas in the garden with limited sunlight, thus ensuring efficient placement and potentially better growth outcomes .

You might also like