Computer Science Homework Solutions
Problem
#67560

Create E-R diagram

(See attached file for full problem description)

---
Using the script file below to create an E-R diagram of the entities, attributes and relationship.


# use the "my_database" database
USE my_database;

# create a table called "items" with 3 records
CREATE TABLE IF NOT EXISTS items
(
  id INT PRIMARY KEY,
  vendor INT NOT NULL,
  name CHAR(20) NOT NULL,
  price DECIMAL(6,2) NOT NULL
);
INSERT INTO items (id, vendor, name, price)
  VALUES (601, 2, "Elephants", 147.50);
INSERT INTO items (id, vendor, name, price)
  VALUES (602, 2, "Reindeers",  123.00);
INSERT INTO items (id, vendor, name, price)
  VALUES (603, 1, "Alligators", 185.00);

# create a table called "vendors" with 2 records
CREATE TABLE IF NOT EXISTS vendors
(
  id INT PRIMARY KEY,
  name CHAR(20) NOT NULL
);
INSERT INTO vendors (id, name) VALUES (1, "Alpha Inc");
INSERT INTO vendors (id, name) VALUES (2, "Zeta Inc");

# create a table called "orders" with 3 records
CREATE TABLE IF NOT EXISTS orders
(
  num INT PRIMARY KEY,
  item INT NOT NULL,
  qty INT NOT NULL
);
INSERT INTO orders (num, item, qty) VALUES (2805, 603, 10);
INSERT INTO orders (num, item, qty) VALUES (2806, 603, 5);
INSERT INTO orders (num, item, qty) VALUES (2807, 601, 10);

# display order number, quantity, item name, vendor
# and total order value of order number 2805
SELECT  orders.num AS Number,
     orders.qty AS Qty,
items.name AS Toy,
vendors.name AS Vendor,
items.price * orders.qty AS Total
FROM items, vendors, orders
WHERE vendors.id = items.vendor
AND             items.id = orders.item
AND            orders.num = 2805;

# delete these sample tables
DROP TABLE IF EXISTS items;
DROP TABLE IF EXISTS vendors;
DROP TABLE IF EXISTS orders;
---

Attached file(s):
Attachments
ER.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

ER.doc
Using the script file below to create an E-R diagram of the entities,
attributes and relationship.

# use the "my_database" database

USE my_database;

# create a table called "items" with 3 records

CREATE TABLE IF NOT EXISTS items

(

id INT PRIMARY KEY,

vendor INT NOT NULL,

name CHAR(20) NOT NULL,

price DECIMAL(6,2) NOT NULL

);

INSERT INTO items (id, vendor, name, price)

VALUES (601, 2, "Elephants", 147.50);

INSERT INTO items (id, vendor, name, price)

VALUES (602, 2, "Reindeers", 123.00);

INSERT INTO items (id, vendor, name, price)

VALUES (603, 1, "Alligators", 185.00);

# create a table called "vendors" with 2 records

CREATE TABLE IF NOT EXISTS vendors

(

id INT PRIMARY KEY,

name CHAR(20) NOT NULL

);

INSERT INTO vendors (id, name) VALUES (1, "Alpha Inc");

INSERT INTO vendors (id, name) VALUES (2, "Zeta Inc");

# create a table called "orders" with 3 records

CREATE TABLE IF NOT EXISTS orders

(

num INT PRIMARY KEY,

item INT NOT NULL,

qty INT NOT NULL

);

INSERT INTO orders (num, item, qty) VALUES (2805, 603, 10);

INSERT INTO orders (num, item, qty) VALUES (2806, 603, 5);

INSERT INTO orders (num, item, qty) VALUES (2807, 601, 10);

# display order number, quantity, item name, vendor

# and total order value of order number 2805

SELECT orders.num AS Number,

orders.qty AS Qty,

items.name AS Toy,

vendors.name AS Vendor,

items.price * orders.qty AS Total

FROM items, vendors, orders

WHERE vendors.id = items.vendor

AND items.id = orders.item

AND orders.num = 2805;

# delete these sample tables

DROP TABLE IF EXISTS items;

DROP TABLE IF EXISTS vendors;

DROP TABLE IF EXISTS orders;

____________________________________________________________________

Items

id

name

vendor

price

vendors

id

name

orders

num

qty

item
Solution
What is this?
By OTA - Overall OTA Rating
Charlene Li, MIWP (IP) - 4.4/5
Purchase Cost Now
$2.19 CAD (was ~$7.98)
Included in Download
  • Plain text response
  • Attached file(s):
    • ER-Diagram.gif
    • ERDiagram&Note.gif
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Example of Database Relationships - Look for an example of a one-to-one relationship, an example of a one-to-many relationship, and an example of a many-to-many relationship in a newspaper, magazine, book, or everyday situation you enco ...
  • Databases-derived attribute - Hi, What is derived attribute? Give an example. I require a detailed example and definition of this problem with referencing please. Regards,
  • Relational Databases - Look for an example of a one-to-one relationship, an example of a one-to-many relationship, and an example of a many-to-many relationship in a newspaper, magazine, book, or everyday situation you enco ...
  • The Relational Model and Data Normalization - 1. Define functional dependency and give an example. 2. What are insertion and deletions anomalies? 3. List and briefly describe first, second and third normal form. 4. Descri ...
  • Database Concept - What are the main components when designing an ERD?
Browse