foreign-key-relationship

SQL 2000: T-SQL to get foreign key relationships for a table

Similar but NOT IDENTICAL to SQL Server 2000 - Query a Table’s Foreign Key relationships I need a T-SQL statement that will work SQL 2000 that given a table name, will return the foreign key relationships for that table e.g. Table MyFristTable has a foreign key to MySecondTable, where MyFirstTable.ColA must be in MySecondTable.ColB. I'...

Entity framework Update fails when object is linked to a missing child

I’m having trouble updating an objects child when the object has a reference to a nonexising child record. eg. Tables Car and CarColor have a relationship. Car.CarColorId >> CarColor.CarColorId If I load the car with its color record like so this var result = from x in database.Car.Include("CarColor") where x.CarId = 5 ...

Should I use a Foreign Key to Show Tree Relationship in SQL

I am trying to model a tree relationship in a table. For instance, there are "Categories" and categories can themselves be inside a Parent category. My schema is: id int PRIMARY KEY, parent_id int, name My question is, should I label the parent_id column as a Foreign key? Foreign implies "outside" and not self-referencing. Is ther...

Dictionary table relationships (MS SQL 2005)

I have table named 'Dictionary' with columns as follow: ID bigint TYPE varchar (200) ITEM varchar (200) Table is used by various tables as simple dictionary / lookup. Eg it stores countries, titles, business type lists. TYPE column keeps info about type of dictionary , ITEM is dictionary string value. All works well but I ha...

does the order a composite key is defined matter?

I have a table with (col1,col2) as a composite primary key. create table twokeytable(col1 int,col2 int,constraint twokeytable_pk primary key (col1,col2)); and another table with col3,col4 collumns witha composite foreign key(col3,col4) which references the(col1,col2) primary key. For some processing I need to drop the foreign key an...

nhibernate parent/child one-to-one mapping

I have two classes: public class Code { public virtual Guid CodeId { get; set; } public virtual string CodeValue { get; set; } public virtual Guid EntryId { get; set; } } public class Entry { public virtual Guid EntryId { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { ...

What to use as foriegn key if no match in the other table - MySQL

I am working on an attendance/overtime module for a schedule web app. The idea is that there is a table in MySQL of shifts, each shift having a start and end time. The manager will choose a shift and make an entry into the attendance table specifying whether the employee was early/late/left early/worked overtime. That entry in the attend...

Linq to sql causing foreign key constraint errors

Here is the revelant code. TournamentTeam newTeam = new TournamentTeam(); TournamentTeams.InsertOnSubmit(newTeam); SubmitChanges(); TournamentParticipant newSignup = new TournamentParticipant { CheckedIn = false, TournamentID = tournamentId, UserID = participant...

Cannot retrieve user object from foreign key relationships using Linq to Entities statement

Hi, I'm trying to retrieve a user object from a foreign key reference but each time I try to do so nothing gets returned... My table is set up like this: FBUserID long, UserID uniqueidentifier so I have my repository try to get the User when it's provided the FBUserID: public User getUserByFBuid(long uid) { User...

How to select an object through a foreign key

If I have a table with a primary key (AccLinkID) and a foreign key (aspnet_Users UserID), how can I select the object that the foreign key points to using Linq to Entities. User myUser = _myDB.AccLinkSet.Where(user => user.LinkID == linkId).FirstOrDefault().aspnet_Users; did not work... anyone have any ideas? ...

How to alter table

CREATE TABLE [dbo].[INVS_ITEM_LOCATIONS]( [DEPARTMENT_CODE] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [IM_INV_NO] [numeric](10, 0) NOT NULL, [LOCATION_CODE] [varchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [CURR_QTY] [numeric](10, 0) NOT NULL CONSTRAINT [DF__INVS_ITEM__CURR___1352D76D] DEFAUL...

Postgres: problem with FK contraint

How can I solve FK contraint? With trigger or something else? #IF "DELETE FROM human where name='a';", error due to the FK contraist. # If the error, I want in the order: # FIRSTLY. DELETE FROM address where name='a'; # SECONDLY. DELETE FROM human where name='a'; DROP TABLE human; DROP TABLE address; CREATE TABLE human( name...

Retrieving Items and values from Foreign Key Table in ASP.NET MVC using LINQtoSQL

Our team is currently working on a large project which makes heavy use of foreign key tables as they are used on our TeamMember Management Webapp. Basically, one TeamMember can be in a Team, in an Area and a TeamArea (the latter for editing and rights management). My main goal is focused on retrieving the data for showing these FK Fiel...

Fluent NHibernate: foreign key not null problem

I have the following domain classes: public class Installation : Entity<Installation> { public virtual string Name { get; set; } public virtual IList<Institution> Institutions { get; set; } public Installation() { Institutions = new List<Institution>(); } } public class Institution : Entity { pub...

Limiting the scope of a ForeignKey relationship?

I'm developing a portfolio application. Within this application, I have a model called "Project" which looks something like this: class Project(models.Model): ... images = models.ManyToManyField(Image) ... so, basically, this Project can contain a set of images (any of these images may belong to another Project as well). ...

Activerecord, 'foregin_key' has to be a combination of 2 fields

I want a has_many relationship described below class User < ActiveRecord::Base has_many :mcollections, :foreign_key=>'obj_id' end Below is definition of table mcollections create table mcollections ( id int not null auto_increment, obj_id varchar(255) not null, category ...

How do I relate two fields with Ruby on Rails?

Just starting to use Ruby on Rails to see what its like. I have a user model with an id and a post model with an adderId. The adderId of the post model should be the user id of the user that created it. How can I relate these with Ruby on Rails? ...

SQL foreign keys with multiple tables

If I have three tables: music_genres ----------- music_type_id genres [other unique fields] minerals -------- mineral_id mineral [other unique fields] verbs ----- verb_id verbs [other unique fields] and these are populated with: rock jazz funk punk rock boulder stone shale rock wobble shake vibrate Now let's say I was displayin...

When to use "ON UPDATE CASCADE"

Hi All, I use "ON DELETE CASCADE" regular but never use "ON UPDATE CASCADE" as I am not so sure what situation it will be useful. For the sake of discussion let see some code. CREATE TABLE parent ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ); CREATE TABLE child ( id INT NOT NULL AUTO_INCREMENT, parent_id INT, I...

Following a foreign-key of a commented item in a Django Queryset

Dear all, I'm working on a Django application allowing one to comment either a Text, its Paragraphs or the comments themselves. I'm using the Comment app bundled with Django, and A Text class instance is made up of Inline Paragraph class instances. I'm desperately looking for a way get back a QuerySet/List of all the Comments related d...