RobMack8932 / assignments

Assignments for Suncoast Developers Guild
0 stars 0 forks source link

03 - 02 - Foreign Keys - The SQL #9

Closed RobMack8932 closed 4 years ago

RobMack8932 commented 4 years ago

As we continue to explore databases and ideas, this project will help you practice model databases and relationships.

We will be expanding on our CompanyDatabase from the INSERT INTO Student (knowledge) VALUES ('SQL') assignment. You will be adding new tables and be writing queries for these new tables.

Reuse the same repository from that assignment for this assignment. Add the new queries below the queries from that assignment such that the one repository will have both sets of queries. Use the same repository URL to turn in tonight's homework.

Objectives

Explorer Mode

Adventure Mode

Epic Mode

Additional Resources

RobMack8932 commented 4 years ago

----New table for Departments

CREATE TABLE "Departments" ( "Building" TEXT, "DepartmentName" TEXT, "Id" SERIAL PRIMARY KEY ); --Create foreign key NEEDS WORK CREATE TABLE "Employees" ( "DepartmentId" SERIAL PRIMARY KEY, "Description" TEXT ); --Adding tables Products and Orders IMPLEMENT CREATE TABLE "Orders" ( "Id" SERIAL PRIMARY KEY, "OrderNumber" INT, "DatePlaced" DATE, "EMAIL" STRING_AGG

); --DOUBLE????? CREATE TABLE "Products" ( "Price" INT.INT , "Name" STRING_AGG, "Description" STRING_AGG, "QuantityInStock" INT );

--many to many relationship????

CREATE TABLE "ProductOrders" ( "Id" SERIAL PRIMARY KEY, "OrderId" INTEGER REFERENCES "Orders" ("Id"), "ProductId" INTEGER REFERENCES "Products" ("Id") ); --Make Quantity in Stock CREATE TABLE "Products" ( "QuantityInStock" SERIAL PRIMARY KEY, "Description" INT );

--- INSERT INTO DEPARTMENTS INSERT INTO "Departments" ("Building", "DepartmentName") VALUES ('Main', 'Development'); INSERT INTO "Departments" ("Building", "DepartmentName") VALUES ('North', 'Marketing'); ----INSERT INTO EMPLOYEES INSERT INTO "Employees" ("FullName", "Salary", "JobDescription", "PhoneExtension", "IsPartTime", "DepartmentId") VALUES ('Tim Smith', 40000, 'Programmer', 123, 'false', 1); INSERT INTO "Employees" ("FullName", "Salary", "JobDescription", "PhoneExtension", "IsPartTime", "DepartmentId") VALUES ('Barbara Ramsey', 80000, 'Manager', 234, 'false', 1); INSERT INTO "Employees" ("FullName", "Salary", "JobDescription", "PhoneExtension", "IsPartTime", "DepartmentId") VALUES ('Tom Jones', 32000, 'Admin', 456, 'true', 2); --INSERT PRODUCTS INSERT INTO "Products" ("Price", "Name", "Description", "QuantityInStock") VALUES (12.45, 'Widget', 'The Original Widget', 100); INSERT INTO "Products" ("Price", "Name", "Description", "QuantityInStock") VALUES (99.99, 'Flowbee', 'Perfect for haircuts', 3); --Insert new order INSERT INTO "Orders" ("OrderNumber", "DatePlaced", "EMAIL") VALUES (X529, 'Jan 1st, 202 at 4:55pm', 'person@example.com '); --Add order quantity of 3 to widget UPDATE "QuantityInStock" SET "OrderNumber" = 3 WHERE "Name" = 'Widget'; --Add order quantity of 2 to Flowbee UPDATE "QuantityInStock" SET "OrderNumber" = 2 WHERE "Name" = 'Flowbee'; --Given a department id return all employees 2 SELECT "DepartmentId" FROM "Employees" WHERE "DepartmentId" = 2; --Given department name return all phone extensions ? SELECT "DepartmentName", "PhoneExtension" FROM "Employees"; --Find all orders that contain the product id of 2 SELECT "ProductId" FROM "Orders" WHERE "ProductId" = 2; --Remove Flowbee from x529 DELETE FROM "Flowbee" WHERE "OrderNumber" = X529;

RobMack8932 commented 4 years ago

Your homework 03 - 02 - Foreign Keys - The SQL was marked: Meets Expectations

Get up and dance!

“Get up and dance!”