event session database design - database

to make an event session, how'd you define a relationship.
Event has days, days has sessions. Days will hold the number of rows depending upon the number of days.
Should I be making 3 Tables or more?
1) Event Table (id, name)
2) Day Table (id, date, event_id)
3) Session Table (id, name, start_time, end_time, day_id)
or something different, please advise.
one event has multiple days, and each day has multiple sessions.
Edit: (is this okay)
event
id name
1 event 1
2 event 2
-----
day
id date event_id
1 '2015-06-01' 1
2 '2015-06-02' 1
3 '2015-07-01' 2
4 '2015-07-02' 2
------
session
id name day_id
1 'session a' 1
2 'session b' 1
3 'session c' 2
4 'session d' 2
------

Related

databases - manage products part of products in business management software

in my company's business management software, I manage the products this way:
table products
id name part_of_id ...
1 license NULL
2 computer NULL
3 computer 2
4 keyboard 2
5 mouse 2
table customer_invoices
id ...
1
2
table customer_invoice_products
product_id invoice_id price ...
1 1 100
2 2 300
table supplier_invoices
id ...
1
2
table supplier_invoice_products
product_id invoice_id price ...
1 1 90
3 2 250
4 2 10
5 2 10
1st example, we buy 1 license from the supplier and sell it to the customer, everything is fine
2nd example, we buy 1 computer, 1 keyboard, 1 mouse from the supplier and sell them as 1 computer to the customer, the problems are if e.g. I need to search for all the products related to an order I have to query for all the products directly related to it (product id 1) and for all the products related to them (products id 2, 3 and 4)
apart from obviously selling the computer to the customer as 3 products, is there a better way to do this and what are best practices to manage this?

Database schema for product quantity

I have some issues with creating database schema for a following scenario:
Shop, where you configure your order. Let's say user orders flowers and chocolate. So far I had the following structure:
OrderID FK_Flower FK_Chocolate
1 1 1
Where FK's pointed to the entry in database such as:
Id Name Price
1 Rose 100
The same for chocolate.
However now, there is a change: use can order multiple different flowers. So let's say, he can order 5 Roses, 3 Daisies.
What changes should I make, to solve this issue?
You want a many-to-many relationship.
Change the Orders table to something like this:
Orders:
-------
Id
1
The Flowers table stays the same:
Flowers:
------------------
Id Name Price
1 Rose 100
2 Daisy 120
Create a new table with with the Order and Flower ID's as foreign keys:
Orders_Flowers:
-------------------------
FK_Order_Id FK_Flower_ID
1 1
1 1
1 1
1 1
1 1
1 2
1 2
1 2
This way, the Order with Id = 1, has 5 Roses and 3 Daisies.

Getting Expired Purchases And Associated Features

I am updating our in-house purchase system. While doing this, I had to move the service expiration date from the client table to the purchase table so each system could expire separately. I am trying to update the SQL statement to get systems that need to be billed, but am running into issues. Below is a simplified example of what I need:
Purchase Table
ID Product ClientID SystemID IsSystem ExpireDate
1 System1 12 1 1 9/22/2015
2 Feature1 12 1 0 NULL
3 Feature2 12 1 0 9/22/2016
4 System2 12 2 1 9/22/2016
5 Feature1 12 2 0 9/22/2015
6 Feature2 12 2 0 NULL
In the example above, I would need to get lines 1, 2 and 3. What I need to do is:
Look at each system to see if the ExpireDate is less than or equal to a given date (say today)
If it is, take all rows with a matching ClientID and SystemID reguardless of ExpireDate
Although line 5 would be expired, it would not get included because the system it is a part of has not expired.
This is getting inserted into a much larger SQL statement spanning several tables, but I should be able to extrapolate from an example with this table.
This is probably best accomplished using a common table expression that gets the expired client and systemIDs and then checks every row in your table against that list:
WITH expired AS
(
SELECT DISTINCT
ClientID,
SystemID
FROM purchase
WHERE
CONVERT(DATE, ExpireDate) <= CONVERT(DATE, GETDATE())
AND isSystem = 1
)
SELECT
*
FROM purchase p
WHERE
EXISTS (SELECT * FROM expired WHERE p.ClientId = ClientID AND p.SystemId = SystemId)

Oracle DB Table - To implement History,Audit and Versioning

I have three history tables as shown below for the corresponding main table and one audit table . The table are related with each other with primary key id in table.
com
-----
id - primary key
description
history_id
db_comm
--------
id - refers id in com
query
type
flag
history_id
comm_frm
-------
id - refers id in com
scope
status
seq
history_id
audit
------
history_id
version_id
created_dt
replaced_dt
ended_dt
userId
ipaddr
action
status
I have created history table(_history) for these three tables. For any change(insert/update/delete) in any one of these three tables
do i need to duplicate the rows in other table, even if there is no
change in that table.
for example
if the user has modified column query in comm table. then i will have following entry in these history tables.If you see here the com table is only changed ,but do we need to make a new entry in db_comm also.
com_history
id description history_id
1 loaded data 1
1 loaded 3
db_comm_history
id scope sequence history_id
1 G 1 2
1 G 1 4
audit
history_id version_id created_dt replaced_dt ended_dt userId ipaddr action status
1 1 sysdate sysdate sysdate xxx 192.1 Update INACTIVE
2 2 SYSDATE XXX 192.1 iNSERT ACTIVE
3 1 sysdate sysdate sysdate xxx 192.1 Update INACTIVE
4 2 SYSDATE XXX 192.1 iNSERT ACTIVE
how do i maintain same version(global version) in all the history tables for a change in one of the table.

Database design - tracking details per order from parent

I have a requirement where there are 3 tables (Orders, details & users)
OrderId OrderDesc UserId Timestamp
--------- ---------- --------- ---------------------
1 Pencils 1 02/08/2011 9:35 pm
2 Fruits 2 02/08/2011 8:44 am
Order Id DetailId DetailDesc UserId Timestamp
---------- ----------- ---------- ---------- -----------------
1 1 HB-1 2 04/09/2012 5:00 pm
1 2 HB-2 2 04/09/2012 5:00 pm
UserId UserName
-------- ---------
1 john
2 james
I want a user to enter details only for an order which has been entered into system,avoiding duplicates (I am thinking about converting an existing order to a detail in design view)
I want the user entering the orders 'john' to know about any details that may have been entered for a specific order he innitiated without introducing a field in my orders table or joining orders & details together
Thanks for any help, Damien.
To enter details for any orders that have been entered, you only allow the user to select orders that already exist either using drop downs or a checkbox
Your order details are already linked to the order by the Order Id field.

Resources