foreign-key-relationship

Database Design - Column In One Table References Two Tables

Here is an example of what I have (take Stack Overflow). I have 2 tables, Questions and Answers. I also have a Comments table. The Comments table will reference both Questions and Answers. How should I set up the database? Have 2 columns in Comments, a QuestionId and AnswerId. Have one table for both Questions and Answers? Have ...

Rails references...

Let's say that you have a foreign key called COMPANY_ID in the table PERSON. In the model PERSON, can you write? validates_presence_of :company_id or validates_presence_of :company or both? Which is the preferred and why? ...

Retrieve DataTable info for a table in SQL Server

I need to get the column names, primary keys, foreign keys, and other schema info. The DataTable class seem to contain all of those. Below is the current code I got so far. With it I could retrieve all info except the foreign keys. I'm expecting them to be defined in DataTable.Constraints but they are not. This is my current code: ...

SQL table normalization: Simple question about restricting record participation in a many to many relation

If you have the following tables and relations: A Product table A Price Point table (one or more prices for a product) A Version table (groups of products sold in the same area) and the constraint that only one product price can exist in any given version. How would you construct the tables to reflect the constraints? To illustrate ...

Foreign key relationship with composite primary keys in SQL Server 2005

I have two tables Table1(FileID,BundledFileID,Domain) and Table2(FileID,FileType,FileName). In Table2 FileID and FileType are the composite primary key. I want to create a foreign key relationship from Table1.FileID to Table2. Is it possible to do this? Then how plz help. I am using SQL Server 2005 ...

Database tables, one table referencing multiple unrelated tables

This question has come up a few times in various forums in my searching, but none have provided a concise resolution. If I have the following tables: User +- id +- username +- password Article +- id +- title +- content and I want to join them in order to determine who created what articles, I could simply add the column user_id to A...

ActiveRecord relation using an array of foreign keys

Hi, Is that possible to establish a relationship between Tree and Branch such as: class Tree < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :tree end But with an array of foreign keys branch_ids stored in Tree? I know it's the opposite of the default process, but I want to do so (just fo...

MySQL foreign key to another foreign key

Hi. The idea is quite simple: i have three (or more) tables - master_tbl (id, something, somethingelse) - tbl2 (id, ....) - tbl3 (id, ....) Now what i want is a foreign key relationship, such as tbl3.id would point to tbl2.id and tbl2.id would point to master_tbl.id - all foreign keys are ON UPDATE CASCADE and ON DELETE CASCADE. What ...

Django - How to save and continue editing when adding a new user from related model?

Is it possible to get a save and continue to edit functionality on the creation of a user when clicking on the "+" in a related model? for example here's a model: class Example(models.Model): user = model.ForeignKey(User) ... ... When in the Add/Edit admin screen for Example objects when a user wants/needs to add a new user t...