dbTalk Databases Forums  

Schema Relationship Question

comp.databases.theory comp.databases.theory


Discuss Schema Relationship Question in the comp.databases.theory forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JamesHoward
 
Posts: n/a

Default Schema Relationship Question - 10-03-2007 , 04:44 PM






I have a set of predefined constants with a set of predefined
relationships and am looking for a way to link them if possible to
ensure data integrity.

An example would be if I wanted to keep track of programs and I have a
table Programs with rows operating system type and programming
language. If both operating system type and programming language are
foreign keys to reference tables (just tables with a primary key and a
name to the element they are referencing) is there a way to ensure
data integrity for possible nonsensical pairings such as programming
language c# and operating system unix?

Thanks in advance,
Jim Howard


Reply With Quote
  #2  
Old   
JOG
 
Posts: n/a

Default Re: Schema Relationship Question - 10-03-2007 , 07:15 PM






On Oct 3, 10:44 pm, JamesHoward <James.w.How... (AT) gmail (DOT) com> wrote:
Quote:
I have a set of predefined constants with a set of predefined
relationships and am looking for a way to link them if possible to
ensure data integrity.

An example would be if I wanted to keep track of programs and I have a
table Programs with rows operating system type and programming
language. If both operating system type and programming language are
foreign keys to reference tables (just tables with a primary key and a
name to the element they are referencing) is there a way to ensure
data integrity for possible nonsensical pairings such as programming
language c# and operating system unix?

Thanks in advance,
Jim Howard
Well, those non-viable pairings are part of your data. You could have
an ugly hard coded check constraint, or alternatively create a table
containing those disallowed pairings, and check select against it on
any insertion into your programs table. I'd check out the particular
flavour of RDBMS you are using on google for appropriate syntax. Good
luck.



Reply With Quote
  #3  
Old   
David Portas
 
Posts: n/a

Default Re: Schema Relationship Question - 10-03-2007 , 07:27 PM



"JamesHoward" <James.w.Howard (AT) gmail (DOT) com> wrote

Quote:
I have a set of predefined constants with a set of predefined
relationships and am looking for a way to link them if possible to
ensure data integrity.

An example would be if I wanted to keep track of programs and I have a
table Programs with rows operating system type and programming
language. If both operating system type and programming language are
foreign keys to reference tables (just tables with a primary key and a
name to the element they are referencing) is there a way to ensure
data integrity for possible nonsensical pairings such as programming
language c# and operating system unix?

Thanks in advance,
Jim Howard

That could be four tables for example. The constraint you refer to would be
a referential constraint between Programs and ValidPrograms.

Programs {os, language}
ValidPrograms {os, language}
OS {os}
Language {language}

--
David Portas





Reply With Quote
  #4  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Schema Relationship Question - 10-04-2007 , 04:09 PM



On Oct 3, 8:15 pm, JOG <j... (AT) cs (DOT) nott.ac.uk> wrote:
Quote:
On Oct 3, 10:44 pm, JamesHoward <James.w.How... (AT) gmail (DOT) com> wrote:

I have a set of predefined constants with a set of predefined
relationships and am looking for a way to link them if possible to
ensure data integrity.

An example would be if I wanted to keep track of programs and I have a
table Programs with rows operating system type and programming
language. If both operating system type and programming language are
foreign keys to reference tables (just tables with a primary key and a
name to the element they are referencing) is there a way to ensure
data integrity for possible nonsensical pairings such as programming
language c# and operating system unix?

Thanks in advance,
Jim Howard

Well, those non-viable pairings are part of your data. You could have
an ugly hard coded check constraint, or alternatively create a table
containing those disallowed pairings, and check select against it on
any insertion into your programs table. I'd check out the particular
flavour of RDBMS you are using on google for appropriate syntax. Good
luck.
better is a table of allowed pairings and a Foreign key constraint
(IMHO)

Ed



Reply With Quote
  #5  
Old   
JamesHoward
 
Posts: n/a

Default Re: Schema Relationship Question - 10-05-2007 , 12:43 PM



Thanks for the answers. It sounds like the best solution between
allowed pairings and disallowed pairings comes down to how much data
you will have to enter. If one of those is dense in a large possible
data space then it wouldn't be ideal to enter that much manual data.

I think I am going to go for the disallowed pairings in this case as
it is less data to enter.

Jim


Reply With Quote
  #6  
Old   
David Portas
 
Posts: n/a

Default Re: Schema Relationship Question - 10-06-2007 , 01:55 PM



"JamesHoward" <James.w.Howard (AT) gmail (DOT) com> wrote

Quote:
Thanks for the answers. It sounds like the best solution between
allowed pairings and disallowed pairings comes down to how much data
you will have to enter. If one of those is dense in a large possible
data space then it wouldn't be ideal to enter that much manual data.

I think I am going to go for the disallowed pairings in this case as
it is less data to enter.

Check the features of your DBMS product first. Some SQL DBMSs don't support
multi-table constraints other than foreign keys. If that's the case with
your DBMS then you may have to resort to procedural code to enforce the rule
about disallowed pairings. On the other hand, the rule for valid pairings
CAN be implemented using only a foreign key.

--
David Portas




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.