Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. You own a farm (ok, a big farm) and want to start a DB to keep track of impor

ID: 3698520 • Letter: 1

Question

1. You own a farm (ok, a big farm) and want to start a DB to keep track of important things. In particular you want to keep track of crops and animals. 2. Create the following tables, with at least the field information listed (the info provided are not field names; you supply them): A. Crop -crop name -cost of seed (per bushel) -yield per acre (in bushels) -current number of acres planted in the crop -average cost to grow per acre -date the crop is ideally planted B. Animal -animal name (e.g., "cow); this may not be null -type (either "DO for domestic or FN for foreign) -current number of head owned -offspring? (a yes/no field that states if the animal could have baby animals on the farm) 3. Create the proper relationship between the two tables. The business rules are that an animal may be fed one crop, and a crop is fed to one or more animals. 4. After you have done the above, add a field the gives the average number of days that it takes for a crop to grow, from planting to harvesting. Do not let this value be left blank

Explanation / Answer

2) Create statement is used to create table Crops and Animal. Each of these table have primary key. The attributes are similar to mentioned description.

CREATE TABLE Crop

(

cname VARCHAR(25),

seedCost DECIMAL(4,2),

yieldAcre INT,

plantedACre INT,

avgCost DECIMAL(4,2),

plantedDate DATE,

PRIMARY KEY (cname)

);

CREATE TABLE Animal

(

aname VARCHAR(25),

type CHAR(2),

headOwned INT,

offSpring BOOLEAN,

PRIMARY KEY (aname)

);

3)Creating a relationship between two tables Crops and Animal. A crop is fed to one and more animals. This is 1:N relationship.

CREATE TABLE fed

(

cname INT,

aname INT,

PRIMARY KEY (cname, aname),

FOREIGN KEY (cname) REFERENCES (Crop),

FOREIGN KEY (aname) REFERENCES (aname)

);

4) Adding one more column to table Crops and declaring it as not null.

ALTER TABLE Crop

ADD daysToGrow INT NOT NULL;