By Olivia Chan
The database for Survey SQL includes all entities necessary to facilitate the process of tracking manager's progress in following up client's response to our survey after making a purchase, and help managers to track the both the survey and corresponding transaction detail. As such, included in the database's scope is:
- Clients, including basic identifying information
- Transactions, including all transaction details
- Survey, including ratings, date and comments about the transactions
- Shop, which includes basic shop information
- Items, which includes items information
- Manager, including basic identifying information
- Advisor, including basic identifying information
- Log, which includes the managers feedback on the call and the follow-up status
Out of scope are elements like advisor's commission, item's discounts, and other non-core attributes.
This database will support:
- CRUD operations for all activities
- Tracking all client's transactions and surveys
Note that in this iteration, the system will not support altering clients information.
Entities are captured in SQLite tables with the following schema.
The database includes the following entities:
The customers table includes:
id, which specifies the unique ID for the customer as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.first_name, which specifies the client's first name asTEXT, givenTEXTis appropriate for name fields.last_name, which specifies the client's last name.TEXTis used for the same reason asfirst_name.phone, which specifies the client's phone number as anINTEGER.email, which specifies the client's email asTEXT, givenTEXTis appropriate for email fields.
All columns except email in the customers table are required and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The transactions table includes:
id, which specifies the unique ID for the transaction as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.date, which specifies the transaction date asDATE.item_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theitemtable to ensure data integrity.customer_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thecustomertable to ensure data integrity.advisor_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theadvisortable to ensure data integrity.payment_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thepaymenttable to ensure data integrity.survey_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thesurveytable to ensure data integrity.
The survey table includes:
id, which specifies the unique ID for the survey as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.date, which specifies the survey submission date asDATE.rating, which is anINTEGERspecifying the rating given by the client. Rating should not be less than 0 and the maximum rating is 10.comment, which is the comment leave by the client asTEXT.
All columns except comment in the survey table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The rating column has an additional constraint to check if its value is greater than 0 and less than or equal 10, given that this is the valid range for a rating score.
The shop table includes:
id, which specifies the unique ID for the shop as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.name, which is the name of the shop as anTEXT.location, which is the name of the shop location as anTEXT.
All columns in the shop table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The item table includes:
id, which specifies the unique ID for the item as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.name, which is the name of the item as anTEXT.price, which is the price of the item asNUMERIC.category, which is the item category as anTEXT.
All columns in the item table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The payment table includes:
id, which specifies the unique ID for the payment as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.type, which is the type of the payment like cash, visa, master,etc... as anTEXT.amount, which is the total amount swiped asNUMERIC.
All columns in the payment table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The manager table includes:
id, which specifies the unique ID for the manager as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.name, which is the name of the manager as anTEXT.title, which is the title of the manager as anTEXT.advisor_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theadvisortable to ensure data integrity.shop_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theshoptable to ensure data integrity.log_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in thelogtable to ensure data integrity.
All columns in the manager table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The advisor table includes:
id, which specifies the unique ID for the advisor as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.name, which is the name of the advisor as anTEXT.title, which is the title of the advisor as anTEXT.shop_idThis column thus has theFOREIGN KEYconstraint applied, referencing theidcolumn in theshoptable to ensure data integrity.
All columns in the advisor table are required, and hence should have the NOT NULL constraint applied. No other constraints are necessary.
The log table includes:
id, which specifies the unique ID for the log as anINTEGER. This column thus has thePRIMARY KEYconstraint applied.date, which specifies the date the client is being contacted asDATE.response, which is the manager response to the conversation asTEXT.followup_status, which specifies the progress. If client is being contacted, marked yes so this column is specified asTEXT.
The below entity relationship diagram describes the relationships among the entities in the database.
As detailed by the diagram:
- One client is capable of making 0 to many transactions.
- A transaction is associated with 0 and only 1 survey.
- A transaction is associated with 1 and only 1 shop, whereas a shop can have 1 to many transactions.
- A transaction is associated with 1 to many items, payements respectively.
- A transaction is associated with 1 advisor at a time, while an advisor can make 1 to many transactions.
- A shop is associated with 1 advisor and 1 manager to many advisor and many managers, while one manager is associated with one shop at a time and one advisor is associated with one shop at a time.
- A survey is associated with 1 and only 1 transaction, while a transaction can have no survey associated with or 1 survey related to the transaction.
- A log is written by one and only one manager, while the manager can write 0 to many log.
Per the typical queries in queries.sql, it is common for users of the database to access all logs follow up status by managers, as well as the advisor who corresponded to the transactions. Overall survey rating is of partiular concern as well. For that reason, indexes are created on the followup_status, name, and rating columns to speed up the searches by those columns.
The current schema assumes individual log submissions. In real-world case a client survey may follow up by several managers. Collaborative submissions would require a shift to a many-to-many relationship between managers and logs.
