database-design

how to design this relation in a DB schema

I have a table Car in my db, one of the columns is purchaseDate. I want to be able to tag every car with a number of Policies (limited to 10 policies). Each policy has a time to life (ttl, a duration of time, like '5 years', '10 months' etc), that is, for how long since the car's purchaseDate the policy can be applied. I need to perfor...

Mutiple FK columns all pointing to the same parent table - a good idea?

For those of you who live and breath database design, have you ever found compelling reasons to have multiple FK's in a table that all point to the same parent table? We recently had to deal with a situation where we had a table that contained six columns which were all FK columns to the same parent table. We're debating whether this in...

How to force grails GORM to respect DB scheme ?

I have two domains : class CodeSet { String id String owner String comments String geneRLF String systemAPF static hasMany = [cartridges:Cartridge] static constraints = { id(unique:true,blank:false) } static mapping = { table 'code_set' version false columns { id column:'code...

schema for storing different varchar fields over time?

This app I'm working on needs to store some meta data fields about an entity. The problem is that we can already foresee that these fields are going to change a lot in the future. Right now every entity's property is translated to one column in the entity table, but altering table columns later down the road will be costly and error-pr...

How can several different datatypes be saved in one table

This is my situation: I am constructing an ad-like application in Django and Mysql. I am using a flexible-ad approach where we have: a table with ad categories (several categories such as home, furniture, cars, etc.) id_category name a table with details for the ad categories (home: area, squared meters. car: seats, color.) id_det...

Graph-structured databases and Php

I want to use a graph database using php. Can you point out some resources on where to get started? Is there any example code / tutorial out there? Or are there any other methods of storing data that relate to each other in totally random/abstract situations? - Very abstract example of the relations needed: John relates to Mary, both ...

Edit primary keys in Symfony auto-generated admin

I need to edit primary keys in several tables. By default, symfony hides primary keys in New/Edit forms. For example, can't edit table 'Tags' with only field 'tag' which is PK. Adding integer ID to this table is not exactly good db design. Thanks in advance for your help. ...

Basic Database Design

Hi, This question would be a bit childish, I have three tables, users, usergroups and contacts. In my system, the end user can create a contact and subsequently he\she may define the visibility of the contact by setting only for that user, or for a set of users or a set of usergroups. So I am wondering, how my database design would b...

how many index per database table?

Hi, How many indexes is preferred for one table in MYSQL?? I have a company table where I search mostly for ID,state and category? Thansk ...

Storing n-grams in database in < n number of tables.

If I was writing a piece of software that attempted to predict what word a user was going to type next using the two previous words the user had typed, I would create two tables. Like so: == 1-gram table == Token | NextWord | Frequency ------+----------+----------- "I" | "like" | 15 "I" | "hate" | 20 == 2-gram table == Token ...

How do I write this MySQL query?

I am working on an Asset DB using a lamp stack. In this example consider the following 5 tables: asset, server, laptop, desktop, software All tables have a primary key of id, which is a unique asset id. Every object has all asset attributes and then depending on type of asset has additional attributes in the corresponding table. If ...

Event feed implementation - will it scale?

Situation: I am currently designing a feed system for a social website whereby each user has a feed of their friends' activities. I have two possible methods how to generate the feeds and I would like to ask which is best in terms of ability to scale. Events from all users are collected in one central database table, event_log. Use...

How to store data in mysql, to get the fastest performance?

Hey, I'm thinking about it, which of the following two query types would give me the fastest performance for a user messaging module inside my site: The first one i thought about is a multi table setup, which has a connection table, and a main table. The connection table holds the connection between accounts, and the messaging table. I...

How can I drive a boolean field in SQL Server off of a nullable column?

I'd like to have two columns in a database, one for tracking whether or not the user has submitted something, and another for the timestamp of that submission. How can I structure the table definition so that the state of these two columns is never inconsistent? Basically, I'd like the boolean field to be driven by whether or not a Sub...

database is normalized but the resulting keys are a problem

but the prob is there are relations ships which are so huge that after normalizing they have like a 20 primary keys( composite keys) which are really foreign keys but have to be declared as primary keys to identify the relationship uniquely. so please help? is it correct and i apologize to the expert community for not accepting answers...

Many tables for many users?

I am new to web programming, so excuse the ignorance... ;-) I have a web application that in many ways can be considered to be a multi-tenant environment. By this I mean that each user of the application gets their own 'custom' environment, with absolutely no interaction between those users. So far I have built the web application as a...

Database with "Open Schema" - Good or Bad Idea?

The co-founder of Reddit gave a presentation on issues they had while scaling to millions of users. A summary is available here. What surprised me is point 3: Instead, they keep a Thing Table and a Data Table. Everything in Reddit is a Thing: users, links, comments, subreddits, awards, etc. Things keep common attribute like up/down...

What is the best schema design for child collection with a "primary" entity

Here is the scenario: You have a Persons table with a one-to-many relationship with an Addresses table, where one of the Address rows is the "primary" Address. Is it better in a normalized schema to Use a Persons.PrimaryAddressID to access the "primary" Address for a Person or Use an Addresses.IsPrimary bit column to reference th...

Find and replace table/field names in Access?

I've been handed a rather large, old, and crusty Access 2000/2003 database to clean up. I'll need to rename a number of tables and fields, but need to do so in a way that doesn't break existing queries. (Fortunately, there are no macros, forms, or reports to worry about.) I've heard there are some commercial tools to make this job easie...

How to Link VS2010 Database Project and LINQ to SQL

As I am working with the new database projects in VS2010, and as I am learning LINQ to SQL, I am curious as to the best way to link the two groups of information so that when I update one, the other updates along with it. From my research here at SO, as well as in Google, it appears the general rule of thumb is: "Build the database, and...