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

SQL Table Creation Homework Due 2 April 1. You own a farm (ok, a big farm) and w

ID: 3741366 • Letter: S

Question

SQL Table Creation Homework Due 2 April 1. You own a farm (ok, a big farm) and want to start a DB to keep track of important things. In particular vou 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 "D? for domestic or " N" 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 For this homework, I want the hardcopy Notepad++ printout of the code.

Explanation / Answer

Hi

1.

CREATE table Crop (

CropName varchar(255);

cost_Seed decimal;

yieldPerAcre decimal;

planted_acre long;

avg_costPerAcre decimal;

crop_plantedDate date;

);

CREATE table Animal(

animl_Name varchar(255) NOT NULL;

type varchar(2) CHECK (type IN('DO','FN');

headCount int;

offspring varchar(3) CHECK (offspring IN('Yes','No');

);

3.Here the business rules means animal table will refer crop and animal will be fed on 1 crop.

We can create a new table.: Feed

  

And columns will be animl_Name which will act as primary key and cropName will act

as Foreign key referring Crop Table.

  

  

4.

We don't have any harvest date field, so lets assume and add to calculate the number of days.

Alter table Crop Add HarvestPlant Date;

Alter table Crop Add avgDaysToHarvest Date (crop_plantedDate - HarvestPlant);