473,734 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

refential integrity to multiple tables ??

HI,

let's say i have a tansaction table called TRANSACTION (transaction_id ,amount,type,ty pe_id)

Let's say a transaction can have multiple types: TYPE1, TYPE2 for example.

EACH type has his own definition and his own table.

Every transaction has a type that could be type1 or type2 that's why if the type is TYPE1 i want to make a referential integrity to the TYPE1_TABLE and if the type is TYPE2 i want to make a referential integrity to the TYPE2_TABLE.

IS IT POSSIBLE TO DO THAT???

I made a turn around to this problem by creating two tables:
- table TYPE1_TRANSACTI ON (type1_id,trans action_id)
- table TYPE2_TRANSACTI ON (type2_id,trans action_id)

But this does not seem so right for me ??

thx for any help


---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
Nov 12 '05 #1
3 2563
Almost everything is possible if you accept to write your own triggers
and trigger functions. But there is no standard solution to this
problem.

There are of course inherited tables, but in the current
implementation, foreign key constraints doesn't work very well with
them (making them completly worthless IMO). That is going to change in
a future release according to the docs, but for now, table inheritance
is not the way to go in your case. Triggers are.

Regards
Erik
let's say i have a tansaction table called TRANSACTION
(transaction_id ,amount,type,ty pe_id)

Let's say a transaction can have multiple types: TYPE1, TYPE2 for
example.

EACH type has his own definition and his own table.

Every transaction has a type that could be type1 or type2 that's why
if the type is TYPE1 i want to make a referential integrity to the
TYPE1_TABLE and if the type is TYPE2 i want to make a referential
integrity to the TYPE2_TABLE.

IS IT POSSIBLE TO DO THAT???

I made a turn around to this problem by creating two tables:
- table TYPE1_TRANSACTI ON (type1_id,trans action_id)
- table TYPE2_TRANSACTI ON (type2_id,trans action_id)

But this does not seem so right for me ??

thx for any help


_______________ _______________ _______________ _______________ ____________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #2
On Wednesday 08 October 2003 06:53, Nagib Abi Fadel wrote:
HI,

let's say i have a tansaction table called TRANSACTION
(transaction_id ,amount,type,ty pe_id)

Let's say a transaction can have multiple types: TYPE1, TYPE2 for example.

EACH type has his own definition and his own table.

Every transaction has a type that could be type1 or type2 that's why if the
type is TYPE1 i want to make a referential integrity to the TYPE1_TABLE and
if the type is TYPE2 i want to make a referential integrity to the
TYPE2_TABLE.

IS IT POSSIBLE TO DO THAT???


You're looking at it the wrong way around, but in any case there are still
problems.

transaction_cor e(trans_id, trans_name, trans_type)
transaction_typ e1(tt1_core_id, tt1_extra1, tt1_extra2...)
transaction_typ e2(tt2_core_id, tt2_extra1, tt2_extra2...)

And have tt1_core reference trans_id (not the other way around). Do the same
for tt2_core and we can guarantee that the two transaction types refer to a
valid trans_id in transaction_cor e.

Now, what gets trickier is to specify that tt1_core should refer to a row in
transaction_cor e where trans_type=1.
Ideally, we could have a foreign-key to a view, or specify a constant in the
FK definition. We can't so you have to repeat the type field in
transaction_typ e1/2 and keep it fixed for every row.

HTH
--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3

--- Richard Huxton <de*@archonet.c om> wrote:
On Wednesday 08 October 2003 06:53, Nagib Abi Fadel
wrote:
HI,

let's say i have a tansaction table called

TRANSACTION
(transaction_id ,amount,type,ty pe_id)

Let's say a transaction can have multiple types:

TYPE1, TYPE2 for example.

EACH type has his own definition and his own

table.

Every transaction has a type that could be type1

or type2 that's why if the
type is TYPE1 i want to make a referential

integrity to the TYPE1_TABLE and
if the type is TYPE2 i want to make a referential

integrity to the
TYPE2_TABLE.

IS IT POSSIBLE TO DO THAT???


