foreign-keys

Is it possible to determine the table linked to by a foreign key?

I have a table containing a foreign key and I know the column name of that foreign key. Is it possible, using this information, to determine the table to which that key links? The reason for this is that the foreign key is dynamic and so I cannot determine the linked table in advance. ...

Mysql insert with foreign key referring to primary id

Let's say I hava a table object: id, primary key auto-increment obj_id, foreign key (object.id) val, integer Is it possible to insert a record with obj_id = id. Not having an error with foreign key constraint? Insert into object (val) values (123) ...

PostgreSQL : Transaction and foreign key problem

Hi all!!! I'm inserting a value in table A, that has a serial type as primary key. I wanna use the returned value of the query as a foreign key of table B... but I get this message: *ERROR: insert or update on table "tb_midia_pessoa" violates foreign key constraint "tb_midia_pessoa_id_pessoa_fkey" DETAIL: Key (id_pessoa)=(30) is not pre...

Primary and foreign key

Can we apply two primary keys in a table in anyway? ...

Can You Specify the Property Name of a Foreign Object in LINQ

Suppose that I have 2 tables: [User] - UserID - Username [Task] - TaskID - TaskName - TaskCreatedByUserID - TaskAssignedToUserID In the [Task] table, both of the ***UserID fields are foreign keys to the [User] table. So when I use the designer to create my LINQ models, I have access to 2 foreign [User] objects with proper...

Tips for build foreign keys into a legacy database

Hey, I've got a database that doesn't have any foreign keys. I've done some checks and there are a a fair few orphaned records. Its a pretty large database 500 + tables and I'm looking at the possibility of building the foreign keys back in. Other than trawling though every single table over time? Has anybody ever been through this ...

Is there a way to delete all foreign entities when i delete a record using NHibernate?

I recently began using Fluent Nhibernate for my data layer and have come across an issue. Whenever i want to delete a record that has multiple foreign key constraints, i have to create another class just to represent that database entity. That means that for something like a User record, which has relationships with many other tables, ...

Does a foreign key need to appear in children of children?

I have a set of tables with children of children, like so: Clients (PK ClientID) which is parent (one to many) to Property (PK PropertyID, FK ClientID) which is parent (one to many) to Property Detail (PK PropDetailID, FK PropertyID) and Case (PK CaseID, FK PropertyID). Should the foreign keys for the parent tables be repeated furth...

Rails Foreign Key Issue

Sorry if this question seems simple, I am very very new to Rails (just started learning a few days ago), but after consulting Google and "Agile Web Development with Rails" I can't find the answer. I have an issue with Rails 2.3.8 creating a foreign key on two models. My tables look like this: cars manuf...

Updating SQL Table In Enterprise Manager - Foreign Key Issues

I have a table with a whole bunch of FKs. Table Vehicles ----------- ColorID -> Color.ID MakeID -> Make.ID ModelID -> Model.ID etc... My issue is that I forgot a few columns and I need to add them. I can add them through right clicking on the table and choosing 'Design', but not if I want to make them NOT NULL, or delete a column. I...

Foreign Keys won't cascade in MySQL

I can't seem to get my cascade action going here. I've got two tables defined as the following. Can anyone tell me what's wrong? An update to system_rigs "id" won't cascade to the messages table. Messages Table CREATE TABLE `edr_messages` ( `message_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `rig_id` int(10) unsigned NOT NU...

Entity Framework Foreign Key Mapped to Same Table

This is not a duplicate of this post although the title is very similar. I am using EF4 with MSSQL Express 2008 R2 on VS2010. A simplified version of my schema is as follows: Table [Team]: Id (PK) Member1 Member2 Table [Person]: Id (PK) FirstName [Team].Member1 and [Team].Member2 are foreign keys pointing to [Person].Id. When ...

SQL Server table relationships practice

What is the recommended way in this situation: Customer ..* <-------------> 0..1 Car So there is a Customer table and a Car table, Customer can have zero or one Car, the Car can be linked to many Customer tables. Should I add a nullable CarID column to Customer or Should I create a Customer_Car_Map table containing CustomerID and Ca...

Can the same column have primary key & foreign key constraint to another column

Can the same column have primary key & foreign key constraint to another column? Table1: ID - Primary column, foreign key constraint for Table2 ID Table2: ID - Primary column, Name Will this be an issue if i try to delete table1 data? Delete from table1 where ID=1000; Thanks. ...

How to give 3 relations to same table in Cakephp

Hi i am new in cake php and can't solve the problem. The problem is I have a table like; id varchar(16) parent_id varchar(16) text text user_id bigint(20) is_deleted_by_user bit(1) is_deleted_by_us bit(1) who_deleted bigint(20) who_answ...

Hibernate, mapping of foreign keys that have been generated by a sequence in the parent table

I have a 1:n relation in the database and java objects that represent the relation with hibernate. The primary key of the parent table is generated with a database sequence, the child object uses the primary key of the parent object as foreign key. I create a new parent object including a set of new child objects. Then I try to persist ...

How to workaround mysql bug: Trigger not executed following foreign key UPDATE/DELETE

MySQL Bug #11472 confirms that when rows of a tableB are updated/deleted indirectly as a result of a FK constraint (relating tableA), triggers on tableB are not executed. How can I workaround this bug? I found a messy workaround, but would like to hear the SO communities suggestions as well. In this example joins has a FK to users a...

foreign key in google app's datastore

A quick question, Does google app's datastore support foreign key mapping, if yes, can anyone enlightened me XD, or share some link. thank you very much, ...

How can I make a foreign key only able to reference a subset of rows in the target table

I have a table with a primary key (lets call it "person"), and another table that references it (lets call it "grade", as in student grades). Table "grade" has field "grade.personid", which is a foreign key to "person.personid". Lets say "person" has field "person.type" as well (varchar with possible values of "student" or "teacher" for...

Recommended approach to merging two tables

I have a database schema like this: [Patients] [Referrals] | | [PatientInsuranceCarriers] [ReferralInsuranceCarriers] \ / [InsuranceCarriers] PatientInsuranceCarriers and ReferralInsuranceCarriers are identical, except for the fac...