database-design

Year Based Primary Key?

How can I create a Primary Key in SQL Server 2005/2008 with the format: CurrentYear + auto-increment? Example: The current year is 2010, in a new table, the ID should start in 1, so: 20101, 20102, 20103, 20104, 20105... and so on. ...

One-to-Many Table Join?

I have one table (webRooms) which has a number of rows which match those in a second table (Residency). Table 1 looks like this: ID | dorm_building | dorm_room | occupant_num Table 2 looks like this: student_ID | dorm_building | dorm_room What I'd like is to get results like this: ID | dorm_building | dorm_room | o...

CSV identity fields: nHibernate oddity or db design error?

I've inherited a database and know an nHibernate engine was used on top of it. Inside the database I see CSV values representing multiple identities instead of "proper" link tables being used for primary and foreign keys. For example one tuple looks like this: PersonID, int: 1 Name, varchar: John Smith Edus, varchar: "76,5262,...

PostgreSQL/PHP custom CMS - multiple schemas within single database security.

Hi. I am writing a CMS using PHP and PostgreSQL. The CMS is capable of running multiple sites from a single codebase, using a unique set of tables per site / domain, differeing depending on which features are enabled. I understand that PostgreSQL supports multiple schemas within a single database, and that access permissions are then se...

Model changes to widgets (price/description) over time in Rails

I recently asked this question and the answer makes alot of sense to me. Now I ponder how those answers hold up in an environment like Rails where there are plugins/gems available like, say, vestal_versions? If I'm selling widgets and the price and/or description of the item will change over time and Rails is my framework. How would you...

how to store 2 billion users?

There is a portal with two billion users registered. If you store all the 2 billion users in a conventional databases it will take more time to retrieve the data about a particular user when that user tries to login. How do you handle this situation to make sure that the user gets the response quickly. ...

Databases and Deep Copy

If I find myself wanting to do a deep copy of an object stored in my relational database, have I necessarily done something fundamentally wrong architecturally? This is a different angle on another (much more detailed) question I asked, but haven't gotten much response to called Copying Relational Table Data. ...

What are best practices for removing "friends" from a database?

Say you have a table schema such as this: friends(friendship_id, uid1, uid2, are_friends). When one friend un-friends another person, is it best practice to delete that row from the database (and reset auto-incrementing)? Or should you simply change the are_friends status to 'N'? I'd love to know what you think and why. EDIT: My prima...

Inventory Management System in 3 Hours?

Inventory Requisition Process: Whenever a user requires inventory, user generates an inventory requisition, and if the inventory is available, the inventory will be directly issued and user’s inventory account will be updated. In case the inventory is not available, the purchase order will be generated for the required inventory to the c...

SQL FOREIGN KEY USAGE ? what does it really do ? and when it was needed ?

ok im makeing a simple database for my example, there is users data and the user company's data . CREATE TABLE `users` ( `UID` INT(25) NOT NULL AUTO_INCREMENT , `username` VARCHAR(60) NOT NULL , `password` VARCHAR(100) NOT NULL , `ownername` VARCHAR(150) NOT NULL , `userstatus` TINYINT(1) NOT NULL , `userregistertime` DATETI...

What are the best practices for designing DB Tables

We're building our DB design (using PostgreSQL) and for (almost) every table , I have the following columns CREATE_TIMESTAMP TIMESTAMP, CREATED_BY VARCHAR(25), modified_TIMESTAMP TIMESTAMP, modified_BY VARCHAR(25), I am also using Audit tables for some of the Entity Tables. The DB about 15 tables as of now (very soon will ...

How to store testing options into database?

Let's say I have some parameters such as a,b,c, and I need to store the test results by changing them. The thing is that the the number of parameters will be keep increasing, so I can't keep them as static column. For example : Test 1 : a = 10, b = 20, c = 1 Test 2 : a = 11, b = 21, c = 11 Test 3 : a = 11, b = 20, c = 1 ... Test 1001...

Database design with table sharing

My application saves posts to database, I have 6 different types of posts and I delibrately NOT joining these post tables with any other tables. Now, they all share some common columns, like, PostID, UserID, Title, Body, PostDate, ViewCount, and many more common columns... And, these 6 types of posts have many of their own unique c...

User Messages Database Schema?

This is probably very subjective and I have my own thoughts on this, but how would one go about constructing a database that supports user to user messages (one to one or one to many). My original thought was to have a MESSAGE table and MESSAGE_PARTIES table MESSAGE would include the following fields: -ID, Subject, Body, Create...

Database design for a social networking site...

What are the Tables that would be present in a social networking site (ex:twitter).... I have a users table as of now... How to keep tracker of followers and people i follow... Should i maintain separate table for followers and people i follow... What are the columns which would be there in those tables? Please don't think this as Su...

Help clarify my thinking for rails associations

I'm building a rails app that allows athletes to create and manage timesheets for the sport of skeleton. I can't seem to wrap my brain around the correct associations between my models. Here's what I have so far. Athletes have Runs, which are composed of several Splits. Each individual split should be associated with a particular timing ...

Audit Table DB Design : Does creating Audit Tables for Join Tables make sense

we are creating separate audit tables for those entity tables which need auditing using triggers on PostgreSQL 8.4. <Family> <Contact> <Family_Contact> <Address> We have some join tables. Eg : Family_Contact is a join table. Family has 1 or more than 1 contacts. Each contact has an Address. So, we have the following Table structure....

creating a tag-based website and not using programing?

Hi. I want to create a tag-based website, and I need a tool that I could use (preferably without programing). It's a site where a user could pick tags on a certain item (tags are to be listed under a few categories). On the other end - a visitor could choose a tag, and then be redirected to a few items on which that tag was selected the...

Database Design Decoupling

Hi, I am working on a .NET web project with an SQL Server back end. There is a core part of the database that is populated with stock data. This data is loaded daily by a loading application. This data should remain readonly to the website. By this I mean, that I do not want a Web developer to modify the tables that are are specific ...

which database type are good for arrays ?

i want my database to support one company haveing many users how can i do that? exampleusers table(UID,username,password)company table(CID,companyname,usersthatistheownerofthecompany) how can i do that? what should i do ? should i make an array in php like 1241,423,4123 *uid's that will be inserted on usersthatistheownerofthecompany row ...