foreign-keys

MySQL not showing foreign keys that are also primary keys

Navicat does not show primary keys which are also foreign key on table report as foreign keys. Why? I gave the image explaining the situation: ...

Save entity with relationship in Entity Framework / ASP.NET MVC 2

I have been dealing with this for at least two days now. I don't have a book available to reference, and I cannot for the life of me find an explanation of how this is supposed to work. What I am trying to do is a simple operation: Load a create form populated with 3 dropdownlist elements which reference other tables Fill out the form...

CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [Lead__c]

Hi there, I am getting an error message when I try to instert a custom object into an exisiting lead object. List<Lead> leads =[select Id from Lead where Email =:lead.Email ]; if(leads.size()>0) { Lead existing_lead = new Lead(Id = leads[0].id); social_account.Lead__c = existing_lead.Id; //social_account is a custom object that ...

Database Design - How to enforce a foreign key constraint on a table with a Surrogate Key

My table schema is something like this 1. Master table : Clause Columns ClauseID = surrogate pk (identity) ClauseCode = nvarchar user specified value Class = nvarchar FK to a master class table etc... ClauseCode + Class = candidate key for this table 2. Master table : GroupClause Columns GroupClauseID = surrogate pk (identi...

Foreign key referencing a view in Oracle

Hi everyone, I'm attempting to reference a view with a foreign key but I am getting this error: "Error: ORA-02270: no matching unique or primary key for this column-list" However, I have created a primary key on this view and verified it in the Constraints tab in TOAD. This is the table I'm attempting to create: CREATE TABLE QUESTI...

Disabling foreign key constraint, still can't truncate table? (SQL Server 2005)

I have a table called PX_Child that has a foreign key on PX_Parent. I'd like to temporarily disable this FK constraint so that I can truncate PX_Parent. I'm not sure how this goes however. I've tried these commands ALTER TABLE PX_Child NOCHECK CONSTRAINT ALL ALTER TABLE PX_Parent NOCHECK CONSTRAINT ALL (truncate commands) ALTER ...

How do I setup one-to-one relationship in nhibernate? (currently doesn't return the foreign object)

I have a User, some of which are an employee. This is a one-to-one relationship and not all users are employees. When I get a user it doesn't seem to be bring back the employee information it just has it marked as null. I thought I have got my head around nhibernate but I have tried playing with so many properties on the mapping files a...

Kohana v3 ORM Select and Where clause based on different table.

Hi I need to do something like this: $hours->task->job->where('group_id' , '=' , $num)->find_all(); This would return job information. Is there any way to tell orm to return the information from the $hours table instead? ...

MySQL multiple Id lookups

I'm trying to add a full text search to a system. The query I want to write needs to involve multiple lookups followed by the search (if that's even possible). I've got a table of teachers and a table of subjects. teacherProfile teacherId [int] - primary key subjectOneId [int] subjectTwoId [int] subjectThreeId [int] teacherBiography [t...

Django complex filtering of related objects

Hello, I've faced with following issue, basically I do it like this: class Account(models.Model): TraffPerMonth = models.IntegerField(default=0) Tariff = models.ForeignKey('Tariff') class Tariff(models.Model): InetTraff = models.IntegerField(default='0') and here is the select: for user in Account.objects.all(): t_traf...

Entity Framework and Silverlight foreign key objects

I'm trying to add a new instance of an object to my data source, and there's a foreign key defined for ListUserName. The CurrentUser object is the right type to put into it and is populated correctly, but it blows up on me when submitting it to the data source. This is all pulled from a Domain service class into the Silverlight app. L...

django : models with reverse foreignkeys?

I've got a chicken and egg problem here. Firstly I've got a userprofile class which builds upon the default user model of django. class UserProfile(models.Model): def __unicode__(self): return self.user.username user = models.OneToOneField(User, unique=True) exam = models.ForeignKey('questions.Exam', null=True) Nex...

rails relationship using unique key

Hi, I have 2 entities: Table/Entity 1: RetrievedDataRecords Columns: id record_key Table/Entity 2: SourceKeys Columns: id key_name (unique key) I cant alter these tables for legacy reasons, but want rails relationship between RetrievedDataRecord and SourceKey using record_key and key_name (they are the same key) in RetrievedDat...

Why 'foreign key constraint fails' when foreign key exists?

I have a simple query UPDATE `t_timecard_detail` SET `timeoff_request_id` = 'adad8e0d-c22b-41c3-a460-6cf982729299' WHERE `id` = 'cfc7a0a1-4e03-46a4-af89-069a0661cf55'; which gives this error ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`demo1_timeapp`.`t_timecard_detail`, CONSTRAINT `timeoff...

Circular dependencies in foreign keys: use it or avoid it?

My application loads lots of data from a database into a complex data structure. The in-memory data structure ressembles the structure of the database, which means that if the database contains the following tables: table A, key is A1 table B, key is B1, one of the columns is a foreign key to [the key of] table A table C, key is C1, o...

MYsql innodb foreign key between different databases

I would like to know if it's possible in innodb in mysql to have a table with foreign key that references another table in a different database ? And if so, how this can be done ? ...

SQL Server: Howto get foreign key reference from information_schema ?

In SQL Server, how can I get the referenced table + column name from a foreign key? Note: Not the table/column where the key is in, but the key it refers to. Example: When the key [FA_MDT_ID] in table [T_ALV_Ref_FilterDisplay]. refers to [T_AP_Ref_Customer].[MDT_ID] such as when creating a constraint like this: ALTER TABLE [dbo].[T_...

Compound foreign key with nullable column

In the following table, is there a way to ensure PreviousID always references an ID in a row with a matching ParentID, or, if ParentID is null, it is also null in the referenced row? CREATE TABLE MyTable ( ID int not null identity(1,1) primary key, ParentID int null foreign key references MyTable (ID), PreviousID int null foreign ...

Is is possible to get new values for Id (IDENTITY) before inserting data in a table ?

Is is possible to get new values for Id (IDENTITY) before inserting data in a table ? Is is possible to write something like that : INSERT INTO Table1 SELECT *GET_NEW_IDENTITY*, Field1, Field2 FROM Table2 I need the values of Id because I want to insert data in Table1 and, just after, insert data in another table which has a foreign ...

SQL Server keys and foreign keys

If I have a primary key in table A and in table B of the same database (table B has its own primary key) I create a relationship with the primary key in table A so that a column in table B is the foreign key, does it mean that the primary key data created in the primary key column of table A will also be added to table B by virtue of it ...