r/DatabaseHelp • • May 27 '18

Asset Tracking + Accounting Design

1 Upvotes

So this started with some frustrations with a few different pieces of personal accounting software (Quicken, GNUCash, etc.). I'm completely paperless when it comes to receipts, but I want more functionality than split transactions and just attaching an image. By trade I work with some commercial software that handles assets, ROI, etc., but as a thought experiment I started to work on modeling a database that would do that for personal items. It's ending up being harder than I thought. Some examples:

  • "Products" are things that I can buy (cars, computer parts, paper...)
  • "Assets" are products that I personally own ('my' car, 'five' reams of paper...)
  • Some assets are unique and serialized ('this' Makita drill, S/N XYZ123)
  • Some assets are common and not serialized, and are therefore stockable ('6' plain white t-shirts, '3' cases of water)
  • Assets are acquired and lost via several means, such as Purchase, Gifts, Sale, and Donations. These events have different financial implications that I want to reflect and relate in bank transactions.
  • Bank transactions are purely financial, from some account to another account. Sometimes transactions are to purchase assets, but I also want to account for taxes, shipping, and other non-tangible transactions. Think 'split' transactions for Quicken that would detail out a mortgage payment in principal, interest, and escrow - except with the ability to tie to assets.

In my design approach, this has resulted in a mess of supertypes and subtypes to account for all the different kinds of documentation, invoicing, and asset events. For instance:

  • "Asset" is a supertype of "Unique Assets" and "Non-Unique Assets" (one has serial numbers, the other has a quantity that changes over time).
  • "Asset" relates to an "Acquisition", which is a supertype of different 'gain' events, such as Purchases, Gifts, Creations, etc.
  • Likewise, "Loss" is a supertype for Sales, Donations, Gifts Given, or other damages/EOL situations.
  • Purchases and Sales can relate to bank transactions; assets received as gifts don't relate to transactions; donations have tax implications, but don't necessarily relate to bank transactions.

These kinds of event supertypes were the only way I could think of relating the changes of Assets to events over time. That way, if I look up my Makita drill, the purchase details would be related to it (date, price, retailer), and the loss details would be recorded if I donated it to Vietnam Vets of America at a valuation of $30. For a non-unique item, like cases of water, the data I would want to get out of it would be how many I purchase throughout a year, and how much I've been paying for that item (or items of a similar category) over time. I'd also want to see that maybe I've been paying more for those items at one supermarket over another. That'd be the idea, anyway.

The reason I say this has become a thought experiment is because all the supertype/subtypes make me question my approach to normalizing data. I've found it difficult to track down a data model that fits this level of detail for personal use. Have a gone off the deep end here?


r/DatabaseHelp • • May 25 '18

Design theory question using MySQL

3 Upvotes

Thanks for all the wonderful help here!

I'm designing my first database and got stumped. I know I can do this several different ways but can't think clearly on which way is better/best.

I have three distributors product lists updated daily. Distributors A, B, and C sell widgets in 3 different colors and 3 sizes. Dist. A sells widgets 100/case, while Dist. B sells them 150/case, and Dist C sells them in 75, 100, and 150/case. Prices fluctuate daily. Widgets are the same but each distributor uses a different product code for the widgets.

Whats the best way to set up my DB so that I can make sure I get the best deal per widget for each individual color?

I could make a table that checks the price of each size/color combination on each of the distributors product list but since they use different codes for each widget I'm not sure the best way to handle this without a lot of manually entering data. (Think thousands of sizes and thousands of colors).


r/DatabaseHelp • • May 24 '18

Structuring DB for historical weather data

2 Upvotes

Say someone needed to create a(n SQL) DB to hold historical weather information for a list of cities cities (50 now, but would increase later). The db would have 5-6 weather data types (temperature, pressure, precip, high/low, and dew point, for example; no more added later). What is the proper way to do this?

I suspect you would first make a table with the cities. That I already have and am using to get the data I need. Storing the data I get is where the problem comes in. A new record for each city would be added daily. Does it all go in one gigantic table? Does each city in this example get its own table? I am really not sure what the best way to do this is. (And, no, this is not homework.)

