Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the schemas and instances below. #prod should be prodid #dep should be depid. The primary key of product is prodid. The primary key of

Consider the schemas and instances below.
#prod should be prodid
#dep should be depid.
The primary key of product is prodid. The primary key of depot is depid. The (composite) primary key of stock is prodid, depid.
prodid in stock is a foreign key referring the primary key prodid in product.
depid in stock is a foreign key referring the primary key depid in depot.
* Schemas:
-Product(#prod, pname, price)
-Depot (#dep, addr, volume)
-Stock (#prod, #dep, quantity)
*Instanoes:
Product
#prod pname price
p1 tape 2.5
p2 tv 250
p3 ver 80
Depot
#dep addr volume
d1 New York 9000
d2 Syracuse 6000
d4 New York 2000
Stock
#prod #dep quantity
p1 d11000
p1 d2-100
p1 d41200
p3 d13000
p3 d42000
p2 d41500
p2 d1-100
p2 d22000
Write the code that will create the tables: product, depot and stock, and populate them with the provided data following the instructions below.
SQL code (tested in PostgreSQL without syntax errors):
Instructions:
* YOU WILL NOT WRITE SQL CODE THIS WAY:
CREATE TABLE Product(
prod_id CHAR(10),
pname VARCHAR(30),
price DECIMAL,
PRIMARY KEY (prod_id),
CHECK (price >0));
* BUT YOU WILL PROVIDE NAMES FOR ALL OF THE CONSTRAINTS AND USE ALTER TABLE:
CREATE TABLE Product(
prod_id CHAR(10),
pname VARCHAR(30),
price DECIMAL);
ALTER TABLE Product ADD CONSTRAINT pk_product PRIMARY KEY (prod_id);
ALTER TABLE Product ADD CONSTRAINT ck_product_price CHECK (price >0);
Primary key constraints begin with pk_.
Foreign key constraints begin with fk_.
Check constraints begin with ck_.
Follow instructions for above question and give what exactly question want.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Perform an Internet search. Discuss a company that uses EPLI.

Answered: 1 week ago

Question

How do you feel about employment-at-will policies? Are they fair?

Answered: 1 week ago