database-design

How do you merge tags on an already existing system

We have a simple interface to tag a particular question (e.g. entry has 1..many tags and each tag entry has a foriegn key pointer back to the entry table) 1. What is the current production version of the jdk? (Tags: jdk6 jdk-6 jdk java) 2. In what version was java.util.spi package introduced? (Tags: jdk-6, jdk7, jdk5) 3. Whic...

What's the point of a candidate key?

I'm fairly new to database management and this question never seems to be answered in more than one sentence. All other SO answers say "A candidate key is a minimal super key." That means nothing to me. A candidate key is supposed to specify uniqueness of a db record, correct? And a primary key is a candidate key. If a primary key alrea...

Apply the unique constraint to combinations of columns in SQL

Hi, I have a table called product_attributes in a MySQL Database. It consists of a product SKU (foreign key), an attribute label and an attribute value. I need to ensure that combinations of SKU and attribute labels are unique. EXAMPLE - inserting this would be legal {001, 'weight', '100 lbs'} {001, 'color', 'blue'} {002, 'weight'...

Design: Custom access control (restrict page access based on some criteria)

Although I will be using Ruby on Rails, this is a general questions about the best way to model a database and design a custom access control system for a CMS. So it does not matter what language/db. I would be happy to hear input from all experts. My problem: I am in the early process of developing an online tutorial system for a local...

How to store Log in database ?

My application let users to send files to each other. Regular users can edit their contacts, change password, etc. In addition, admin users can add/remove users and view the log of what happened. My question is how to store this log in MySQL database ? I thought to store the log like this: log_id time user_id action_type ...

Primary key: code or name?

One of the most common kinds of database table has an alphanumeric code and human friendly name (e.g. countries, currencies, accounts, products, VAT codes etc.) The traditional/obvious thing to do is make the code the primary key. And for some tables e.g. customers where the number may be large so that names may not be unique identifier...

Customizeable database

What would be the best database/technique to use if I'd like to create a database that can "add", "remove" and "edit" tables and columns? I'd like it to be scaleable and fast. Should I use one table and four columns for this (Id, Table, Column, Type, Value) - Is there any good articles about this. Or is there any other solutions? May...

Database design challenge

Hi Guys, I'm creating an virtual stamp card program for the iphone and have run into an issue with implementing my database. The program essentially has a main points system that can be utitlized through all merchants (sort've like air miles), but i also want to keep track of how many times you've been to EACH merchant So far, i have ...

Microsoft SQL Compact Edition rename column

Hy, I'm new with SQL Compact Edition and I am having problems renaming a column. I know that you can rename a table using sp_rename and this doesn't work with columns. I've searched for an alternative, but didn't find one. Can I delete a column and then add a new one after a specific column? If I delete the column and add it after t...

SQL Server: how to constrain a table to contain a single row ?

I want to store a single row in a configuration table for my application. I would like to enforce that this table can contain only one row. What is the simplest way to enforce the single row constraint ? ...

User types / role - developers

You have regular user's that use your website/services, they can login to mainsite1, then you have developers, that can not login to mainsite1, but can login to developercenter1. 1) Do you store every type of users into 1 large USER table then assign different roles? or 2) Do you create a completely separate table just for develope...

Database Normailization

Convert tables into 1st, 2nd, and 3rd normal form CustomerID(FirstName,LastName,BillingAddress,PhoneNumber,EmailAddress) ...

Is there a reason to use Base2 lengths for columns in SQL Server?

Possible Duplicates: varchar Fields - Is a Power of Two More Efficient? Nvarchar or varchar what is better use multiply of 2 or rounded full numbers?? Out of sheer habit I define the sizes of columns that I use in SQL Server to be Base2 sizes. For example, here's a table that I'm working on: ID int FirstName nvarchar(64) L...

Could I same column to represent a foreign key to multiple tables?

I am trying to use the same column to represent a has foreign key to different columns. This is because there could be an arbitrary number of tables to be indexed using this column. Right now, my idea is to use a small varchar() field to represent which field they are indexing and then check for them my probably sub-querying for all that...

MySQL Alter Table using existing field values

Hello, I am working with a database that has a table called date, which contains a separate field for day, month, year. Clearly this is not ideal when I am trying to run comparisons, etc. I am wondering is it possible for me to add a DateTime field to each row of this table and insert a concatenated string into the new field from the ex...

System variables in database: One row per variable or one row with pickled dictionary per module?

I am designing a blog/news website with a number of modules. These modules need some settings saved in the database. Which of these two options is better: Each variable gets saved in a single row. When they are needed, the row gets queried. Variables of a single module get pickled on submitting the settings form (only the user can cha...

Help with database structure

I am trying to create a system which allows local network users to collaborate content together. Requirements: The user should be able to: create content, edit content (content created by anyone), records should be kept on who edited what and when, should easily be able to go back and forth between edits, add comments to pages, sho...

Actions log table structure

Hi, I have to write a service which will implement some kind of a black/white list manager. Short description : It is very similar to messaging in social networks. imagine by default anyone can send you a message. And you have the possibility to block it for everyone, so no one can send you a message. Once it is blocked you can have a ...

Storing object graph as of date in a database

I'm going to try to keep this question database agnostic, but I have an interesting problem that I need to tackle and I thought I'd open up the floor for suggestions and feedback. I need to be able to download data from a feed source and store it in a database of some kind, the data needs to be merged into the existing data and I need t...

How to compare two tables column by column in oracle

I have two similar tables in oracle in two different databases. For example : my table name is EMPLOYEE and primary key is employee id. The same table with same columns(say 50 columns are is avlbl in two databases and two databases are linked. I want to compare these two tables column by column and find out which records are not matchi...