Question

In: Computer Science

USING SQL Create a table named Zones with the attributes and assumptions indicated below. Attributes: the...

USING SQL

Create a table named Zones with the attributes and assumptions indicated below.

  • Attributes: the zone ID, the lowest and the highest accepted temperature.

Assumptions: the ID will be the primary key and have one or two digits, the temperatures (in Fahrenheit) will be at most two digits and a possible minus sign, none of the temperatures can be NULL.

Populate table Zones so that it has the following rows:

id lowerTemp higherTemp
2 -50 -40
3 -40 -30
4 -30 -20
5 -20 -10
6 -10 0
7 0 10
8 10 20
9 20 30
10 30 40

3. Deliveries

The same flower vendor wants to use a code to explain the type of delivery for each flower. Create a table named Deliveries with the attributes and assumptions indicated below.

  • Attributes: the delivery ID, the category or type of delivery, and the size of the delivery.

  • Assumptions: the ID will be the primary key and have one one digit, the category will be at most five characters (pot, plant, hedge, shrub, tree), and the delivery size will be up to five digits with three decimal spaces (possibly NULL).

Populate table Deliveries so that it has the following rows:

id categ delSize
1 pot 1.500
2 pot 2.250
3 pot 2.625
4 pot 4.250
5 plant NULL
6 bulb NULL
7 hedge 18.000
8 shrub 24.000
9 tree 36.000

3. FlowersInfo

Create a table named FlowersInfo with the attributes and assumptions indicated below. Choose the most appropriate data types.

Attributes: an ID with three characters, common name, Latin name, the coolest and hottest zones where it can be grown, the delivery category, and the sun needs.

Assumptions: The ID will be the primary key, the attribute common name may have up to thirty characters, and the Latin name up to thirty-five characters. The attributes coolest zone, hottest zone, and delivery category will match the IDs from other tables, and the sun needs will be up to five characters, S for Sun, SH for Shade, P for Partial sun and any combination (StoP, StoSH, etc.). Your table definition should implement referential integrity whenever possible.
Populate table FlowersInfo so that it has the following rows:

id conName latName cZone hZone deliver sunNeeds
101 Lady Fern Atbyrium filix-femina 2 9 5 SH
102 Pink Caladiums C.x bortulanum 10 10 6 PtoSH
103 Lily-of-the-Valley Convallaria majalis 2 8 5 PtoSH
105 Purple Liatris Liatris spicata 3 9 6 StoP
106 Black Eyed Susan Rudbeckia fulgida var. specios 4 10 2 StoP
107 Nikko Blue Hydrangea Hydrangea macrophylla 5 9 4 StoSH
108 Variegated Weigela W. florida Variegata 4 9 8 StoP
110 Lombardy Poplar Populus nigra Italica 3 9 9 S
111 Purple Leaf Plum Hedge Prunus x cistena 2 8 7 S
114 Thorndale Ivy Hedera belix Thorndale 3 9 1 StoSH

4. Queries

Write SQL statements to answer the following queries. Write a comment header right before each SQL statement with the letter of the query answered by the statement.

a) the total number of zones.

b) the number of flowers per cool zone.

c) common names of the plants that have delivery sizes less than 5.

d) common names of the plants that require full sun (i.e., sun needs contains ‘S’).

e) all delivery category names order alphabetically (without repetition).

f) the exact output (note that it is order by Name):

Solutions

Expert Solution

If you have any doubts, please give me comment...

--1

CREATE TABLE Zones(

    id INT(2) NOT NULL PRIMARY KEY,

    lowerTemp INT,

    higherTemp INT

);

INSERT INTO Zones VALUES(2,-50,-40);

INSERT INTO Zones VALUES(3, -40, -30);

INSERT INTO Zones VALUES(4, -30, -20);

INSERT INTO Zones VALUES(5, -20, -10);

INSERT INTO Zones VALUES(6, -10, 0);

INSERT INTO Zones VALUES(7, 0, 10);

INSERT INTO Zones VALUES(8, 10, 20);

INSERT INTO Zones VALUES(9, 20, 30);

INSERT INTO Zones VALUES(10, 30, 40);

-- 2

CREATE TABLE Deliveries(

    id INT(1) NOT NULL PRIMARY KEY,

    categ VARCHAR(5),

    delSize DECIMAL(9, 3)

);

INSERT INTO Deliveries VALUES(1, 'pot', 1.500);

INSERT INTO Deliveries VALUES(2, 'pot', 2.250);

INSERT INTO Deliveries VALUES(3, 'pot', 2.625);

INSERT INTO Deliveries VALUES(4, 'pot', 4.250);

INSERT INTO Deliveries VALUES(5, 'plant', NULL);

INSERT INTO Deliveries VALUES(6, 'bulb', NULL);

INSERT INTO Deliveries VALUES(7, 'hedge', 18.000);

INSERT INTO Deliveries VALUES(8, 'shrub', 24.000);

INSERT INTO Deliveries VALUES(9, 'tree', 36.000);

-- 3

