database-design

Can a Compound key be set as a primary key to another table?

Can a compound key be set as a primary key to another table? For instance i have the tables: Books -with Primary Key:Product_ID Client -with Primary key: Client_ID Clients_Books -with Compound Primary Key:Product_Id and Client_ID I want to set this compound Primary key from Clients_Books as a Primary Key to another table named: O...

Sorting by ratings in a database - Where to put this SQL? (PHP/MySQL)

Hi folks OK - I'll get straight to the point - here's the PHP code in question: <h2>Highest Rated:</h2> <?php // Our query base $query = $this->db->query("SELECT * FROM code ORDER BY rating DESC"); foreach($query->result() as $row) { ?> <h3><?php echo $row->title." ID: ";echo...

Adopting the "aspnet_ ..." sql tables from ASP.NET MVC

Hi everyone, I'm just starting a new project on ASP.NET MVC and this will be the first project actually using this technology. As I created my new project with Visual Studio 2010, it created to my sql server a bunch of tables with "aspnet_" prefix. Part of them deal with the built-in user accounts and permission support. Now, I want t...

Table relationship for subtypes

I have a parent table called 'Website' which holds records about websites. I have a child table called 'SupportSystem' which holds records about different types of support systems such as email, phone, ticketing, live chat etc. There is an intermediate table 'Website_SupportSystem' which joins these tables in a many-many relationship. ...

Advantage Database or SQL Server

I have a client that currently uses a local Advantage Database on their PC along with an application. They are thinking of upscaling their setup to have multiple applications running communicating with a database server i.e/a client-server environment. They are now considering the best database for this approach. They are looking at t...

Is there a severe performance hit for using Foreign Keys in SQL Server?

I'm trying my best to persuade my boss into letting us use foreign keys in our databases - so far without luck. He claims it costs a significant amount of performance, and says we'll just have jobs to cleanup the invalid references now and then. Obviously this doesn't work in practice, and the database is flooded with invalid reference...

SQL: Get latest record

Hi all, this is my relational model: Request ------------------------------ RequestId ------------------------------ 1 2 RequestState ------------------------------ RequestStateId | Name ------------------------------ 10 | Received 20 | Processing 30 | Finsihed Request...

First-time database design: am I overengineering?

Background I'm a first year CS student and I work part time for my dad's small business. I don't have any experience in real world application development. I have written scripts in Python, some coursework in C, but nothing like this. My dad has a small training business and currently all classes are scheduled, recorded and followed up...

Is this a good case for decomposing a table and having a 1-1 table relationship?

I am storing information about websites in a table. One set of information is the whois data about a websites domain name. This set of data contains about 40 fields and each record relates to a single website. I have no requirement to track updates. I could put all the whois data in the websites table, but it seems 'cleaner' and more int...

Auto-renaming columns in PowerDesigner LDM/PDM

I want to rename columns in a PowerDesigner LDM/PDM according to the state of the Primary checkbox. To be more specific, I want the column renamed from "oldname" to "id_oldname" if Primary is checked. I think it is possible with a custom check/autofix script like the one in "MSSQLSRV2008::Profile\Column\Custom Checks\Identity Seed and I...

News and news archive in different tables

I have encountered a situation where the news and the news archive are in different tables. Given that those tables contain many records and both share exactly the same structure is it still smart to split them up instead of having a flag that marks them as archived? ...

When to do calculations

Which way is better to store sales information in a database: Store cost for an item and sales price per item Store cost * qty and sales price * qty - so you are storing the totals in the db ...

Database design for Wave-like collaboration system

How do we decide what the smallest unit is? For text collaboration should it be a word, a paragraph? Is there going to be performance issues if the unit is too small? But it might be more flexible ...

What's the best way to manage file/item relationship?

I'm working on a CMS basically because I want to learn how to build one from scratch, and am at the point where I have to stop and think about how I want to manage the relationship between files and let's say, for the sake of simplicity, blog entries. If each file is going to be associated with one and only one "blog entry" (or item), t...

Storing checkbox values in a MySQL database then retrieving whether they're set or not... what is the best method?

Hi everyone I have a form where users can submit sites and say if they work in different browsers. Currently, it looks like this: <input type=checkbox name="browsers[]" value="IE6"/>Internet Explorer 6<br/> <input type=checkbox name="browsers[]" value="IE7"/>Internet Explorer 7<br/> <input type=checkbox name="browsers[]" value="I...

MySQL triggers cannot update rows in same table the trigger is assigned to. Suggested workaround?

MySQL doesn't currently support updating rows in the same table the trigger is assigned to since the call could become recursive. Does anyone have suggestions on a good workaround/alternative? Right now my plan is to call a stored procedure that performs the logic I really wanted in a trigger, but I'd love to hear how others have gotten ...

Standard Way of Storing Names in a Database

I have recently been pondering names and the way we store them. Generally a person will have a First, Last and Middle name. If you want to be particularly complete you might add a suffix field, perhaps even a title field. So if someone wants to be "Dr. John Q. Public III", they can. But a person can have more than one honorific and more ...

Creating MySQL and SQLServer compatible objects

I have a need to support two separate database engines - MySQL and SQL Server. I do not want to maintain two different sets of scripts to create database objects (tables, views, stored procedures etc...), if possible. I wanted to find out if someone has experience in doing such a thing and what were the learnings. Any links to articles/...

What Are The Best Practices For String Data Field Sizes?

Are there any recomended field sizes for commonly used string data storage types? For example things like FirstName, LastName, AddressLine1, AddressLine2, City, State, PostalCode, EmailAddress etc. I am sure anyone who has created a table to store these commonly used data fields has had to make a decision as to what maximum size to use. ...

Parse/regex one field after query using PHP or store segmented data in multiple fields?

Should I plan to parse/regex, for example, an entire url string retrieved from one field of a database table during a while loop of query results using PHP? Or should I store segments of the data (directory, filename, extension) in their own separate fields and concatenate the results during a while loop of query results? Assuming wo...