foreign-keys

Why is SQLMetal.exe generating different results for SQL Compact 3.5 and SQL Express 2008 (foreign keys are missing).

Here's the story: I created a SQL Compact 3.5 database and used SQLMetal.exe to generate DataContext for it. It worked well, but soon I realized that it simply does not suit my needs so I decided to go for SQL Express 2008. I fired up the very same SQL script I used for the Compact to create schema and then fired up SQLMetal.exe tool. I ...

ElevateDB relational model do’s and dont’s

My company uses ElevateDB in one of our products. However, our database is just a bunch of tables. Recently, as more features are designed and more modules are added, we have found out our data is no longer “bunch of unrelated tables”, but it begins to be real data structure. I have no previous experience with ElevateDB, I worked with O...

Changing a relationship / foreign key in Entity Framework - not being persisted

Hey there, Ive got a WPF app, following the Model View ViewModel pattern, using the Entity Framework to interact with a SQL 2008 database. Problem: My problem is i can't change a foreign key value in the databse using EF. I have two entities: Site and Key. A Site can have many Keys on it. I would like to move a Key from one Site to a...

one primary key column foreign key to 2 other table columns.How to resolve data entry issue.

I have a requirement according to which I have to create a central Login system.We have 2 things Corporate and Brand each represented by tables "Corporate" and "Brand". When a corporate gets registered,corporateID is given,When a user under that corporate gets registered there is a table corporateuser in which corporateID is a foreign k...

To use a foreign key in MySQL or not to?

I have been coding with MySQL DBs for a couple years now and I have never used a foreign key. Now, I understand that a foreign key is like an ID on one table that corresponds with a primary key of another table. I have a user table on my site and probably around 10 other tables that all correspond with the primary key of my user table ...

Mysql: Programmatically remove all foreign keys

I'm working with a bit of a dodgey database at the moment, there are foreign keys defined in all the wrong places all over the place, I'd like to remove them all and then start from scratch. I don't wish to remove the column, just the foreign key relationships. How can I remove all foreign keys from an entire database? (Or table by tabl...

Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails

I'm having a bit of a strange problem, I'm trying to add a foreign key to one table that references another, but it is failing for some reason. With my limited knowledge of MySQL, the only thing that could possibly be suspect is that there is a foreign key on a different table referencing the one I am trying to reference. Here is a pict...

How to list out all Foreign Keys with "WITH NOCHECK" in SQL Server

Hi Does anyone know a query for listing out all foreign keys in a database with "WITH NOCHECK" description applied to it? (removing them will boost performance and stability). ...

Insufficient privileges when adding FK constraint (Oracle)

ALTER TABLE LAB_ADMIN_USER.TEST_TEMPLATE_ABBR ADD ( CONSTRAINT TEST_TEMPLATE_ABBR_R01 FOREIGN KEY (test_template_id) REFERENCES LAB_ADMIN.TEST_TEMPLATE (test_template_id) ON DELETE CASCADE) What is the most likely cause of 'ORA=01031: insufficient privileges' when executing the command above? In other words, what permission do...

Foreign Keys and Multi Model forms in Rails 2.3 - Bug or feature?

I am playing with making a blog. I would like to have several types of entries (a link to an interesting site + brief comment, a traditional blog post with title and body text, a picture... you get the idea). The idea seemed straight forward. An entry table/model with a the few details common to all those types (creation time and a litt...

Adding & Updating Foreign key in Entity Framework v1

Hello, I'm using .NET 3.5 SP1. I created entity 'Category', based on table 'category_table' and 'MyUser', based on table 'App_User_table'. CREATE TABLE category_table ( catg_id int, catg_name varchar(50), catg_description varchar(250) ) CREATE TABLE App_User_table ( userid int, username varchar(50), fullname varchar(50), catg...

MySQL table with only a varchar as a foreign key

Hi, I have a table with a single unique VARCHAR(512) field. I want to have another table hold a foreign key reference to this first table. Both tables use InnoDB. If I add a VARCHAR(512) key to the second table and add a foreign key constraint on it will the 512 bytes long data be held twice? If so, is there a way to hold only a refere...

Foreign Key Triggers in SQLite

SQLite comes with a utility, genfkey, that will generate triggers to enforce foreign key constraints. Here is the source. There is a README as well, just change previous url to f=sqlite/tool/genfkey.README (stackoverflow only letting me post one url) Two pairs of triggers are generated per FK: BEFORE INSERT and BEFORE UPDATE on refere...

How can I make a Django query for the first occurrence of a foreign key in a column?

Basically, I have a table with a bunch of foreign keys and I'm trying to query only the first occurrence of a particular key by the "created" field. Using the Blog/Entry example, if the Entry model has a foreign key to Blog and a foreign key to User, then how can I construct a query to select all Entries in which a particular User has wr...

Altering constraint delete action

I did this: ALTER TABLE `db`.`my_table` ADD CONSTRAINT FOREIGN KEY (`my_second_table_id`) REFERENCES `my_second_table` (`id`); I should have done this: ALTER TABLE `db`.`my_table` ADD CONSTRAINT FOREIGN KEY (`my_second_table_id`) REFERENCES `my_second_table` (`id`) ON DELETE SET NULL; Is it possible to ALTER this, or do I have...

Hibernate unidirectional one to many association - why is a join table better?

In this document (scroll down to the Unidirectional section): http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections it says that a unidirectional one-to-many association with a join table is much preferred to just using a foreign key column in the owned entity. My question i...

MySQL "set unique_checks", "set foreign_key_checks" vs. "alter table disable keys"

We're having a problem where a mysqldump script is spending 90% of it's time populating a small handful of the tables it deals with. Eliminating FK's and indexes eliminates the speed problem, but is not an acceptable solution. The dump script DOES have: /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET ...

Django: many-to-many relations, and through

I want to store which user invited another user to a group... but django is telling me this is ambigous and against the rules (which makes sense). groups.group: Intermediary model Group_to_Member has more than one foreign key to User, which is ambiguous and is not permitted. So how do I do this correctly? Maybe a generic rel...

Postgres: Are Nested Foreign Keys allowed?

I mean things like: FK1 -> 1FK2 -> 2PK Please, note that 1FK2 is a PK to FK1, but the 1FK2 is a FK to 2PK. So the key in the nested structure is a FK and a PK. An example: --- Like an interface CREATE TABLE q_content ( user_id SERIAL PRIMARY KEY, ---); ---- tables that refer to it CREATE TABLE questions ( user_id SERIAL refer...

Using relationship/foreign key with linq2sql?

Hi there, Can anyone help? I have a created a relationship between my Reservation(prim key) and Insurance(for key) tables and imported into linq2sql and checked my automatically created c# files and sure enough i have reservation.MyFieldNames etc etc PLUS reservation.Insurance which is my relationship but reservation.Insurance i can't ...