19
Database Systems
October 17, 2016
Contents
I. Database System Overview 3
1. Context 3
2. Database System Goals and Objectives Statement 4
3. How the proposed Database System addresses the Business Problems? 4
4. How the Proposed Systems aligns to the Mission Statement and Strategic Goals of the Organization? 5
5. Mission and Goals of the Retail Store 6
6. Conclusion 7
II. Entity Relationship Model 8
1. Relational Database Proposal for online Retail Shop 8
2. ER Model and Relational Model 9
3. Converting ER Diagram to Relational Model 14
4. ER Tables Normalization 17
III. Structured Query Language (SQL) Scripts 18
IV. Database Administration Plan 19
V. Future Database System Implementation Plan 20
VI. References 21
Database System Overview
Database management systems or DBMS is a technology of retrieving and storing users’ data with utmost efficiency and appropriate security measures. The retail store Company is experiencing increased growth in the recent weeks. The customers expressed their interest in purchasing their products electronically. The Company’s website is simple, but it is not clear, if the Company,is in a position, of receiving online purchases. The Company aims at eventually integrating to online purchasingusing the current order entry system. This research project gives a description of the general business environment of the retail store Company. Referencing database objectives, statements, and system goals. Included is a narrative discussing how the proposed DBS addresses the current organization problem.
Context
Development of the retail store online could provide a lucrative alternative increase in sales by attracting customers, meeting the needs of the organization, and market expansion. However, conducting an online retail store creates some environmental considerations. The general business environment defines the external and internal factors that influence the Company’s operating situation. The business environment includes suppliers, clients, competitors, technology, government activities, and laws.(Elmasri & Navathe, Fundamentals of Fourth Edition Database Systems, 2005)
Database System Goals and Objectives Statement
Objectives and goals define what the database project will accomplish or the value of the database project to the business. Database designers should keep in mind six aims during the design of any database system. First, provide a mass storage of the relevant data. Second, protect data from unauthorized access. Such as, in the current database system of the retail store, allows promotional, and discountsof products, when not authorized. Third, the database system must aim at allowing growth. Some of the orders in the retail store, is not available, when required. Fourth, data systems should aim at making access of the order, easy access to the users of the system. Fifth, a database system should eliminate redundant data and allow many users to access to the database simultaneously. ...
1. 19
Database Systems
October 17, 2016
Contents
I. Database System Overview 3
1. Context 3
2. Database System Goals and Objectives Statement 4
3. How the proposed Database System addresses the Business
Problems? 4
4. How the Proposed Systems aligns to the Mission Statement
and Strategic Goals of the Organization? 5
5. Mission and Goals of the Retail Store 6
6. Conclusion 7
II. Entity Relationship Model 8
1. Relational Database Proposal for online Retail Shop 8
2. ER Model and Relational Model 9
3. Converting ER Diagram to Relational Model 14
4. ER Tables Normalization 17
III. Structured Query Language (SQL) Scripts 18
IV. Database Administration Plan 19
V. Future Database System Implementation Plan 20
VI. References 21
Database System Overview
Database management systems or DBMS is a technology of
retrieving and storing users’ data with utmost efficiency and
2. appropriate security measures. The retail store Company is
experiencing increased growth in the recent weeks. The
customers expressed their interest in purchasing their products
electronically. The Company’s website is simple, but it is not
clear, if the Company,is in a position, of receiving online
purchases. The Company aims at eventually integrating to
online purchasingusing the current order entry system. This
research project gives a description of the general business
environment of the retail store Company. Referencing database
objectives, statements, and system goals. Included is a narrative
discussing how the proposed DBS addresses the current
organization problem.
Context
Development of the retail store online could provide a lucrative
alternative increase in sales by attracting customers, meeting
the needs of the organization, and market expansion. However,
conducting an online retail store creates some environmental
considerations. The general business environment defines the
external and internal factors that influence the Company’s
operating situation. The business environment includes
suppliers, clients, competitors, technology, government
activities, and laws.(Elmasri & Navathe, Fundamentals of
Fourth Edition Database Systems, 2005)
Database System Goals and Objectives Statement
Objectives and goals define what the database project will
accomplish or the value of the database project to the business.
Database designers should keep in mind six aims during the
design of any database system. First, provide a mass storage of
the relevant data. Second, protect data from unauthorized
access. Such as, in the current database system of the retail
store, allows promotional, and discountsof products, when not
3. authorized. Third, the database system must aim at allowing
growth. Some of the orders in the retail store, is not available,
when required. Fourth, data systems should aim at making
access of the order, easy access to the users of the system.
Fifth, a database system should eliminate redundant data and
allow many users to access to the database simultaneously.
Sixth, a database system should make the latest modifications to
the database available immediately.(Rob & Coronel, 2002)
How the proposed Database System addresses the Business
Problems?
The retail shop scenario explains that the employees rely greatly
on paper-based sales and invoices. The Company needs to
consider the time that is wasted on tasks that database systems
can handle at an instant. The same also, goes to the financial
reporting mechanism that is currently being employed by the
Company. Currently the retail company takes ages to reconcile
and consolidate financial data; a database system can make an
important impact. (Elmasri & Navathe, Fundamentals of Fourth
Edition Database Systems, 2005)
The retail company is growing significantly in the recent
months; one of the biggest challenges faced by the retail
company is inventory management. Ensuring that the right order
is in the right customer at the right time is a vital for the
organization operations. In addition, when sales, customer data,
and inventory is maintained separately, the current view of the
retail store, can create serious problems in the Company. If the
Company runs out of a popular product, the sales will be off,
until the next shipment arrives. In addition, if a consumer, or a
customer, makes an inquiry about their order, and the
employees are unable to track, if the order is being shipped, or
if it is in the company’s current inventory, the retail company,
will develop a bad reputation, for customer service, and
reliability. Database systems help in tracking orders and
answers, customers’ questions; with ease and gives the exact
4. shipping status of the order. (Elmasri & Navathe, Fundamentals
of Fourth Edition Database Systems, 2005)
How the Proposed Systems aligns to the Mission Statement and
Strategic Goals of the Organization?
The proposed system defines the components, rules, the
roadmap that governsEnterprise Resource Planning (ERP)
utilization, and deployment. The proposed system takes into
account the mission of the company, the organizational goals,
and the strategies of the retail Company. First, the proposed
system enables the standardization of the Companies’ process
and the use of the best practices. Second, the proposed will
provide the necessary information, which is readily available
for decision making, for performing individual tasks, and
planning. Third, the proposed system will enable data
management, better handling of master data, definition of
information, and transactional data. In addition, the proposed
system, will result the retail company, to be more efficient,
positive customer service, governmental compliance, and
minimized operational costs.(Dittrich & Geppert, 2001)
The prosed system is business intelligence based, this will help
in analyzing data, and decision making. The best feature of the
proposed system, is that all data and information, is kept by the
company, which includes the central repository, or the data is
saved, in a single database. This helps in answering all the
questions posed by a customer,resulting in
delivering,outstanding customer service. In conclusion, the
proposed system assists in improved security and availability of
data, better information transparency, better harmonization of
all the IT infrastructure, high quality of organizational
processes, better information quality, and transparency.(Dittrich
& Geppert, 2001)
Mission and Goals of the Retail Store
5. The mission of the retail store company is to work together and
employ current technology in an online database infrastructure,
lowering the cost of production of the organization, and achieve
an increased profit margin. In order, to full fill this mission the
retail shop will work on the unique procedures that have an
open door policy, all the managers in the retail company, are
open to collaboration of all the employees, at all levels and
answering, customers, and supplier questions, on a daily basis.
The goals of the retail store company comprise of the following:
First, the system should not allow discounts and promotional
products. Second, the orders must be available for customers
and the customer service platform should be effective. Third,
the orders must not be misdirected. Fourth, the current database,
must be up to date, with the current stock, and inventory. Fifth,
the online platform must include credit processing, discount
offers, shipping options, and purchasing. Lastly, the system
must provide high security to both the customer’s data and the
organization’s sensitive information. (Robinson & Robinson,
2005)
Conclusion
The proposed systems have revolutionized organizations and
Companies around the globe. An example, is Wal-Mart stores
have relied heavily on online stores and ERP systems to carry
out its daily activities. This has made the company harvest
increased profits in recent years. This research project includes
discussion of the database system objectives statement and
goals. Including the needed goals for the proposed system. In
part two, I was able to show how the proposed system will
address some of the business problems. In conclusion,analysis
of how the proposed system aligns the strategic goals of the
organization and identification of the mission and the goals of
the organization. With these four parts, a description of a
general business environment for the presented case study.
Entity Relationship Model
6. Relational Database Proposal for online Retail Shop
The retail company will offer products online because of
customer demand. The company has faced many challenges in
the recent past which have made operations very inefficient.
The current system in use has no documentation which does
show a system blueprint for errors, corrections, or even any
attempts, to improve the system. Customer orders get lost,
products in the inventoryare out of stock, and customer tracking
is often difficult. Also,customers are often awarded promotional
goods and discounts undeservingly. There is a need to install
controls to curb this abuse of the system. The proposed database
system will ensure all organizational operations is
accomplishedefficiently.
ER Model and Relational Model
The diagram below presents a recommended relational database
that the company should use. The design takes into account the
challenges of the retail store.
Figure 1: ER Diagram
Entity-Relationship model is a high-level description of thedata
model. It is utilized extensively in conceptual designing of
relational schema databases. The requirements of a database
developed are usually laid down in a top-down
structure.(Elmasri & Navathe, Data Modeling Using the Entity
Relationship (ER) Model, 2011)
ER diagrams are the diagrams drawn using the standard. Entities
7. are represented as points, or polygons, and relationships are
shown using lines that connect entities. From an ER diagram, it
is easy to obtain a relational table, aiding in optimizing designs,
and in debugging systems. From the case scenario, various
entities were identified that need implementation,in reference to
problems faced within the current system. (Teory, 2011)
These entities are as follows:
1. Customer – this entity refers to anyone who makes an order
on the company’s website. Roles of a customer include checking
out products through theorder. This entity relates to order and
discount relations as every customer makes an order. A client
must at least make an order in a view to qualify for thediscount.
This is a control measure put in place to curb unwarranted
discounts to undeserving clients.(Teory, 2011)
2. Order – it represents a single transaction when a customer
purchases items. This order relates to the store, by checking the
availability of the product in question.(Teory, 2011)
3. Product - represents individual item that the company offers
to its customers.
4. Inventory – represents different types of reports generated in
combination with other entities. These reports include cost of
stocks, inventory per items, inventory total’s, amongst other
many reports.(Teory, 2011)
5. Store – this is the actual storage place where products are
stored and customers can get them from.
6. Employee –this is an entity that represents a person that
supervises all operations of the online store. Employee entity
relates to many other tables like the approving discounts on
discount relation, processing orders, etc.
7. Discounts – this is an entity for providing an extra service or
product to the customer.
8. Constraints – different types of constraints that have to be
implemented to ensure optimum performance of the database.
(Teory, 2011)
Entity integrity constraintsensures that the primary key field
cannot be NULL. It is because a primary key field, is used to
8. uniquely,to identify a record, and having no value, in this field,
means that we cannot identify, some tuples in a relation.
(Elmasri & Navathe, Data Modeling Using the Entity
Relationship (ER) Model, 2011)
We also, have the primary and unique key constraint. It is a
norm, to have an attribute that identifies, every entity in a table.
Such an attribute is referred to as akey attribute. In some
instances, more than one attribute may be used to form the key
attribute. When this happens, we refer to the key as composite.
This key needs to be minimal as much as possible, but has to
contain all attributes that will express, theexplicit uniqueness of
an entity.(Elmasri & Navathe, Data Modeling Using the Entity
Relationship (ER) Model, 2011)
According to Graves,referential integrity constraint is used,
whenever, there are two relations, and its prime purpose, is to
uphold consistency, in the tuples, of the relating tables. It is
basically defined, as a tuple in one relation that relating to a
tuple, in another relation. It just means, having a foreign key,
which references a primary key, in another relation.(Graves,
2002)
Finally, there are check constraints, which help define, the valid
data, whenever, we are adding, or updating data, in a relational
database. A check constraint, must be a predicate, and has to be
applied, in each tuple. It must be able to refer either to a single
or many columns of a relation. The output we get from check
constraint, is either TRUE, FALSE or even UNKNOWN. The
outcome is dependent on the NULL values present in a tuple.
(Graves, 2002)
The last set of constraints we need to use are the business rules.
These are the constraints that we cannot express directly in data
models but have to be enforced by application programs.
(Silverston, 2013)
Some of those rules which must be implemented are as
follows:A customer must place one order with a view to qualify
9. for a discount or promotional product.One and only one product
belongs to one category.Aclient can make many orders.An order
can have more than one discount since each order has many
products.One employee can process many orders.One or many
employees can manage many stores.Each customer discount can
have many products.Only one employee can serve one customer,
with many discounts; since a customer can place an order with
many products.Only one product entry is found in an inventory.
(Silverston, 2013)
Looking at the diagrammatic representation above, we have
tried to represent these rules on every table relation, even
though each, and every one, has to be implemented,at the
application level.
Converting ER Diagram to Relational Model
A good ER diagram allows us to derive relational tables
efficiently. From the ER above, this section presents detailed
models of the tables including the data types, description of
each field, and their relationships.
Customers table
Field
Description
CustomerId[PK]
Integer value and auto generated
FirstName
128-letter character string
SecondName
PhoneNo
10-digit character string ranging from 0 to 9
Email
128-letter character string
City
10. 50 character string ranging from A to Z
Candidate keys: FirstName, econdName, PhoneNo, Email,
Employee Table
Field
Description
EmployeeId[PK]
Integer value and auto generated
EmployeeName
128-letter character string
Position
50-letter character string
SSN
character string ranging from 0 to 9
PhoneNo
10-digit character string ranging from 0 to 9
Email
128-letter character string
City
50 character string ranging from A to Z
Order
Field
Description
OrderId
Primary key Auto-generated integer
EmployeeId[FK]
Integer value referencing employees table
CustomerID [FK]
Integer value referencing Customers table
ProductId
Integer value referencing products table
Orderdate
Date over which order was made
Quantity
Integer digit describing number of items bought
TotalCost
11. Double number with a two digit precision(Currency)
City
50 character string ranging from A to Z
Candidate keys are:OrderId, CustomerId, productId
Filed to index is OrderId
Product Table
Field
Description
Id
Primary key Auto-generated integer for identifying the product
Name
128-letter character string
categoryId
Integer value referencing product Category table
Price
Double digit number with precision of two digits
Description
1000-letter character string describing each product
Inventory table
Field
Description
InventoryId
Primary key Auto-generated integer
EmployeeId
Integer foreign key to employees table
StoreId
Integer foreign key referencing Stores table
ProductId
Integer foreign key referencing products table
Quantity
Integer digit describing number of items in stock
Description
1000-letter character string describing each product
Candidate keys are:StoreID, ProductID
Filed to index is: StoreID, ProductID
12. Discount table
Field
Description
DiscountID
Primary key Auto-generated integer value
CustomerId
Integer foreign key to Customers table
EmployeeID
Integer foreign key to employees table
OrderId
Integer foreign key referencing orders table
Description
1000-letter character string describing each Discount
Category table
Field
Description
CategoryId
Primary key Auto-generated integer value
CategoryName
128-letter character string
Description
1000-letter character string describing each Discount
Store Table
Field
Description
StoreId
Primary key Auto-generated integer value
StoreName
128-letter character string
Candidate key:StoreId
Field to index:StoreId
13. ER Tables Normalization
Normalization is a process that is usually used to ensure
database design achieves minimal data redundancy and
providing sensible data dependencies. The databaseis associated
with operations like insertion, deletion, updating. Without
proper normalization, these tasksbecome difficult to perform
and may lead to data loss at times. And when not the case, the
database becomes very redundant. Harrington and Harrington,
explains how normalization is achieved using the forms; 1NF,
2NF, 4NF and the 4NF. (Harrington, 2009)
To satisfy 1NF form, duplicative columns must be eliminated on
a table. In a case where there are such repeating columns, then
the table is broken down, into two, so that each column,can
hold, an atomic value. The rows must have unique columns.
Looking at our design of the retail store database, all the tables
satisfies this condition. For example, if we look at the product
table in the diagram ERabove, all the fields are dependent on
the primary key field, Id. If we try to add two or three rows of
data to our table, we will realize that there is not duplication.
We can, therefore, say that our design satisfies 1NF of
normalization forms. The 2NF forms require that a database
must meet 1NF conditions and then all the subsets of multiple
rows be removed, and placed on separate tables. In the 3NF, all
fields that do not depend on the primary key field are removed
to form new table. The above design has satisfied all these
conditions. For instance, there are relationships defined, for
each table, as well as, the keys relating them. (Silverston,
2013)Structured Query Language (SQL) Scripts
Database Administration Plan
Future Database System Implementation Plan
21. USE storemanager
GO
--CHECK TO SEE IF TABLE EXISTS AND IF SO, DROP AND
RECREATE TABLE
IF EXISTS(SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_NAME = 'Crosstab')
DROP TABLE Crosstab
GO
--CREATE TABLE FOR DEMONSTRATION PURPOSES
CREATE TABLE Crosstab
( Year SMALLINT,
Quarter TINYINT,
Amount DECIMAL(2,1) )
GO
22. INSERT INTO Crosstab VALUES (2010, 1, 1.1)
INSERT INTO Crosstab VALUES (2010, 2, 1.2)
INSERT INTO Crosstab VALUES (2010, 3, 1.3)
INSERT INTO Crosstab VALUES (2010, 4, 1.4)
INSERT INTO Crosstab VALUES (2011, 1, 2.1)
INSERT INTO Crosstab VALUES (2011, 2, 2.2)
INSERT INTO Crosstab VALUES (2011, 3, 2.3)
INSERT INTO Crosstab VALUES (2011, 4, 2.4)
GO
--SELECT the SUM of each quarter, grouped by year:
SELECT Year,
SUM(CASE Quarter WHEN 1 THEN Amount ELSE 0 END)
AS Q1,
SUM(CASE Quarter WHEN 2 THEN Amount ELSE 0 END)
AS Q2,
SUM(CASE Quarter WHEN 3 THEN Amount ELSE 0 END)
23. AS Q3,
SUM(CASE Quarter WHEN 4 THEN Amount ELSE 0 END)
AS Q4
FROM storemanager.dbo.Crosstab
GROUP BY Year
GO
U3_Worked_Examples/DDL.pdf
1C:UsersMarcelloDropboxCourse ...Course
MaterialsWorked ExamplesDDL.sql
USE master
GO
--CHECK TO SEE IF DATABASE EXISTS AND IF SO, DROP
AND RECREATE DATABASE
IF EXISTS(SELECT name FROM sys.databases
WHERE name = 'storemanager')
DROP DATABASE storemanager
GO
CREATE DATABASE [storemanager]
GO
--SWITCH TO DATABASE
USE storemanager
--CREATE TABLES
CREATE TABLE tblStores
(
StoreID char(10) NOT NULL PRIMARY KEY,
24. StoreName varchar(25) NOT NULL,
StoreAddress1 char(35),
StoreAddress2 char(35),
StoreCity varchar(20),
StoreState char(2),
StoreZip char(10)
)
CREATE TABLE tblDepartments
(
DeptID char(10) NOT NULL PRIMARY KEY,
DeptName varchar(20) NOT NULL,
StoreID char(10) FOREIGN KEY REFERENCES
tblStores(StoreID)
)
U3_Worked_Examples/DDL.sql
USE master
GO
--CHECK TO SEE IF DATABASE EXISTS AND IF SO, DROP
AND RECREATE DATABASE
IF EXISTS(SELECT name FROM sys.databases
WHERE name = 'storemanager')
DROP DATABASE storemanager
GO
25. CREATE DATABASE [storemanager]
GO
--SWITCH TO DATABASE
USE storemanager
--CREATE TABLES
CREATE TABLE tblStores
(
StoreID char(10) NOT NULL PRIMARY KEY,
StoreName varchar(25) NOT NULL,
StoreAddress1 char(35),
StoreAddress2 char(35),
StoreCity varchar(20),
StoreState char(2),
StoreZip char(10)
)
26. CREATE TABLE tblDepartments
(
DeptID char(10) NOT NULL PRIMARY KEY,
DeptName varchar(20) NOT NULL,
StoreID char(10) FOREIGN KEY REFERENCES
tblStores(StoreID)
)
U3_Worked_Examples/DELETE UPDATE SQL.pdf
1C:UsersMarcelloDropboxCourse ...MaterialsWorked
ExamplesDELETE UPDATE.sql
--switch to the correct database
USE storemanager
GO
--update store city in tblstores based on StoreID
UPDATE tblStores
SET StoreCity = 'Hampton'
WHERE StoreID = '1005'
--To delete a parent record in which there is one or more related
child records, the child
records
--must be deleted first before the parent
--delete department associated with store that needs to be
deleted from tblstores based on
27. StoreID
BEGIN TRAN
DELETE FROM tblDepartments
where StoreID = '1000'
COMMIT TRAN;
--delete store from tblstores based on StoreID (USING A
TRANSACTION WITH ERROR HANDLER)
BEGIN TRAN
DELETE FROM tblStores
where StoreID = '1001'
IF (@@ERROR <> 0) BEGIN
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
END
COMMIT TRAN
U3_Worked_Examples/DELETE UPDATE.sql
--switch to the correct database
USE storemanager
GO
--update store city in tblstores based on StoreID
UPDATE tblStores
SET StoreCity = 'Hampton'
WHERE StoreID = '1005'
28. --To delete a parent record in which there is one or more related
child records, the child records
--must be deleted first before the parent
--delete department associated with store that needs to be
deleted from tblstores based on StoreID
BEGIN TRAN
DELETE FROM tblDepartments
where StoreID = '1000'
COMMIT TRAN;
--delete store from tblstores based on StoreID (USING A
TRANSACTION WITH ERROR HANDLER)
BEGIN TRAN
DELETE FROM tblStores
where StoreID = '1001'
29. IF (@@ERROR <> 0) BEGIN
PRINT 'Unexpected error occurred!'
ROLLBACK TRAN
END
COMMIT TRAN
U3_Worked_Examples/DML.pdf
1C:UsersMarcelloDropboxCourse ...Course
MaterialsWorked ExamplesDML.sql
--SWITCH TO DATABASE
USE storemanager
--INSERT RECORDS IN THE CORRECT ORDER, BASED ON
DEPENDENCIES (PARENT BEFORE CHILD)
30. INSERT INTO tblStores
VALUES ('1000','ABC Company', '100 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblStores
VALUES ('1001','XYZ Company', '8 Oak Street', '',
'Hampton','NJ','08827')
INSERT INTO tblStores
VALUES ('1002','John West Ltd.', '110 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblStores
VALUES ('1003','Jacobs Store', '52 Lexal Ave.', '', 'Loch
Sheldrake','NY','12759')
INSERT INTO tblStores
VALUES ('1004','Harris Store', '10 South Blvd.', '',
'Newburgh','NY','12437')
INSERT INTO tblStores
VALUES ('1005','Johnson Company', '50 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblDepartments
VALUES ('10','Accounting', '1000')
INSERT INTO tblDepartments
VALUES ('11','Human Resources', '1000')
INSERT INTO tblDepartments
VALUES ('12','Shipping', '1001')
INSERT INTO tblDepartments
VALUES ('13','Accounting', '1002')
INSERT INTO tblDepartments
VALUES ('14','Human Resources', '1003')
INSERT INTO tblDepartments
VALUES ('15','Shipping', '1004')
U3_Worked_Examples/DML.sql
31. --SWITCH TO DATABASE
USE storemanager
--INSERT RECORDS IN THE CORRECT ORDER, BASED ON
DEPENDENCIES (PARENT BEFORE CHILD)
INSERT INTO tblStores
VALUES ('1000','ABC Company', '100 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblStores
VALUES ('1001','XYZ Company', '8 Oak Street', '',
'Hampton','NJ','08827')
INSERT INTO tblStores
VALUES ('1002','John West Ltd.', '110 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblStores
VALUES ('1003','Jacobs Store', '52 Lexal Ave.', '', 'Loch
Sheldrake','NY','12759')
INSERT INTO tblStores
VALUES ('1004','Harris Store', '10 South Blvd.', '',
'Newburgh','NY','12437')
32. INSERT INTO tblStores
VALUES ('1005','Johnson Company', '50 Main Street', '',
'Clinton','NJ','08809')
INSERT INTO tblDepartments
VALUES ('10','Accounting', '1000')
INSERT INTO tblDepartments
VALUES ('11','Human Resources', '1000')
INSERT INTO tblDepartments
VALUES ('12','Shipping', '1001')
INSERT INTO tblDepartments
VALUES ('13','Accounting', '1002')
INSERT INTO tblDepartments
VALUES ('14','Human Resources', '1003')
INSERT INTO tblDepartments
VALUES ('15','Shipping', '1004')
U3_Worked_Examples/REPORT SELECT.pdf
1C:UsersMarcelloDropboxCourse ...Worked
ExamplesREPORT SELECT.sql
33. 1
2 USE storemanager
3
4 --SELECT ALL STORES AND THEIR RELATED
DEPARTMENTS
5 SELECT tblStores.storeID, StoreName, DeptName
6 FROM tblStores
7 INNER JOIN tblDepartments
8 on tblStores.storeID = tblDepartments.storeID
9
10 --SELECT A STORE AND ITS RELATED DEPARTMENTS
11 SELECT tblStores.storeID, StoreName, DeptName
12 FROM tblStores
13 INNER JOIN tblDepartments
14 on tblStores.storeID = tblDepartments.storeID
15 WHERE tblStores.StoreName = 'ABC Company'
16
17 --AGGREGATE QUERY SHOWING TOTAL COUNT OF
DEPARTMENTS PER STORE
18
19 SELECT StoreID, COUNT(DeptID) as "Number of
Departments"
20 FROM tblDepartments
21 GROUP BY StoreID
22
23
U3_Worked_Examples/Thumbs.db
COMPANY SCENARIO
A retail store wants to offer its products online in response to
numerous customers requesting to be able to purchase the
34. company’s products electronically. The company is beginning to
see some growth in spite of the recent economic downturn. The
company strives to meet the needs of its customers, including
giving them the perception that they are the company’s highest
priority. Being a profitable operation has not always been the
case, and the company has historically struggled with customer
service issues, inventory-management problems, employee
turnover, and poor productivity overall. Naturally, the
stakeholders of the company began to lose faith in the viability
of the company, and unfortunately, numerous stakeholders have
dissolved their relationship with the retail store entirely.
Approximately 7 years ago, the company hired a freelance
information technology (IT) organization to create a data-driven
information system that would support customer records and
order entry. The store manager convinced the owner of the
company that this route was the way to go. After all, anything
would be an improvement over what the company had at the
time. The owner felt that because it was important to have an
efficient way to track customers and orders, any computerized
system would be sufficient. He was not too proud to share his
lack of technological skills, and often deferred to others when it
came to making decisions in this area. He often joked that
perhaps some computer training would do him and his
employees some good. He was never really assured that his data
were backed up correctly or that his system was secure. And
what if the system crashed or the data started to appear unusual?
He also had never heard of any of his employees backing up the
system files. If he lost all of his data, he would not know where
to turn or what to do. The very idea of his business depending
so much on technology was almost too stressful to think about.
Deep down, however, he really wanted some assurance that his
information was reliable and secure.
The customer records and order entry system that was installed
solved a few problems for the short term but quickly proved to
lack the capability to meet the goals, objectives, and overall
data needs of the company. The freelance technology company
35. provided no documentation on how to use the system or even
how it was designed. A large component that was missing was
having the ability to track the product inventory. The system in
its current state does not seem to be fully functional and often
lets employees override the store procedures that the owner has
clearly stated should be adhered to. For example, customers are
given discounts when they are not eligible, certain products are
completely depleted from inventory without being flagged for
reorder, and prospects who have never placed an order are set
up as customers with a fake order to give them free product
samples and promotional materials. This usually involves a
person who is friends with an employee collaborating to set up
fake order for a product that is not even real.
Although the owner does not feel that he is very technically
proficient, he admits that perhaps he should have researched the
needs of his company and the possible options before jumping
on the first opportunity that presented itself. He knows that he
reacted to the problem instead of responding in an effective
manner. After all of that trouble, employees cannot keep track
of customer records, orders get misplaced on the system, and
products that are not in inventory keep coming up as available.
The problem has gotten so bad that the owner has directed all
employees to resort back to the manual method to handle all
daily business transactions.
At this point in the company’s history, the need for positive
changes is apparent to the owner. He is committed to his
company and his customers. He values all of the input that
stakeholders have provided to him over the years and knows
that with a little determination, the company can be a success.
His employees are loyal to him and appreciate his attentiveness
to their needs and concerns. He knows that each employee is
good at solving problems and wants to able to reward all of
them by recognizing when they are able to solve problems for
the company. He sees his employees as dedicated and capable of
meeting any of the goals and objectives that he sets for them.
He often compliments them on the cleanliness of the store and
36. the way that the shelves are organized. He has told them that the
company takes pride in its appearance and ability to greet the
customer with a smile. This includes having the products that
the customer wants at a reasonable price; that is what he
calls customer service.
Perspectives:
Kelly, Customer Service Representative
“Every time customers call me and want to know the status of
their order, I feel like it takes forever for the system to provide
a simple answer to a simple question. I can understand why
customers get frustrated with us because all they want is to
know what is going on with their order. After all, they are
trying to coordinate their busy lives and such. I feel like an
idiot when I cannot answer the customer right away, and I am
upset because I thought this system would make things better. I
feel like I spend more time listening to customers complain, and
it makes me uncomfortable.”
Mark, Cashier
“I don’t understand why I can’t simply give the customers a
break sometimes. I know they should not get a discount all the
time, but if I know them, I think it is good customer service to
make them happy. Plus, the system allows me to do it. If this
was such a bad thing, then the system should not allow me to
give discounts and promotional products when I am not
supposed to.”
Sandy, Product Manager
“This new system was supposed to help me manage product
inventory more efficiently but it isn’t. I do not have time to go
back into the warehouse and count everything. I told customers
that we had plenty of stock, and we actually had none in the
warehouse, so naturally the customers are really angry with me.
But it is not my fault. The system told a different story, and I
relied on the system to be right. Now the owner is mad at me
because he thinks I am not capable of doing my job. He says I
should always check to make sure that the system is not lying,
but I don’t have the time to do this!”
37. Ralph, Store Manager
“I really thought a new system was the way to go; after all,
technology is supposed to solve all problems, right? Why can’t
things just work? The owner is really upset because we spend so
much time trying to fix problems that occur on a daily basis that
we do not have time to make things better in the store. At this
point, we will never be able to sell our products online. We
cannot even manage the store we have! Orders get misplaced,
customers are angry because the wrong products come in on
their orders, and I am really tired. I just don’t understand it. I
have seen technology actually help businesses run more
smoothly. Why does technology not work for us?”
Ellen, Customer
"I love the convenience of shopping online. With my busy
lifestyle, I have no time to go shopping at the store for what I
need. I do appreciate being treated with respect as a customer
too. After all, I should get the product I want at a fair price and
should have the ability to choose from a wide selection. I love
the websites that have customer support options so that I can
call if I have a problem. I will be honest, however, that I have
little patience for order mix-ups and things like that. A company
that sticks by its word, though, means a lot to me. We all make
mistakes; it's how we fix those mistakes that matters."