473,378 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Wird behavour of foreign keys

Hi list

As I'm new to this list please kick me in the right direction if this question
is better asked somewhere else.

I'm seing some wird behavoure regarding foreign keys.

My situation is this:
I have 3 tables:

pages
PK: page_id

page_group
pk: page_group_id
fk: pages(page_id) ON DELETE CASCADE, ON UPDATE NO_ACTION
fk: groups(group_id) ON DELETE CASCADE, ON UPDATE NO_ACTION

groups
pk: group_id

let's say I have the following data:

pages: page_group: groups:
page_id pg_id | page_id | group_id group_id
1 1 | 1 | 1 1
2 2 | 1 | 2 2

(I know this could be done more easy and the page_group table could be dropped,
but I did not make the design, I'm just struggling with it)

Now, if I move a group (say with id 1) from one page (page 1) to another (page
2)I do it by;
UPDATE page_group set page_id=2 WHERE page_group_id=1;

Now I have:

pages: page_group: groups:
page_id pg_id | page_id | group_id group_id
1 1 | 2 | 1 1
2 2 | 1 | 2 2

Now I have moved group 1 from page 1 to page 2. BUT if I delete page 1 then
page_group 1 and 2 are both delted, and so are the two groups.

This is not what I would expect, as I have moved group 1 to page 2.

Is this a BUG, or is it something that I'm doing wrong.
As i understand the ON UPDATE constraint on the foreignkey, it will only update
the foreign key if the value which it references is changed, which is not what
I'm doing.

Hope someone can help me, or tell me if it's a bug or not. Because I'm going
crazy here.

René Jensen

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #1
1 1330
Sorry, I cannot reproduce that behaviour. I guess there are more
triggers or rules in the schema than you are currently aware of.
Especially the deleting from groups is very suspicious.

what does \d for all these tables tell?
Jan

lu******@tbkol.dk wrote:
Hi list

As I'm new to this list please kick me in the right direction if this question
is better asked somewhere else.

I'm seing some wird behavoure regarding foreign keys.

My situation is this:
I have 3 tables:

pages
PK: page_id

page_group
pk: page_group_id
fk: pages(page_id) ON DELETE CASCADE, ON UPDATE NO_ACTION
fk: groups(group_id) ON DELETE CASCADE, ON UPDATE NO_ACTION

groups
pk: group_id

let's say I have the following data:

pages: page_group: groups:
page_id pg_id | page_id | group_id group_id
1 1 | 1 | 1 1
2 2 | 1 | 2 2

(I know this could be done more easy and the page_group table could be dropped,
but I did not make the design, I'm just struggling with it)

Now, if I move a group (say with id 1) from one page (page 1) to another (page
2)I do it by;
UPDATE page_group set page_id=2 WHERE page_group_id=1;

Now I have:

pages: page_group: groups:
page_id pg_id | page_id | group_id group_id
1 1 | 2 | 1 1
2 2 | 1 | 2 2

Now I have moved group 1 from page 1 to page 2. BUT if I delete page 1 then
page_group 1 and 2 are both delted, and so are the two groups.

This is not what I would expect, as I have moved group 1 to page 2.

Is this a BUG, or is it something that I'm doing wrong.
As i understand the ON UPDATE constraint on the foreignkey, it will only update
the foreign key if the value which it references is changed, which is not what
I'm doing.

Hope someone can help me, or tell me if it's a bug or not. Because I'm going
crazy here.

Rene' Jensen

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

--
#================================================= =====================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================= = Ja******@Yahoo.com #
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Olivier Crèvecoeur | last post by:
Hello, Excuse me for my poor english. I would kike know if create index on the foreign key it's necessary or if Oracle, are optimized for using foreign key whithout index. Best regards ...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
1
by: Vinodh Kumar P | last post by:
I understand the number of foreign keys allowed is restricted by the DBMS I use. In a general relational schema design perspective how many foreign keys a table shall have? If I have large number...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
2
by: Ian Davies | last post by:
I have created a database with about 17 tables. I have been creating foreign keys some of which have worked but when creating others I get the message below ************************* 1005...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
1
by: rbarber | last post by:
I have to synchronize 2 databases hourly but am having difficulty maintaining foreign key relations. These tables use auto-increment columns as primary keys, with child records in other tables...
1
by: apax999 | last post by:
Kinda new to SQL, using SQL Server 2005. I have some foreign keys in a couple of tables. I need to drop these tables, but can't since I'll get the error: Msg 3726, Level 16, State 1, Line...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.