database-design

Perform Joins in O(n) time?

大憨熊 提交于 2020-01-16 06:13:08
问题 is there a way to Join 2 tables in linear time? I heard this can be done by having another data structure (Hashtable), but I'm not sure how this can be done. I was always wondering a Join will involve a cross-product and hence it is O(n^2). 回答1: Algorithm: Loop through table A. Hash all Items, Add them to the Join array. Loop through table B, check each item if it's in the hash table (Check - O(1)), if not, add to the Join table. 回答2: If there are indexes available on columns used in the join

Indexing schema-less dbs having user-defined schemas?

白昼怎懂夜的黑 提交于 2020-01-16 05:36:12
问题 One of the most essential features of any database is query speed. We store data away and want quick access to data that matches our criteria. However, of late, schema-less databases have become popular. It's one thing if we have a schema-less database but there actually is an inferred (in-the-head/in-the-app) schema; it just hasn't been declared formally by the database. On the other hand, let's say we truly need an open database where several users have their own schemas for their own

Database design question: discriminatory column vs foreign key

妖精的绣舞 提交于 2020-01-16 03:57:05
问题 So let's say that I have a database for managing customers. A customer has all the basic properties that one might expect — however, there are special kinds of customers called distributors. A distributor doesn't have any special properties in and of itself, except that it can distribute products to certain markets which are stored in a market table. I can think of two ways to go about distinguishing distributors from "regular" customers: Create a discriminatory column in the customer table

Normalizing a variety of properties with similar data types

半腔热情 提交于 2020-01-16 01:52:33
问题 I'm working on setting up a database to house properties related to a game, for example whether or not it supports multiplayer, what genres it is, release dates, etc. It seems like creating two additional tables (genres, genres_data for example) for each category type isn't nearly as dynamic as it could be. My initial thought was to set it up one of two ways... Have a games table with skeletal information, then a properties table to list all the properties, and a third table to contain all

Many-to-Many Relationship between two tables in two different databases

…衆ロ難τιáo~ 提交于 2020-01-16 01:36:19
问题 As mentioned in the title, is it possible to create many-to-many relationship between two tables that belong to two different databases? If yes, how can i perform that with PostgreSQL? 回答1: The standard way of using foreign key constraints to enforce referential integrity is only possible within the same database - not db cluster. But you can operate across multiple schemas in the same database. Other than that, you can create tables just the same way. And even join tables dynamically among

Define Laravel Eloquent relations between 3 models in a messaging system

我只是一个虾纸丫 提交于 2020-01-16 00:47:31
问题 I'm trying to create multi-participant messaging system. Here's the database design I'v found here: Messaging system database schema Conversation ------------ id Messages -------- id conversation_id from_id subject message from_timestamp Participants ------------ conversation_id user_id last_read_timestamp Could you help me to describe Eloquent relations between these models? I mean this: http://laravel.com/docs/eloquent#relationships 回答1: class Conversation extends Eloquent { public function

How to implement a one-to-many relationship with an “Is Current” requirement

北战南征 提交于 2020-01-15 15:31:14
问题 Designing a database, there's a relationship between two tables, Job and Document . One Job can have multiple Documents , but one (and only one) of these Documents needs to be flagged as IsCurrent . This is not always the most recent Document associated with that Job . Structurally, I can see two ways of doing this. The first is to add a DocumentId column to Job , and a JobId column to Document . This will work, but creates a circular reference: when imported into Entity Framework you end up

How to Save Multiple Check-boxes data to database?

那年仲夏 提交于 2020-01-15 15:29:51
问题 I am not an expert so I'd really appreciate if you are real specific on your answers. I have this registration form that has a section with lots of check-boxes, and I wondering what the best way is to save this in the database. I am not sure if all values should go to a single column, or If I should create a different table only for this section of my registration form. It's also important to take into account that I will later need to pull all this data from the database and to show it in

How to Save Multiple Check-boxes data to database?

喜你入骨 提交于 2020-01-15 15:29:14
问题 I am not an expert so I'd really appreciate if you are real specific on your answers. I have this registration form that has a section with lots of check-boxes, and I wondering what the best way is to save this in the database. I am not sure if all values should go to a single column, or If I should create a different table only for this section of my registration form. It's also important to take into account that I will later need to pull all this data from the database and to show it in

Can an attribute designate one table over another?

廉价感情. 提交于 2020-01-15 09:51:28
问题 I'm creating a sports statistics database. With it, I'd like to catalog game/match statistics for many types of sports. For example, this database would be able to tell you how many touchdowns the Carolina Panthers scored in the 09-10 season (football), or how many free throws were made by the Miami Heat in their last game (basketball). I'm having trouble designing one of the more fundamental tables called Matches. The Matches table has columns for: ID (PK match_id ) date of play ( play_date