You are on page 1of 4

Practical example of a SQL database

Tables used below are describing a system for tracking orders used by a distributor. The
tables are used for the following purposes:

Tracking the sellers

Tracking all the products

Tracking the buyers

Tracking all the orders performed by the buyers

Keeping all the details about each product in every order

For all that to work we need 5 tables (interconnected as a part of a RDBMS project.

Table description:

Sellers Table

Sellers Table is keeping all the data about each seller. Each seller has a record in this
table and seller_id is used to create a connection between sellers and products. seller_id
should be unique.

Column Description

seller_id Sellers unique id


seller_name Sellers name
seller_address Sellers address
seller_city Sellers city
seller_state Sellers state
seller_code Sellers postal code
seller_country Sellers country
Products Table

Products Table has data about all the products. Each product has a line, its own record.
Each product has a unique id which is prod_id and its associated with a seller through
seller_id (sellers unique id).

Column Description

prod_id Product unique identifier


seller_id Sellers unique identifier (asociated with seller_id from
Sellers Table)
prod_name Product name
prod_price Product price
prod_desc Product description

Buyers Table

Buyers table has all the data regarding all the buyers. Each buyer has a line, its own
record. Each buyer has an unique identifier (buyer_id).

Column Description

buyer_id Buyers unique identifier


buyer_name Buyers name
buyer_address Buyers address
buyer_city Buyers city
buyer_state Buyers state
buyer_code Buyers postal code
buyer_country Buyers country
buyer_contact Buyers contact person
buyer_email Buyers email address

Orders Table

Orders Table is keeping the data about the orders (but not the details on each record).
Each order has a unique number which is order_nr). The orders are associated to buyers
through buyer_id (which is associated to buyer_id in Buyers Table).

Column Description

order_nr Order unique number


order_date Order date
buyer_id The id of the buyer that ordered (associated with buyer_id
from Buyers table)

OrderDetails Table

OrderDetails Table is keeping the details about each order. Each order is composed by at
least an article which is a product or more products of the same type (showed by quantity).

For each line in Orders Table there is at least one line in OrderDetails (for the case when
one order consist only one product). If an order has lets say 5 products, then you will have 5
lines representing those products/articles in OrderDetails Table.

Each article/product is uniquely identified by the unique number of order + the article
number (in that particular order). Articles are associated with orders by order_nr (which is
associated with order_nr from Orders). Even more each article from an order has the prod_id
which associates with that article with the product in Products Table.

Column Description

order_nr Order unique number (associated with order_nr


from Orders Table)
article_number Article number (to be able to uniquely identify each
article on an order)
prod_id Products unique identifier (associated with prod_id
from Products Table)
quantity Ordered articles quantity
total_article_price Product price multiplied with quantity.

To do list:
1. Create the 5 tables above;
2. Populate each of those tables with at least 4 rows/records.
3. Create a new database;
4. Create two tables in your newly created database;
5. Delete one of your newly created tables at 4;
6. Delete the database you created at 3; (Do not delete the database containg those 5 tables)
7. Show Buyers structure;
8. Rename column buyer_state to buyer_sector in Buyers Table;
9. Delete column buyer_sector din Buyers Table;
10. Show the most expensive 3 products from Products Table;
11. Show products that cost more than 4 and less than 7;
12. Show products that contain XXXX in their description. (use Products Table);
13. Show prod_id and prod_name from Products where seller_country is Romania.
14. Show seller_name, prod_name, prod_price for sellers from Romania.
15. Show buyer_id, buyer_name, prod_id, prod_name si total_article_price for order_nr =X.

You might also like