database-design

Django: ForeignKey() or ManyToMany() in this case? Or, other?

I have a model that is something like this: class ReturnAuthorization(models.Model): custom_id = models.CharField(max_length=40) class RMAAPILog(models.Model): return_authorization = models.ForeignKey(ReturnAuthorization) If I were to delete() a return authorization, I can't have it delete all the RMAAPILog()s that are relate...

The Integrity of linked data entities on update

What is the best-practice for maintaining the integrity of linked data entities on update? My scenario I have two entities "Client and Invoice". [client is definition and Invoice is transaction]. After issuing many invoices to the client it happens that the client information needs to be changed e.g. "his billing addres...

Can we create multicolumn unique indexes on MS access databases?

We'd like to prevent record duplication in our MS access database using a multicolumn unique index. Because of how the data is sent (via network), duplicate data is sometimes received. The data source does not send a unique ID, so the simplest option is to prevent duplicate records being inserted. According to Unique Index Design Guidel...

DB : Circular dependency in the database

EDIT: This is a duplicate I didn't find it at first. I am building a web-site for user-groups event management. Members : Name, Id Events : DateTime, Topic, OrganizerId (from FK to Members table) EventRegistrations : MemberId (FK), EventId (FK) Description (redundant) : A member can create and event, and becomes this event's or...

[MySQL]: table view or actual table. (tracing a primary key)

Hi, I have a Database that has the following relations: Transaction->Purchase->Item->Schedule Transaction - self explanitory Purchase - any purchase info that relates to the item being purchased (quantity, if the user purchases more than one item). A given Transaction can have more than one Purchase_ID tied to it. Item - Stores Item ...

NHibnerate data design recommendations

While doing some research into mapping one-to-one relationships I've come across some statements that have made me question some of my database design decisions. Basically I have some entities similar to the following: Person, Contact, Parent Both a contact and a parent are people. A person may be a contact, parent, both, or neither. ...

Altering a on attribute data size from a table in SQL Server

So I'm trying to do something I thought would've been straightforward. I have a table in the DB named "Images." It's 'Description' property is of type nvarchar(50). I simply want to make it nvarchar(250). Every time I try, it says it can't save because some tables would have to be redropped. I can't just delete it (i think) because, ther...

Database design, two types of users for website

I'm making a review type website, and I would like for there to be 2 types of users. One would be the majority, reviewers while the other would be the person the review is about. How, in terms of database design would I differentiate the two. Should I have separate tables for reviewers and reviewies or simply assign a different range ...

Design principles for designing database architecture of financial transaction system?

Hi, I want to design a database which will keep record for financial transaction.I want to design it as a product so that it can be used for any type of financial transaction.Are there some design principles specific to financial transaction database design that can help me out to make database more durable for long term with minimal arc...

What is the convention when relevant data needs to be stored in a join table?

Suppose you have a data model that is something like class Question has_and_belongs_to_many :choices end Now suppose, on that choices model, there is a position column. What is the best way to access that information without having horrible messy queries / models? The beauty of has_and_belongs_to_many is that it keeps things concis...

Model login constraints based on time

Good morning, for an existing web application I need to implement "time based login constraints". It means that for each user, later maybe each group, I can define timeslots when they are (not) allowed to log in into the system. As all data for the application is stored in database tables, I need to somehow create a way to model this id...

Storing matrices in a relational database

Hey guys, I am working on a project for a client and going through the initial database design. The project will be a simple web app for tracking processes and their outcomes within a matrix diagram, I am looking for a good way to store these in relational tables. Right now I am thinking I have a general table for Routines which the x...

Best way to create unique identities for distributed data that will be merged?

I have a centrally hosted database (MS SQL Server) and distributed clients save data to it over the Internet. When the Internet connection goes down the client starts storing new data locally into a SQLite instance. When the Internet connection comes back online the accumulated local data is moved to the central db (inserted). What's th...

duplicated foreign key constraints - reasons for or against

I've just come across a table in production which has 4 foreign key constraints. Two of the constraints are exact duplicates of the other two. ie fk1(a_id) references a(id) fk2(a_id) references a(id) fk3(b_id) references b(id) fk4(b_id) references b(id) I have never seen this before ... it strikes me as being quite wrong and my gut ...

SQL: Create new database options explanation..

When creating a new database in SQL SERVER, there are many options. Can any of you guys please help me in understanding all these options? Any explanation/links/help well appreciated. ...

Are usernames a valid candidate for a primary key?

I know surrogate primary keys are generally recommended over natural primary keys but are the arguments in favor of the surrogate primary keys valid when it comes to usernames? ...

Multiple App Instances, Multiple DBs or Interconnected Tables?

I am extending an e-voting application with a database. Consider multiple concurrent ballots. For each ballot, several configuration options are stored, and also the votes. The configuration tables are obviously very small, in the presence of a reasonable amount of concurrent ballots, but the votes table can grow to be extremely large....

How to create a unique order number

Algorithmically speaking, how could I generate a unique, human readable, reasonably lengthed - order number for SQL Server column. The only requirement is that it references the Customer Number and can be easily repeated over the phone. Something like: Customer Number - XXXXXXXX - XXXXXXXX RT65-XXXXXXXX-XXXXXXXX How would I genera...

[MySQL]: Is there a more 'efficient' way to link these tables?

I have three tables - Transaction: ID TimeStamp Discount: Code Amount Transaction_Discount: ID Code It's almost as basic as you can get. Is there a more 'efficient' way to link these tables together? ...

What is the best friend list table design?

What is the best friend-list table design (for performance)? Probably there should not be many rows for every frienship. What Facebook and Myspace is doing? (in MySQL) ...