database-design

How far to take normalization in database design?

If I have a Tables: Projects(projectID, CreatedByID) Employees(empID,depID) Departments(depID,OfficeID) Offices(officeID) ("CreatedByID" is a foreign key for employees) And I have a query that I need to run for almost every request of a web application that grabs all projects in an office. Is it bad practice to just add a redundant "...

AM/PM Column Name

Without arguing the relative merits of storing a datetime this way... If you had a column where you stored AM or PM what would you call that column? EDIT: I should have figured that there'd be a group of you who couldn't resist being snarky about the idea... Nowhere do you see that I'm about to do this, that I want to do this, that I'...

Most elegant solution for humungous problem

I'm working on a site where a user could select certain dates that apply to them, e.g Date 1,Date 2, Date 3, etc. Each date will have certain questions belonging to it, so if the customer checked off 'Date 1' to indicate that this date applies to him, he'll then see a bunch of textboxes asking him about Date 1 and how it applies to them...

How to save a particular, mutable "order" into a Database

Suppose I have some objects, and I want the user to be able to reorder them in any way they wish, say, by dragging them around. So I'd have cheese muffins milk and then the user drags 'milk' to the top, making the new order milk cheese muffins Is there a best practice how to store the order of these objects in a database? The nai...

How do I check constraints between two tables when inserting into a third table that references the other two tables?

Hello Consider this example schema: Customer ( int CustomerId pk, .... ) Employee ( int EmployeeId pk, int CustomerId references Customer.CustomerId, .... ) WorkItem ( int WorkItemId pk, int CustomerId references Customer.CustomerId, null int EmployeeId references Employee.EmployeeId, .... ) Basical...

How to build a simple recommendation system?

How to build a simple recommendation system? I have seen some algorithms but it is so difficult to implement I wish their is practical description to implement the most simple algorithm? i have these three tables Users userid username 1 aaa 2 bbb and products productid prod...

How would you model articles with references and citations in rails & ActiveRecord?

An article has many articles that it refers to and many other articles can refer to it. Sometimes an article can refer to an article that also refers to it. ...

MySQL NOT LIKE query not working

I have 2 tables: posts tags Tags table is structured like this: post_id tag So for every tag that's given for a post, I create a record in the tags table. If a post has 10 tags, there will be 10 records in tags table with that post_id. I'm now trying to build a search page where users can do a search for posts where tags do not ...

Database: To delete or not to delete records

I don't think I am the only person wondering about this. What do you usually practice about database behavior? Do you prefer to delete a record from the database physically? Or is it better to just flag the record with a "deleted" flag or a boolean column to denote the record is active or inactive? ...

SQL Server (2008) Creating link tables with unique rows

Hi guys, I'm having trouble getting in touch with SQL Server Managemen Studio 2008! I want to create a link-table that will link an Event to many Audiences (EventAudience). An example of the data that could be contained: EventId | AudienceId 4 1 5 1 4 2 However, I don't want this: Even...

Good examples for teaching database design

Does anyone have any good scenarios for teaching relational databases and SQL? All the examples I can find are either trivial or have improbable domain constraints (like full name being unique). I'm especially trying to find some good examples for normalisation: tables that don't immediately fit 3NF and BCNF. At the moment I'm using a...

Use item specific prefixes and autonumber for primary keys?

We had a meeting this morning about how would should store our ID for some assets that we have in our database that we are making, the descusion generated a bit of heat so I decided to consult the experts of SO. The table structure that I belive that we should have(short version) is like the following: Example 1) AssetId - int(32) - ...

Are stored procedures required for large data sets?

I've just started my first development job for a reasonably sized company that has to manage a lot of data. An average database is 6gb (from what I've seen so far). One of the jobs is reporting. How it's done currently is - Data is replicated and transferred onto a data warehouse. From there, all the data required for a particular repo...

Double Primary Key Design

My database has a table that keeps track of the department and user id. The catch here is that while the department and user_id column can have duplicates, the combination of them can't. This is to say, DepartmentA 0001 DepartmentA 0002 DepartmentB 0001 DepartmentB 0002 are valid data in my table. But DepartmentA 0001 ...

Model Heterogeneous Type in Database

I am trying to figure out the best way to model a set of "classes" in my system. Note that I'm not talking about OO classes, but classes of responses (in a survey). So the model goes like this: A Class can be defined with three different types of data: A Class of Coded Responses (where a coded responses consists of a string label an...

Dealing with "hypernormalized" data

My employer, a small office supply company, is switching suppliers and I am looking through their electronic content to come up with a robust database schema; our previous schema was pretty much just thrown together without any thought at all, and it's pretty much led to an unbearable data model with corrupt, inconsistent information. T...

Define Generic Data Model for Custom Product Types

I want to create a product catalog that allows for intricate details on each of the product types in the catalog. The product types have vastly different data associated with them; some with only generic data, some with a few extra fields of data, some with many fields that are specific to that product type. I need to easily add new pr...

Database as fileformat

A niave beginners question about database design. I have an app managing some logger data eg. 1000s of sequential measurements of time, voltage, current, temperature. In addition each sequence run has meta data (date, location, etc). So I need a table for each set of measurements and a master table listing these tables and the meta data ...

What are the recommended database column sizes for names?

In regards to database design, what are the recommended column sizes for such fields as someones first, middle, and last name? Additionally, is the standard one character for a middle name safe, or should additional space be allowed for middle initials? Specifically, I'm looking for sizes that will allow this be something I don't have t...

MySQL performance of unique varchar field vs unique bigint

I'm working on an application that will be implementing a hex value as a business key (in addition to an auto increment field as primary key) similar to the URL id seen in Gmail. I will be adding a unique constraint to the column and was originally thinking of storing the value as a bigint to get away from searching a varchar field but w...