dbTalk Databases Forums  

Conditional unique constraint.

comp.databases comp.databases


Discuss Conditional unique constraint. in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stuck&Cold
 
Posts: n/a

Default Conditional unique constraint. - 04-18-2008 , 01:27 PM






Hi guys;

I have a hierarchical structure represented in a database with child
nodes having a foreign key to their parent. I'm wondering how to
create a constraint on uniqueness of a "name" attribute on that
entity, but the uniqueness should only be between siblings. In other
words, duplicate names are allowed as long as the instances don't
share the same parent.

Could someone in the know point me in the right direction?

Thanks in advance.

Reply With Quote
  #2  
Old   
Stuck&Cold
 
Posts: n/a

Default Re: Conditional unique constraint. - 04-18-2008 , 01:39 PM






Doh, after finding out you that unique constraints don't have to be
specified immediately following the column declaration, it turned out
to be simple enough. Simply adding a separate UNIQUE(parent,name)
constraint did the trick.

Reply With Quote
  #3  
Old   
Stuck&Cold
 
Posts: n/a

Default Re: Conditional unique constraint. - 04-18-2008 , 01:39 PM



Doh, after finding out you that unique constraints don't have to be
specified immediately following the column declaration, it turned out
to be simple enough. Simply adding a separate UNIQUE(parent,name)
constraint did the trick.

Reply With Quote
  #4  
Old   
Stuck&Cold
 
Posts: n/a

Default Re: Conditional unique constraint. - 04-18-2008 , 01:39 PM



Doh, after finding out you that unique constraints don't have to be
specified immediately following the column declaration, it turned out
to be simple enough. Simply adding a separate UNIQUE(parent,name)
constraint did the trick.

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

Default Re: Conditional unique constraint. - 04-18-2008 , 01:54 PM



On Apr 18, 8:27 pm, "Stuck&Cold" <stuck.and.c... (AT) gmail (DOT) com> wrote:
Quote:
Hi guys;

I have a hierarchical structure represented in a database with child
nodes having a foreign key to their parent. I'm wondering how to
create a constraint on uniqueness of a "name" attribute on that
entity, but the uniqueness should only be between siblings. In other
words, duplicate names are allowed as long as the instances don't
share the same parent.

Could someone in the know point me in the right direction?

Thanks in advance.
I think you are close to a solution. Think about it, what information
does two siblings share? That together with the name should be
unique.

HTH
/Lennart


Reply With Quote
  #6  
Old   
Lennart
 
Posts: n/a

Default Re: Conditional unique constraint. - 04-18-2008 , 01:54 PM



On Apr 18, 8:27 pm, "Stuck&Cold" <stuck.and.c... (AT) gmail (DOT) com> wrote:
Quote:
Hi guys;

I have a hierarchical structure represented in a database with child
nodes having a foreign key to their parent. I'm wondering how to
create a constraint on uniqueness of a "name" attribute on that
entity, but the uniqueness should only be between siblings. In other
words, duplicate names are allowed as long as the instances don't
share the same parent.

Could someone in the know point me in the right direction?

Thanks in advance.
I think you are close to a solution. Think about it, what information
does two siblings share? That together with the name should be
unique.

HTH
/Lennart


Reply With Quote
  #7  
Old   
Lennart
 
Posts: n/a

Default Re: Conditional unique constraint. - 04-18-2008 , 01:54 PM



On Apr 18, 8:27 pm, "Stuck&Cold" <stuck.and.c... (AT) gmail (DOT) com> wrote:
Quote:
Hi guys;

I have a hierarchical structure represented in a database with child
nodes having a foreign key to their parent. I'm wondering how to
create a constraint on uniqueness of a "name" attribute on that
entity, but the uniqueness should only be between siblings. In other
words, duplicate names are allowed as long as the instances don't
share the same parent.

Could someone in the know point me in the right direction?

Thanks in advance.
I think you are close to a solution. Think about it, what information
does two siblings share? That together with the name should be
unique.

HTH
/Lennart


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.