CREATE TABLE FlowerInfo(

    id INT(3) NOT NULL PRIMARY KEY,

    conName VARCHAR(30),

    latName VARCHAR(35),

    cZone INT(2),

    hZone INT(2),

    deliver INT(1),

    sunNeeds  VARCHAR(5),

    FOREIGN KEY(cZone) REFERENCES Zones(id),

    FOREIGN KEY(hZone) REFERENCES Zones(id),

    FOREIGN KEY(deliver) REFERENCES Deliveries(id)

);

INSERT INTO FlowerInfo VALUES(101, 'Lady Fern', 'Atbyrium filix-femina', 2, 9, 5, 'SH');

INSERT INTO FlowerInfo VALUES(102, 'Pink Caladiums', 'C.x bortulanum', 10, 10, 6, 'PtoSH');

INSERT INTO FlowerInfo VALUES(103, 'Lily-of-the-Valley', 'Convallaria majalis', 2, 8, 5, 'PtoSH');

INSERT INTO FlowerInfo VALUES(105, 'Purple Liatris', 'Liatris spicata', 3, 9, 6, 'StoP');

INSERT INTO FlowerInfo VALUES(106, 'Black Eyed Susan', 'Rudbeckia fulgida var. specios', 4, 10, 2, 'StoP');

INSERT INTO FlowerInfo VALUES(107, 'Nikko Blue Hydrangea', 'Hydrangea macrophylla', 5, 9, 4, 'StoSH');

INSERT INTO FlowerInfo VALUES(108, 'Variegated Weigela', 'W. florida Variegata', 4, 9, 8, 'StoP');

INSERT INTO FlowerInfo VALUES(110, 'Lombardy Poplar', 'Populus nigra Italica', 3, 9, 9, 'S');

INSERT INTO FlowerInfo VALUES(111, 'Purple Leaf Plum Hedge', 'Prunus x cistena', 2, 8, 7, 'S');

INSERT INTO FlowerInfo VALUES(114, 'Thorndale Ivy', 'Hedera belix Thorndale', 3, 9, 1, 'StoSH');

-- 4a

SELECT COUNT(*) FROM Zones;

-- 4b

SELECT cZone, COUNT(*) AS "No of Flowers"

FROM FlowerInfo

GROUP BY cZone;

-- 4c

SELECT conName

FROM FlowerInfo, Deliveries

WHERE FlowerInfo.deliver = Deliveries.id AND delSize < 5;

-- 4d

SELECT conName

FROM FlowerInfo

WHERE sunNeeds = 'S';

-- 4e

SELECT DISTINCT categ

FROM Deliveries

ORDER BY categ;

-- 4f

SELECT categ

FROM Deliveries

ORDER BY categ;


Related Solutions

Create a ‘Student’ table using SQL query. The table must have at least five attributes from...
Create a ‘Student’ table using SQL query. The table must have at least five attributes from your choice with different data types.
Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier...
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier schema. CREATE TABLE IF NOT EXISTS customer_audit ( customer_num CHAR(3) NOT NULL,   customer_name VARCHAR(35) NOT NULL, street VARCHAR(15), city VARCHAR(15), state CHAR(2), zip CHAR(5), credit_limit DECIMAL(8,2), date_changed DATETIME NOT NULL, changed_by VARCHAR(45) NOT NULL); Notice that the audit table does not have a primary key defined. Explain why this might be acceptable. Based on the current attributes in the customer_audit table, suggest a possible...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Use a single SQL statement to create a relational table and to load into the table...
Use a single SQL statement to create a relational table and to load into the table department name, subject code, year of running and session of running that offered by the departments. Note that a running subject offered by a department means a lecturer of the department has been assigned to teach the subject. Next, enforce the appropriate consistency constraints on the new table.    When ready use SELECT statement to list the contents of the relational table created and...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Create a Database in POSTGRESQL using the following table names and attributes: users: userid (int, primary...
Create a Database in POSTGRESQL using the following table names and attributes: users: userid (int, primary key), name (text) movies: movieid (integer, primary key), title (text) taginfo: tagid (int, primary key), content (text) genres: genreid (integer, primary key), name (text) ratings: userid (int, foreign key), movieid (int, foreign key), rating (numeric), timestamp (bigint, seconds since midnight Coordinated Universal Time (UTC) of January 1, 1970) tags: userid (int, foreign key), movieid (int, foreign key), tagid (int, foreign key), timestamp (bigint, seconds...
Using the Quality Attributes Table document provided, complete a page table of quality attributes. Individual Assignment...
Using the Quality Attributes Table document provided, complete a page table of quality attributes. Individual Assignment – Week Four Complete the following table: Attribute Type Categories within the Attribute Type Example from the program Functional attributes <List the categories of attributes of this type (for example “Boolean”)> <Describe an attribute you can measure in your program (for example, user data integrity)> Operational attributes Usability attributes Business attributes Structural attributes
SUBJECT: PROGRAMMING IN SQL 1. Create a view named vDepartmentInstructors that returns these columns: the DepartmentName...
SUBJECT: PROGRAMMING IN SQL 1. Create a view named vDepartmentInstructors that returns these columns: the DepartmentName column from the Departments table the LastName, FirstName, Status, and AnnualSalary columns from the Instructors table. 2. Write a SELECT statement that returns all the columns from the vDepartmentInstructors view that you created in question 1. Return one row for each fulltime instructor in the English department. 3. Write an UPDATE statement that updates the vDepartmentInstructors view you created in question 1 so it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT