database-relations

Conflicting desires in Database Design, with fields of two similar functions

Okay, so I'm making a table right now for "Box Items". Now, a Box Item, depending on what it's being used for/the status of the item, may end up being related to a "Shipping" box or a "Returns" box. A Box Item may be defective:if it is, a flag will be set in the Box Item's row (IsDefective), and the Box Item will be put in a "Returns" ...

How to combine cascading updates/deletes between SQL Server and NHibernate?

I am writing an application with a hand-crafted domain model (classes) and a hand-crafted data model (tables/relationships), and letting NHibernate take care of the mapping. Is it best to tell the database to perform cascading updates or deletes or to tell NHibernate to do it (cascade="all-delete-orphan")? Can they both be set up to do ...

Language features to implement relational algebra

I've been trying to encode a relational algebra in Scala (which to my knowlege has one of the most advanced type systems) and just don't seem to find a way to get where I want. As I'm not that experienced with the academic field of programming language design I don't really know what feature to look for. So what language features would...

Design 1-to-1 relationship DB tables?

A DB design question: when do you decide to use 1 to 1 relation tables? One of the places I see this is, for example, when you have a User and UserProfile table, people split them instead of putting all columns just in a User table. Technically, you can just put all the columns in one table since their relationship is 1-to-1. I know...

Do I need to define a new primary key field for each table?

Hi, I have a few database tables that really only require a unique id that references another table e.g. Customer Holiday ******** ******* ID (PK) ---> CustomerID (PK) Forename From Surname To .... These tables such as Holiday, only really exist to hold information regarding a Customer. Therefore, do I need to s...

Database Design: Storing the primary key as a separate field in the same table

Hi, I have a table that must reference another record, but of the same table. Here's an example: Customer ******** ID ManagerID (the ID of another customer) ... I have a bad feeling about doing this. My other idea was to just have a separate table that just stored the relationship. CustomerRelationship *************** ID CustomerID ...

Finding extra columns in a many to many relationship table

I wish to persist some extra data in a many-to-many relationship by having some extra fields in the association table. For instance, I would like to keep track of what role a user has in a network, such as 'member', 'moderator', 'admin' etc. I would also like to keep track of when he/she joined the network. Now, what I am looking for is ...

T-SQL Database Relationships PK FK Same Name!?

Scenario I have 3 database tables. One is for Images and the other two are People & Places. Since each person can have many images and each place can have many images, I want to have a ONE TO MANY Relationship between both people and images, as well as places and images. Question Does the foreign key have to be called the same name as...

Foreign keys and NULL in mySQL

Hi everyone, Can I have a column in my values table (value) referenced as a foreign key to knownValues table, and let it be NULL whenever needed, like in the example: Table: values product type value freevalue 0 1 NULL 100 1 2 NULL 25 3 3 1 NULL Tab...

Stock management of assemblies and its sub parts (relationships)

I have to track the stock of individual parts and kits (assemblies) and can't find a satisfactory way of doing this. Sample bogus and hyper simplified database: Table prod: prodID 1 prodName Flux capacitor prodCost 900 prodPrice 1350 (900*1.5) prodStock 3 - prodID 2 prodName Mr Fusion prodCost 300 prodPrice 600 (300*2) prodStock 2 - ...

C# (WPF): Database Relationship Viewer

I would like to create a WPF application in C# that can show visually, in a user interface friendly way, the relationships between tables from a database chosen from the application user (MS SQL Server, MS Access, Oracle, MySQL, etc.) and allow the editing of the relationships. For example, in Microsoft Access 2007 it is possible to do...

mysql many to many relationship

Been reading the tutorial How to handle a Many-to-Many relationship with PHP and MySQL . In this question I refer to the "Database schema" section which states the following rules: This new table must be constructed to allow the following: * It must have a column which links back to table 'A'. * It must have a column which links ...

Database design - doubt in mapping the relationships.

I am having confusion in designing the database. Its a Subscription based application : One Subscription can have multiple display devices. While Subscribing, the user will be asked to select one of the displayed devices. Keeping this in mind, I've come up like this: Is the above approach correct? Should the USER_SUBNS.DISP_DEV_...

Create T-SQL Constraint to prevent x amount of duplicate records in table?

In table A I have 2 columns: ID (int, PK) MaxUsers (int) In table B I have 2 columns: ItemID (int) UserID (int) The number of records in table A with matching ItemID's cannot exceed the MaxUsers value. Is it possible to write a T-SQL Table Constraint so that it's not physically possible for this to ever happen? Cheers! Curt ...