473,549 Members | 3,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trigger problem where two tables reference each other's primary keys

Table "grps"
Column | Type | Modifiers
-------------+-----------------------------+--------------------------------
---------------------
grpsid | integer | not null default
nextval('"grps_ grpsid_seq"'::t ext)
grpsname | text | not null
memberofgrp | integer | not null default -1
dateadded | timestamp without time zone | not null default 'now'
addedby | integer | not null default 0
dateupdated | timestamp without time zone | not null default 'now'
updatedby | integer | not null default 0
outsidegrp | boolean | not null default 'f'::bool
active | boolean | not null default 't'::bool
notes | text |

Table "usrs"
Column | Type |
Modifiers
--------------------+-----------------------------+-------------------------
----------------------------
usrsid | integer | not null default
nextval('"usrs_ usrsid_seq"'::t ext)
reportsto | integer | not null default -1
grpsid | integer | not null default -1
titlesid | integer | not null default 0
departmentsid | integer | not null default 0
firstname | character varying(100) |
lastname | character varying(100) |
phone | character varying(25) |
fax | character varying(25) |
celphone | character varying(25) |
address1 | character varying(100) |
address2 | character varying(100) |
citiesid | integer | not null default 0
states_province sid | integer | not null default 0
postalcodeid | integer | not null default 0
countriesid | integer | not null default 0
email | character varying(255) |
password | character varying(255) | not null default '!'
revealcel | boolean | not null default
'f'::bool
revealemail | boolean | not null default
'f'::bool
outsideusr | boolean | not null default
't'::bool
dateadded | timestamp without time zone | not null default 'now'
addedby | integer | not null default 0
dateupdated | timestamp without time zone | not null default 'now'
updatedby | integer | not null default 0
active | boolean | not null default
't'::bool
notes | text |
in the usrs table, addedby and updatedby are self-referential to usrsid
grpsid refers to grpsid in grps

in the grps table, addedby and updatedby refer to the usrs table.

deletes trigger set default and updates cascade

when I update the usrs table ( any other table that has reference to the
usrsid column of usrs) no problem. when I update the grps table in any way,
I get

update grps set memberofgrp = 7 where grpsid = 6;
ERROR: constraint updgrpsupdatedb yusrsusrsid: table usrs does not have an
attribute usrsid

here is that constraint, generated by postgres at table creation and named
later:
CREATE CONSTRAINT TRIGGER "updgrpsupdated byusrsusrsid" AFTER UPDATE ON
"grps" FROM "usrs" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE
PROCEDURE "RI_FKey_cascad e_upd" ('updgrpsupdate dbyusrsusrsid', 'grps',
'usrs', 'UNSPECIFIED', 'updatedby', 'usrsid');

The web application that this serves as backend for can't be updating grps
unless a valide usrsid logged in, so I can be confident that the usrsid of
the updating/adding person will be in the usrs table, but I was hoping to
keep the referential integrity for consistency with the rest of the database
(and because I see it as a Good Thing) any ideas on the source of the bogus
error? Is it the cross-linking between the tables what is setting it off? Is
there a way to compensate for that?
Thanks,

Sean
Web Solutions That Work Developing custom web solutions designed
specifically to accomplish the unique objectives of our clients. Phone
503-639-2727 Fax 503-639-0807
Jul 19 '05 #1
0 4081

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

Similar topics

6
7639
by: Kenneth Osenbroch | last post by:
Hi. I want to create a trigger that only allows delete from table A if corresponding record in table B does not exist. Any idea on how this can be done? Thanks, Kenneth.
8
8588
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is the primary exchange for that symbol. Each symbol can only have one primary exchange. I am trying to write a insert/update/delete trigger that...
1
15392
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
5
11529
by: Dave Sisk | last post by:
Hey folks: I'm trying to do this: CREATE TRIGGER datawhse.emp_ti AFTER INSERT ON emp REFERENCING NEW AS n FOR EACH ROW MODE DB2ROW BEGIN DECLARE v_rrn DECIMAL(15,0);
7
2942
by: Ilan Sebba | last post by:
I am trying to add a record using SQL. My problem is that the primary keys are foreign keys, and these foreign keys are autonumbers. I therefore do not know the primary keys of the record I am trying to insert. I therefore do not think that I can use the sql "Insert Into" command. Here is a simplified illustration of my tables: ...
5
2352
by: Prabu Subroto | last post by:
Dear my friends... I am using SuSE Linux 9.1 and postgres. I am a beginner in postgres, usually I use MySQL. I have 3 tables : appointment, appointment0 and appointment1. the fields of table "appointment" are as follows: noapp* (int4):ID Number of appointment (PK)
3
3710
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code in the application, but I'd rather not! DDL for table and trigger below. TIA
6
3610
by: Jchick | last post by:
Im a newbie with a sql table in a MSDE database that contains fields of CustName, BrokerName, Type, Status. I am trying to write a trigger that does this: 1. When a new record in a table is added, I would like the selected fields to be copied to another table (call it Master). 2. If that Master table already contains a record where the...
13
6549
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables has no primary key. I'm having trouble expressing an update trigger that checks for existing rows, contemporary to the updated one, but...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.