database-design

Modeling a directed graph with a special center node.

I'm looking for opinions on how to model a directed graph that contains one special node. Special node: Cannot have any edges leading to it. Cannot be removed. Current design: Tables: Nodes, Edges. Edges contains two columns; from_node_id and to_node_id, each referencing a record in the Nodes table. Rather than storing the specia...

Extended Property Design

Suppose I have the following table schema: ID | Name | Width | Height | Size What are considerations to think about when breaking this table into two tables with one-to-one relationship? E.g.: ID | Name and ID | Width | Height | Size My concern is that I'll have a lot of columns on the table (not just five, here is for illustratio...

Database design: multiple "options" tables vs. a single table

I believe all of us seen this design requirement in one form or another. Software needs to offer a user several answer options for various questions/settings. These options reside in the database. In a big project a number of such questions can easily surpass 50. Now. Is it okay to have 50+ tables with the identical design like this? ...

A better logging design or some SQL magic?

I'm knee deep in modifying some old logging code that i didn't write and wondering what you think of it. This is an event logger written in PHP with MySQL, that logs message like: Sarah added a user, slick101 Mike deleted a user, slick101 Bob edited a service, Payment Broken up like so: Sarah [user_id] added a user [message], slick10...

How to model Open/Closed statuses in a database?

Hello, Imagine I have an Orders table with columns OrderID (PK), CustomerID, CustomerOrderN and so on. Now I need to add a possibility to "close" orders with specifying a reason why order is closed (for example "offered price is too high for customer", "not available", "customer asked to close the order"). Question 1. What would be ...

A better database design?

I am designing a database and have run into a snag. Ok, not so much of a snag as just something that I do not like. I will have up to 1000 different scenarios, and in each scenario I will need to store the state of each one of 64 different toggles. I've worked this around as best I can and have come up with the following: Table Scena...

What would be the best schema to store the 'address' for different entities?

Suppose we're making a system where we have to store the addrees for buildings, persons, cars, etc. The address 'format' should be something like: State (From a State list) County (From a County List) Street (free text, like '5th Avenue') Number (free text, like 'Chrysler Building, Floor 10, Office No. 10') (Yes I don't live in U.S...

Archive Builder PHP

Before i start id like to say ive posted this question as more of a discussion rather than Problem Question. In my Database i have news posts lets say with 3 columns (Id, title, date). Wher Id and title are self Explanitory the date is stored in mktime() values, in other words the number of seconds passed since 1 January 1970. Now what...

Multiple foreign keys to a single column

I'm defining a database for a customer/ order system where there are two highly distinct types of customers. Because they are so different having a single customer table would be very ugly (it'd be full of null columns as they are pointless for one type). Their orders though are in the same format. Is it possible to have a CustomerId co...

Nullable database attribute in separate table

I have a database table containing data for a submitted application form with a predicted load of two million rows per year. There is an option to tag an application with a custom text but this feature will probably only be used 5-10% of the time. Later on forms can be searched out by this text. Should this be implemented as a nullable...

Storing a directed graph in google appengine datastore

I need to store a large and dynamic undirected graph in google appengine, what's the best way to do this? The graph representation must be able to support rapidly pulling out a set of vertices (for rendering on a page) and all the links from a specific vertex, and pathfinding across the graph (although the optimal path isn't really neede...

Youtube Table structures

Can anyone share me how does youtube stored video related information in there tables ? What would be the table structure and what would be the various columns in tables and the relations between them ? Thanks in advance ...

Zero downtime (or near zero) db schema changes

Hello, I was wondering how/if people have worked around db schema changes that would otherwise cause a production system to be down. It seems with additive changes that are constrained in some way (e.g. unique constraint) would be difficult to do b/c the app and the db must change at the same time otherwise errors will occur either in t...

Same data, two different ways to store it

Hola, The two tables below can both hold the same data - a full year, including some arbitrary info about each month table1 (one row = one month) ------ id month year info table2 (one row = one year) ------ id year jan_info feb_info mar_info apr_info may_info jun_info jul_info aug_info sep_info oct_info nov_info dec_info Table A ...

What is the best way to ensure that primary key and foreign key never intersect?

Say I have a table with a primary key a_id and foreign key b_id. It is important that a_id and b_id never intersect, i.e. it should never be the case that there exists an a_id = b_id. What would be the best way to implement this? Could I somehow do this on the database end (mySql), or should this be ensured programmatically? If I ens...

Forward declaration - no admin page in django?

Hi SO, This is probably a db design issue, but I couldn't figure out any better. Among several others, I have these models: class User(models.Model): name = models.CharField( max_length=40 ) # some fields omitted bands = models.ManyToManyField( Band ) and class Band(models.Model): creator = models.ForeignKey( User ) # some...

How to generate serial STRING primary key in Database.

My collegues don't like auto generated int serial number by database and want to use string primary key like : "camera0001" "camera0002" As camera may be deleted, I can not use "total nubmer of camera + 1" for id of a new camera. If you were me, how will you generate this kind of key in your program? PS : I think auto generated serai...

What is the appropriate limit for a question in a database?

I am doing my first database project. I would like to know what is an appropriate limit for questions in length. My plan has varchar(5000) for the length of a question at the moment. What is the appropriate limit for a question in a database? [edit] A question in the database is like a question here in SO, with code formatting. ...

What RAD environment or tool would you use for a small database-driven app?

I need to code a small record-keeping application for a small business in Windows and I'm considering programming it from scratch using .NET. However, I think that it might be overkill for such a common kind of program. It is mostly a CRUD application with simple arithmetic. I'm tempted to go the MS Access way, but I find it a bit limit...

Normalize or Denormalize: Store Contact Details (Phone Numbers) in separate Table? Search Performance?

Hello, I'm designing a database application which stores simple contact information (First/Last Name etc.) and I also have to store phone numbers. Besides phone numbers I have to store what they are for (mobile, business etc.) and possibly an additional comment for each. My first approach was to normalize and keep the phone numbers in ...