Question

You are given a database schema as follows: Transaction(TID, Staff, Shop) Item(ItemCode, Description, Price) TransItem(TID, ItemCode,...

You are given a database schema as follows:

Transaction(TID, Staff, Shop)

Item(ItemCode, Description, Price)

TransItem(TID, ItemCode, Quantity)

Sample data of the tables are shown below:

TID

Staff

Shop

1

Ann

1

2

Ann

1

3

Ben

2

Transaction

ItemCode

Description

Price

A1

Milk

6

B1

Bread

10

B2

Chocolate

20

Item

TID

ItemCode

Quantity

1

A1

1

1

B2

2

2

B2

1

3

A1

4

3

B2

1

TransItem

Assumptions:

  1. TID, Shop and Price are integers
  2. ItemCode contains a letter followed by number with at most 3 digits
  3. Staff and Description are string with at most 255 characters
  1. Write down the SQL statements for creating the above tables database.

Note: You can ignore the primary key setting in this question.

b. Write down the SQL statements for inserting the sample data to your tables.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below are the queries required and the explanations;

For creating any tables we should have a datbase so we create a database using CREATE DATABASE Command.

CREATE DATABASE PurchaseDB;

The CREATE TABLE statement is used to create a new table in a .Database

Below is the syntax:

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);

1.Creating a Transactions table : to create a table we need to use Create keyword like below

CREATE TABLE Transactions
(
TID int,
Staff varchar(255),
Shop int
);

2. Creating Item table

CREATE TABLE Item
(
ItemCode varchar(50),
Description varchar(255),
Price int
);

3. Creating TransItem Table

CREATE TABLE TransItem
(
TID int,
ItemCode varchar(50),
Quantity int
);

Now we will start inserting data into the tables we cretaed above. To insert data into a table use Insert Command

Insert Data into Transactions table:

insert into Transactions values(1,'Ann',1)
insert into Transactions values(2,'Ann',1)
insert into Transactions values(3,'Ben',2)

Insert Data into Item table:

insert into Item values('A1','Milk',6)
insert into Item values('B1','Bread',10)
insert into Item values('B2','Chocolate',20)

Insert Data into TransItem table

insert into TransItem values(1,'A1',1)
insert into TransItem values(1,'B2',2)
insert into TransItem values(2,'B2',1)
insert into TransItem values(3,'A1',4)
insert into TransItem values(3,'B2',1)