I want to display specific or all data from all, groups, or specific cities. So like all temperatures from 12-12-12 or all temperatures from Anytown or all data from anytown. I would also like to take advantage of some basic math functions (average, min, max). A single table seems like it would make this hard to sort, but lots of tables seems really inefficient.

Apologies if this is confusing. I am not good with the databases when they are more complicated that single records for each subject.


r/DatabaseHelp • • May 22 '18

Database for a list of locations?

3 Upvotes

Hi there,

I am trying to make an open database of a list of locations. Think like restaurants. Each location would have name, address, XY coordinates, hours open, etc and I would like for it to be open and have a website that can display the information and people can help edit and add to it as well as an API people can use to access the info for their own usage.

So far from my reading I would use a Relational Database? Something like Amazon Aurora or MySQL. Am I right? Or should I be using something else


r/DatabaseHelp • • May 15 '18

How to Store Business Data

Thumbnail self.entrepreneur
1 Upvotes

r/DatabaseHelp • • May 09 '18

Need help designing a DB table. Need a column that auto increments and is guaranteed to never use the same integer

2 Upvotes

I'm sorry if my question is badly worded, but I just don't know the proper terminology to describe what I want in a title. Basically I'm trying to implement multiple queues in my application using postgres. Users can then sign up to multiple different queues and wait their turn for servicing. I have a Queues table that stores the queue id and other meta data, a Users table that stores a user id and user data, and a Queue_Users table that has columns queue_id, position, user_id.

I currently have the queue_id and position as a primary key and as an index. The reason being, I want to order the entries by queue, then by position, so it will be more efficient to find the order of the users in the queue. Here's where I'm having trouble since I basically have 1 constraint I'm having trouble implementing. For each entry added to the Queue_Users table, it should create an entry where the position is exactly +1 of the last entry added for THAT queue. So if a user queues up for a queue with ID = 2, and the last user added to queue with ID = 2 is at position 123, then the entry added should be queue_id = 2, position = 124. I need it to be guaranteed that the next number for position will always be +1 of the last value added for that queue so that I can just use the lowest position user to calculate the positions of the other users.

So ideally what it looks like is that I might have 5 queues, with id's 1, 2, 3, 4, 5. So if 3 users queue up for queue_id = 1, then it's last entry will have a value of 3 in it's position column, rest have 0. Now say queue_id = 4 gets 2 users queued up, then the value in it's position column has value of 2.

How do I create a table that implements the above requirements? Is it enough to declare queue_id and position as a composite primary key and have the position auto increment? Thanks.


r/DatabaseHelp • • May 04 '18

Looking for a solution to a problem at work (ODBC Related?)

1 Upvotes

Hi, so as an intro I am a report writer for a small business, we do not have a dba and any dba-type work is expected to be performed by myself or the IT guy. Neither of us really know much about dba.

Our problem: When I write complicated reports that involve a lot of calculations, subqueries, subreports, etc, the report gets very slow. I report directly out of our ERP database which we cannot modify in any way except through the software (so no creating tables, views, or changing the data in the tables themselves). Complicated reports end up loading very slow and what I would like to do is separate the report from the calculations. I want to be able to make new views with the information I need calculated as it goes live, then the report can be run out of that view.

Solution I'm looking at: I'm looking at setting up an ODBC connection to feed the data from our ERP database into a new database that I can manipulate and create views in and report out of that new database instead to improve report performance.

I also may want to feed data from multiple different databases (like our CRM (oracle), rental (access), and payroll databases) into this new database.

How complicated is setting up a whole new database and this ODBC connection and would it even work the way I think it would? Cost is also an issue because we are a small company and do not have the resources to throw tens of thousands of dollars into this.

Would we need to buy something like a SQL Server license? Is that hard to set up?

I am sorry if I am missing something obvious I have no experience in dba and all I really do with the database at work is write sql queries for reporting.

Thanks in advance!


r/DatabaseHelp • • May 04 '18

Shared Data Across Different but similar objects

1 Upvotes

At work I'm building a database to interface with [TestProgram.exe] The test program needs to call and store the following typedef struts in a database:

Part Objects:

  • Shared info
  • Product family (Nokia, Samsung, Honda)
  • Product Model (Lumia, Galaxy, Civic)
  • Parts (inherits Shared info)
  • Life cycle Stage ([Active/End of Life/Obsolete])
  • Tests needed to pass (Camera test, call home, start engine)
  • Generic Tests (inherits Shared info)
  • Test ID number (SHA 256 Hash)
  • Last modified (date)
  • [Other generic data]
  • Specific Test Type A (inherits Generic Tests)
  • [Specific Test criteria For Test Machine A]
  • A Machine G-Code (Non-searchable)
  • Specific Test Type B (inherits Generic Tests)
  • [Specific Test criteria For Test Machine B]
  • B Machine G-Code (Non-searchable)

User Object

  • Tester
  • Name
  • ID no
  • PW Hash

Test Report Object

  • Report ( inherits Parts, Tester, and Specific Test Type A or B)
  • Part Info
  • Test Date
  • Test Type
  • Tester.Name
  • Pass/Fail
  • Test Report (In binary .rtf)

  1. How can I make my database tables best take advantage of the fact that the majority of the data of Specific Test Type A and Specific Test Type B is shared?
  2. Parts and Specific Test Type A/Specific Test Type B have a many to many relationship what is the best way I can represent this while taking advantage of the fact Generic Tests class?

r/DatabaseHelp • • May 02 '18

Help with complicated Report.

2 Upvotes

I need help with a question in one of my papers.

Report that shows the number of males and females who attended classes from October to December 2017. It should be grouped by month, displaying the gender attendance in that month. The total attendance for each month and the attendance overall should also be displayed.

Anyone have any idea how I do this?


r/DatabaseHelp • • May 01 '18

[PostgreSQL] - Looking for feedback on database design for availability

Thumbnail self.sql
1 Upvotes

r/DatabaseHelp • • Apr 24 '18

Question about many to many relationships

1 Upvotes

So far I have two tables in a library system: BORROWER and BOOK

If a borrower returns a book late, he will have a fine he will need to pay, and the payment date is also recorded.

Given that not all borrowers will not have a fine, and that we want to avoid nulls, is it appropriate to have a FINE entity that defines the relationship between BORROWER and BOOK that is many to many (contains borrower_id and book_id as primary/foreign keys)?


r/DatabaseHelp • • Apr 23 '18

Help with normalization!

2 Upvotes

Hey,

I am trying to normalize a table and am not sure if I have it in 3NF or not, please help me out if you can.

https://imgur.com/a/SEIb9oI


r/DatabaseHelp • • Apr 17 '18

Database connection limit and multiple servers

2 Upvotes

Hello!

Databases have a maximum connection limit. You cannot open more than a certain number of simultaneous connections. You can tweak the number by changing the configuration, bringing it up or down, but the limit still exists.

Now, my question is the following. Say I have a DB which waximum connection limit is 50.

I then have my business servers, where the logic of my application relies, connecting to the db. Say that each db opens up a pool of 5 connections. Say that my app grows a lot and I need to turn the number of business servers up in order to be able to scale out to serve the requests.

Now let's forget about the fact the the real maximum limit may be lower because of reserved connections (like for mainteinance).

If I reach 10 server, each with a pool of 5 connections, I reach the maximum limit.

How does one deal with this? Again, sure I can increase the limit, but this doesn't seem the solution to me, as the problem is only mitigated but not solved.

Thanks


r/DatabaseHelp • • Apr 16 '18

Image gallery database.

1 Upvotes

I am seeking to create an image gallery and not quite sure if I should go with MySQL or MongoDB. The gallery should be structured kinda like mangapanda.com. Each gallery can have a varying number of images. None of the images will stored in the database, just partial URLs. I would assume MongoDB due to it being doc based and I can have a array field, but the larger the doc the worse the performance and some of these galleries may have an upwards of 100 images.

Now I have technically used both. SQL Oracle in college and NoSQL Firebase database and DynamoDB in work. (I found Oracle easy, but the NoSQL ones were pain in the ass to get to work.) But I am no expert in this and the pros and cons of SQL and NoSQL aren't all that helpful. So performance wise, which one should I pick?


r/DatabaseHelp • • Apr 14 '18

Retrieve data based on inequality

1 Upvotes

Hello Everyone, I'm sorry if the title wasn't clear enough

My question is: suppose we have the following tables

I'm using MS-ACCESS but any SQL flavor would suffice, How would I retrieve the PNAME, that weren't supplied by sname="jones"

Thank you in advance


r/DatabaseHelp • • Apr 14 '18

Best way to limit store 100 items per group, 1000 groups where data changes every few minutes

1 Upvotes

I apologize if this is a silly question but I am a novice in data storage. I am a setup involving several sensor devices sending me data every 15 mins. There are approx 1000 devices and I need to retain last 100 values of each device.

  • The last 2 readings always need to be updated whenever new data arrives and a new reading needs to be added per group, 1000 groups = 3000 rows at min
  • I need all the 100k rows to aggregate into higher timeframes (30m, 1h etc) every 15 minutes
  • What data storage mechanism should I use?

What I tried so far?

  • PostgresQL takes 11 seconds to push 100k rows every time but I am assuming this is not the true purpose of a database to do a full scan
  • Flat files do this in 0.8 seconds but the updating/inserting part with limits is giving me a headache

Any suggestions are super appreciated


r/DatabaseHelp • • Apr 11 '18

Suggestion on how to store registered courses for many students in a database.

1 Upvotes

I am looking for a suggestion on how to store a registered course(s) for each student in a database. The first idea I came up with didn't seem like a practical solution. For example, if I had 50 students I was thinking of just creating a table for each student to hold their course registration history. However, this doesn't seem like a good idea.

Here is a screenshot of the key tables that I would seems to be needed for that course history:

https://imgur.com/a/cCbBn


r/DatabaseHelp • • Apr 10 '18

Help with a Ternary Relationship

1 Upvotes

In the relationship shown below, any teacher can recommend any book to any class. How can I change it so each teacher can only recommend one book to any specific class and that book can only be from a unique list for each teacher.

For example, Mr. Phillips can only recommend Frankenstein XOR Dracula XOR Strange Case of Dr. Jekyl to a class while Ms. Morgan can only recommend Jane-Eyre XOR Wuthering Heights XOR Moby-Dick to a class. And how do I make it so each teacher can only make a recommendation to a specific class once. So Mr. Phillips can recommend Dracula to class 1 and Ms. Morgan can also recommend Moby-Dick to class 1 but she can't also recommend Wuthering Heights to class 1.

https://imgur.com/a/KYU1z


r/DatabaseHelp • • Apr 08 '18

Question on using two tables in php listing data in a specific order.

3 Upvotes

I am working on a project for my course to mimic a college website. Specifically, I have two tables I created for Faculty and Students. If I were to make another table called Advising/advisor I feel as though this might not work out correctly. For example,

Clelia Smyth (students with last names A-E)

Angela Kim ( students with last names F-L)

Nate Hibbitts (students with last names M-R)

Stephen Erena (students with last names S-Z)

So I have a few questions about this:

  1. Is there a way for me to order data alphabetically? Like if Clella Smyth log in they would be able to see the list of current students they are advising with the last names A-E.
  2. I am a concern with how I am constructing the table, if I were to make an advisor table do I just keep repeating the advisors name and connect to each student. For example:

Attributes: advisorID, faculty, student email, student last name, Department, Major

1 |Clella Smyth, | Alistor@example.com | Alistor English | English

2 | Clella Smyth | Simon@example.com | Simon Math | Math


r/DatabaseHelp • • Apr 08 '18

I'm hoping to create an online database that allows different organizations in my community to input information regarding their cause.

2 Upvotes

I realize this subreddit is geared more toward programming but is anyone aware of a website/service that would allow me to create a user-friendly database to collect and share information in a short amount of time? Thank you!


r/DatabaseHelp • • Apr 07 '18

How to transverse and reorganize/rebuild a mlm forced-matrix ?

1 Upvotes

What I need to do is start at the top, and move down the levels filling out the children and balancing the matrix...

So say we have user A at the top, and then the following users that are sponsored by A: B, C, D, E, F, I, J, K.

B, C, and D are paid members as are J and K.

Additionally B has 2 paid members of their own. G, H, I and 2 non-paid: L, M.

So we should have Something like this:

          A
        /   \ 
       B     C
      /  \    / \
     D   G   J   k
    / \  / \
   H  L I  M

Any extra members the top member gets would fill at the C side until it was balanced like the left as LONG as the paid members were ONLY being placed under paid members, else it would go back to the left, or place members above non-paid members forcing them down even further.

The schema looks like :

Matrix:

id:int,
userid:int, (references id on users)
sponsoruid:int, (references userid on matrix)
parentuid:int, (references userid on matrix)
datecreated:date
side:enum (left/right)

User: id ismember:bool

I need this to be something that can run perhaps daily or weekly on a cron w/out breaking things too badly and without locking the db for a whole day. Ideally a stored procedure using recursive CTE's seems like it may be the most performant way to do this, but also the most out of my 'know-how'.

Currently there are 100k users in the matrix needing shuffled properly. Many of the records are broken -- e.g. we have for example one user who is the parentuid of 10 different users, since there's a right/left leg only there should only be 2 matrix positions w/ same userid in the parent slot.

My best solution now, is doing something along the lines of getting all sponsored children for the current chosen sponsor into an array, and appending as I go... removing spots as they are filled, and re-sorting the array as needed.

So we'd have $arr = [objB, objC, objD], where each obj is the sql selections from the db into a stdObject. Then when I'll have an array of rows that need updated, i.e. if the parentuid is different from the newparentuid -- then add it to the update array, which will go through and update all by the id of the matrix position any parents that changed.

So after I update B, I'd get all sponsored by B append it to A's sponsored, removing B and order by date and if paid. The part I get stuck on is then what happens when I flop back over to c.. C can't use any of B's sponsored's...

I could have it be $sponsored['A'] = [], $sponsored['B'] = [], then $currentSponsored in each leg's could be an intersection or something. But the further I go, the more I keep thinking this is going to fuck me over... and have major design holes...


r/DatabaseHelp • • Apr 02 '18

Donor database help

1 Upvotes

I need to create a donor database for political contributors. This is all open records where people submit donations and they give you their name, address, employer, and occupation. These are all entered by hand and many times have little typos somewhere in them.

I need to compare thousands of these records, link them up, and hold them in a database for exporting to csv. How would one begin doing such a thing?


r/DatabaseHelp • • Mar 31 '18

How should I have solved this database design question?

2 Upvotes

I interviewed for a job a few days ago that had a written coding test involving basic programming knowledge and writing SQL queries. The final question was designing a schema for a database. I heard back today that I did excellent on the test but wasn't being considered based on my design. This was for an entry-level position and I have no professional experience designing databases. So my question is two part: What are some good resources to study database design for interviews and how would you have answered the question?

Here is the database design question:

Company ABC sells books to various bookstores. When making purchases with various payment methods, the bookstores would like to use aliases tied to the payment info so they don't have to give payment information to new employees. Company ABC will store all the payment information along with the alias/name of the information. Company ABC tasks you with designing a database schema that would fit the needs outlined.

This is how I answered:

I built a simple table to hold the data. The Alias table would have as columns a unique alias/name, card number, expiration date, csv number, and a foriegn key id linking back to the bookstore table. I also created an auto incrementing id as the primary key for the alias table.

Problems with this design: Making the alias column unique doesn't allow different bookstores to have the same alias. If this column isn't made unique how I can prevent a bookstore from having multiple aliases with the same name?


r/DatabaseHelp • • Mar 26 '18

Help finding a name of such database system

3 Upvotes

Hello

I am working on a certain project, where I store "nodes" in a database. each "node" has zero to many parents and zero to many children of type node too. I need to store these nodes in such a way that when I am retrieving them, the parents must be retrieved first, then the node, finally the children. At first I thought of implementing this using standard rational database model, but I am pretty sure there are easier ways. Can you please tell me how to implement such a system?

Thank you!