You're looking at it the wrong way around, but in
any case there are still
problems.

transaction_cor e(trans_id, trans_name, trans_type)
transaction_typ e1(tt1_core_id, tt1_extra1,
tt1_extra2...)
transaction_typ e2(tt2_core_id, tt2_extra1,
tt2_extra2...)

And have tt1_core reference trans_id (not the other
way around). Do the same
for tt2_core and we can guarantee that the two
transaction types refer to a
valid trans_id in transaction_cor e.

Now, what gets trickier is to specify that tt1_core
should refer to a row in
transaction_cor e where trans_type=1.
Ideally, we could have a foreign-key to a view, or
specify a constant in the
FK definition. We can't so you have to repeat the
type field in
transaction_typ e1/2 and keep it fixed for every row.

HTH
--
Richard Huxton
Archonet Ltd


Actually a type1_id can have mutiple corresponding
transaction_ids (same thing for type2) that's why i
created the tables as follows:

create table transaction(
transaction_id serial P K,
amount int,...)

create table TABLE_TYPE1(
type1_id serial P K,
....
)

create table transaction_typ e1(
type1_id int,
transaction_id int
)
for example we can have the following possible entries
in table transaction_typ e1:
type1_id,transa ction_id
100,101
100,102
100,103
200,312
200,313
200,314
200,315

Same thing for type 2.

I can also add that a transaction id can be of type1
or (exclusive) of type2 and never of two types at the
same time.


_______________ _______________ ____
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #4

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

Similar topics

3
2743
by: Rodney King | last post by:
Hi, I am supporting an application that was converted from ACCESS to SQL Server 2000. My question focuses on two particuliar tables. The parent table has 14000 rows while child table has over 9 million rows. Referential integrity is set up between the two tables. The parent table has a composite primary key of: CustomerId (int) LocationId (int) ProductId (int)
8
3569
by: DB2 Novice | last post by:
I am trying to use DB2 Control Centre (version 8.2) to load one flat file into multiple tables. However, I don't see the options in Control Centre that allows that. Anyone knows how to do this? DB2 Novice
4
2473
by: Heather | last post by:
I am creating a database with a backend and frontend. The backend consists of a Products table and many other tables. The products table in an .mdb file by itself is over 2 meg. I thought about putting the products table in a file by itself and all the other tables in another file. I anticipate there will be a need for changes in the other tables and since communication is over the internet, having the products table in a different file...
9
7031
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the lookup tables are not likely to change. Question 1: Should I include them in the backend (with rest of data) or the frontend?
11
12694
by: dixie | last post by:
If I wanted to be able to copy all of the tables in an existing database called Original.mde to another database called New.mde from a button click event in Original.mde, is there an easy way of coding it without naming every single table in Original.mde. I am looking for a way of updating a database on site without needing to access the database window and import the existing tables into a new empty database. dixie
5
1468
by: Krechting | last post by:
Hi All, I have a db with three tables which have a relationship. The problem is that when I add a record to the ForAction table it will automatically add a record to the Originator table but not to the RFI table. I do not want access to add a record to the Originator table but only to the ForAction table. Is this possible?
1
18250
by: Brian | last post by:
I have a dataset containing 2 tables. I need to fill a datagrid using data from both of these. If I could create a SQL Statement to fill the datagrid, it would look like this: SELECT fields.fieldname, fieldvalues.value FROM fields, fieldvalues I am having trouble finding documentation explaining how to populate
6
4716
by: heyvinay | last post by:
I have transaction table where the rows entered into the transaction can come a result of changes that take place if four different tables. So the situation is as follows: Transaction Table -TranId -Calc Amount Table 1 (the amount is inserted into the transaction table) - Tb1Id
4
3297
by: knix | last post by:
I have this access project consisting of multiple tables that are linked together in a relationship. I would like to migrate the consolidated information through appending in a datasheet form or importing the gathered information . Can anyone please give solutions with my problem? Can I make a datasheet form (consisting fields from multiple tables that are linked together with relationships) in ms access which I could paste append or insert...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8778
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9453
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9184
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4551
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4814
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.