Add a comment
Know the answer?
Add Answer to:
You are given a database schema as follows: Transaction(TID, Staff, Shop) Item(ItemCode, Description, Price) TransItem(TID, ItemCode,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Shoe store’s database schema is as follows: Shoes(id, name, description, color1, color2, d_id) CK: name...

    The Shoe store’s database schema is as follows: Shoes(id, name, description, color1, color2, d_id) CK: name FK: d_id references Department(id) Department(id, name, description) CK: name Orders(id, shoe, size, quantity, has_arrived) FK: shoe references Shoes(id) Step 1 (30 points): Write create statements for each of the above tables, making sure to have appropriate data types and with all keys declared. To receive full credit, you must have both your exact SQL statement and a screenshot showing the successful executing of your...

  • Project Description In this project, you will design and implement a database for keeping track of...

    Project Description In this project, you will design and implement a database for keeping track of information for an online “SOCIAL NETWORK” system (e.g. a simplified version of Facebook!). You will first design an EER schema diagram for this database application. Then, you will map the EER schema into a relational database schema and implement it on ORACLE or MySQL or some other relational DBMS. Finally, you will load some data into your database (via user Interface) and create some...

  • The following relational schema is given for a Pokemon Database: Pokemon (PID, PName) Type (TID, TName)...

    The following relational schema is given for a Pokemon Database: Pokemon (PID, PName) Type (TID, TName) Trainer (SSN, Name, Surname) InType (PID, TID) StrongAgainst (TID_Strong, TID_Weak) Owns (SSN, PID, Nickname, Level, Height, Weight, Catch_Date) SpecializedIn (SSN, TID) In this database, Pokemon (Imaginary creatures, short for “Pocket Monsters”) are stored in the entity set Pokemon, with a unique PID and PName. Pokemon types are stored in the entity set Type, with a unique TID and TName. Pokemon trainers are stored in...

  • This is third time im posting this Question COURSE; introduction to database Please, No handwriti...

    This is third time im posting this Question COURSE; introduction to database Please, No handwriting thanks for your efforts Design the database by following . Execute the sample requested queries. . ER Diagram. . All schemas before and after normalization. . All SQL statements of: -Creating tables. - Inserting data in tables. -Queries. 5. Screenshots from MySQL (or any other software you use) Question is - Database system for a Wholesale Management System Consider a database system for a Wholesale...

  • You are given a database in a MS Access file called ‘DBP-e14-Cape-Codd’ that contains data collected...

    You are given a database in a MS Access file called ‘DBP-e14-Cape-Codd’ that contains data collected in an outdoor sports retail store. The retail store hired you as a data analyst to answer questions in order to help them make business decisions that will help them grow. Write the SQL statement for each query and save them in MS Access as Q1, Q2,… Please submit the MS Access and MS Word to help speed the grading turnout! in Blackboard. (to...

  • This is third time im posting this Question COURSE; introduction to database Please, No handwriting thanks...

    This is third time im posting this Question COURSE; introduction to database Please, No handwriting thanks for your efforts Design the database by following . Execute the sample requested queries. . ER Diagram. . All schemas before and after normalization. . All SQL statements of: -Creating tables. - Inserting data in tables. -Queries. 5. Screenshots from MySQL (or any other software you use) Question is - Database system for a Wholesale Management System Consider a database system for a Wholesale...

  • QUESTION 1 The following tables form part of a database held in a relational DBMS for storing the information of Customer, Item, Transaction, and temSale A transaction can contain multiple ite...

    QUESTION 1 The following tables form part of a database held in a relational DBMS for storing the information of Customer, Item, Transaction, and temSale A transaction can contain multiple items and an item can be in multiple transactions as depicted in the following sample data Item(itemid, name, category, price Itemid pk) name category price Iteml Pencil Stationery $30 paperStationery Item2 $25 $15 Item3 Cards Stationery S40 Item4 Ink Stationery S13 Item5 Sprite Itemo Food S4 Milk Food Transaction ctransid,...

  • CUSTTYPE (TID, TypeDesc) CUSTOMER (CID, Lname, Fname, TID, Address, ZIPcode) CUSTORDER (OrderNo, OrderDate, PromiseDate, ShippedDate, ShippingTerm,...

    CUSTTYPE (TID, TypeDesc) CUSTOMER (CID, Lname, Fname, TID, Address, ZIPcode) CUSTORDER (OrderNo, OrderDate, PromiseDate, ShippedDate, ShippingTerm, SalesID, CID) SALESREP (SalesID, Name, Phone, Address, ZIPcode, RepType) ORDERLINE (OrderNo, PID, Qty, Qty_RETD) FTSALESREP (SalesID, MonthPay, Rank) PTSALESREP (SalesID, HourlyRate, WeekHours) ZIP_TABLE (ZIPcode, City, State) VENDOR (VID, Name, Phone ZIPcode) PRODUCT (PID, CateID, ProdName, ProdFinish, Price, Qty_on_Hand, Description, VID) CATEGORY (CateID, CateType) Local View #1: Use three base tables to develop a SQL statement that will list the following information for a customer,...

  • SQL QUERIES 1) Using the Product and PC relations, create both tables in your database and...

    SQL QUERIES 1) Using the Product and PC relations, create both tables in your database and insert all the data. Show the SQL statements to create each table and show a representative SQL insert statement for the data in each table (i.e. you do not need to show insert statements for all the data). – For the remaining questions, assume that your SQL is part of a program function and the function provides the input needed for your SQL query....

  • Please help I promise positive feedback Part IV. Formulate SQL queries that follow for the database...

    Please help I promise positive feedback Part IV. Formulate SQL queries that follow for the database with the following tables: CUSTOMER, PRODUCT, SALES, and ITEM-SOLD. Table: CUSTOMER Primary Key: Account-No Account-No Customer-Name Customer-City 1 A NYC 2 B NYC 3 C MIA Table: PRODUCT Primary Key: Item-No Item-No Price 1 $1.00 2 $2.00 3 $3.00 4 $4.00 Table: SALES Primary Key: Receipt-No Foreign Key: Account-No References CUSTOMER Receipt-No Account-No Sales-Person 1 1 S1 2 1 S1 3 2 S2 4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT