database-design

Database design on 1 to many approach

Hi all, I am learning database design, given with the following business requirement. Which design approach should I take? Each customer can apply many applications. Each company can apply many applications. Each organisation can apply many application. Each approach, I thought of has a draw back. If you were to choose which will be...

Storing user action data in MySQL: one table or many?

I am building a website wherein the users can perform a variety of actions and they get a variable number of "points" or "badges" for performing specific actions. Certain data must be stored no matter which type of action the user performs, such as the user ID, the action type, a timestamp, the current point total, and any badge awarded....

Efficient retrieval of overlapping IP range records via a single point.

I have a table with millions of IP range records (start_num, end_num respectively) which I need to query via a single IP address in order to return all ranges which overlap that point. The query is essentially: SELECT start_num , end_num , other_data_col FROM ip_ranges WHERE :query_ip BETWEEN start_num and end_num; Th...

How to model a database where one page can have different content types?

I have the database table page with the fields contenttype_id and content_id. I want to link a page to a contenttype via contenttype_id and refer to an actual content via content_id. The problem is contents depend on the contenttype_id and are modelled differently, therefore the content_id refers to different tables depending on the cont...

Pattern for searching entire DB record, not specific field

More and more, I'm seeing searches that not only find a substring in a specific column, but they appear to search in all columns. An example is in Amazon, where you can search for "Arnold" and it finds both the movie Running Man starring Arnold Schwarzeneggar, and the Gund toy Arnold the Snoring Pig. I don't know what the term is for t...

Database Design for Storing Checklists and Results

I've already read these questions but the answers are either irrelevant or unsatisfactory. I have a number of checklists that are used as a guide for frequently repeated procedures. The checklists evolve slowly over time as each procedure is refined and improved. What I'm looking to do is store a number of distinct Checklists that each...

Array or Database Table?

I could really use some good feedback on best practices / insight on whether it is better to put things in the database, or build an array. Take for example you have the suits of cards: $suits = array('clubs', 'spades', 'hearts', 'diamonds'); The array could change in the future, but not very frequently if at all. Now these suits are ...

Optimal database structure design for one to many

I am building an inventory tracking system for internal use at my company. I am working on the database structure and want to get some feedback on which design is better*. I need a recursive(i might be using this term wrong...) system where a part could be made up of zero or more parts. I though of two ways to do this but am not sure wh...

How to search for a substring in SQLite?

Whats the most efficient way to search for a sub string in SQLite? I'm looking at the LIKE operator. Do I have the right idea? Has this worked well for you? http://www.sqlite.org/lang_expr.html Thank You. ...

How to store Goals (think RPG Quest) in SQL

Hi, Someone asked me today how they should store quest goals in a SQL database. In this context, think of an RPG. Goals could include some of the following: Discover [Location] Kill n [MOB Type] Acquire n of [Object] Achieve a [Skill] in [Skillset] All the other things you get in RPGs The best I could come up with is: Quest 1-* Que...

Inheritance and foreign key constraints with postgresql?

In our project we benefit a lot from the inheritance feature of the PostgreSQL database! We implement the dynamical creation of schemes for different agencies. This structure permits us to solve a lot of security issues which occurs immediately in the case of bulk tables (without partitioning). The only problem we encountered is to gu...

Storing inherited objects in a database

I'm trying to figure out the best way to map inheritance relationships in an object model into a relational database. For example consider the following class structure. public Class Item { public String Name{get; set;} public int Size {get; set} } public Class Widget:Item { public String Color{get; set;} } public Cla...

What's the best way to implement a rank field in a database?

Suppose you have a table where you store the musical preferences of people, and you'd like to give users the ability to rank their preferences. At the time of insertion, the rank field should be calculated automatically. Later, however, the user should have the ability to edit his rankings. id, memberid, trackid, rank EDIT: It appears ...

Location / Brands / Company - schema design route?

Geo entities are: Continent, Country, Province, City, Neighborhood. By default Continent, Country and City will always exist. Province is optional as not all countries have state/province. And neighborhood data takes time to find, so it is a load as the data comes in. Other entity: Zipcode (mapping to City(required) and Neighborhood ...

Social Network Database

I'm building the database for my Social Networking Site project. My database has to hold information of many user accounts. Each user has a profile and the profile contains various information. The account owner should be able to set the privacy of each profile information (either private or public). I'm wondering how I should keep track...

What's the best approach to designing a database that keeps track of orders and wish lists?

The best way to describe this scenario is to use an example. Consider Netflix: do they store their orders (DVD's they mail out) in a separate table from their member lists (NOT members table, but a joiner table of members and movies--a list of movies each member has created), or are orders distinguished by using additional information i...

Database design question

I have a form where users submit different fields to create events. The number and type of fields requested are different on each form, depending on the category of event. What is the best way of going about designing this database - should the events contain every possible field and simply null the unused fields? Thanks! ...

Best database for a real-time event analytics solution

I'm developing a real-time analytics solution and I need to choose the best database to do it. I believe MongoDB is ideal but I don't have the experience to compare all the other solutions. What's your advice? Thanks ...

What would be the relational way to store a tournament bracket in MySQL?

Right now I have a table for matches where each match has a reference to 2 competing participants and a winner, but there isn't a way to store the order of the rounds. ...

Which one is good database design when creating child tables?

Hi all, There are two methods which I noticed while designing child tables Method 1 Example: Master Table >>Order Table (order_id pk) Child Table >>order_products table (order_id,product_id, quantity,PK (order_id,product_id)) Method 2 example: Master Table >>Order Table (order_id pk) Child Table >>order_products table (order_pr...