Nessa
01-17-2009, 11:08 AM
Hello all,
I'm new to database programming, and I'm trying to set up my first database. I'm having a bit of trouble implementing a couple of constraints, my mind seems to be stuck even though it must be simple :confused:
Firstly, I have a table where ColumnA (primary key) is referenced by ColumnB. What I want is basicly two things:
a) I want ColumnA and ColumnB to not be equal. This one was easy to implement, no trouble here.
b) If there is an entry where ColumnA equals, say, 2 and ColumnB equals, say, 5 then there should be no entry where ColumnA=5 and ColumnB=2. This is where I need your help. :(
Secondly, I have another table, let's call it TableA, where one column (Reference) references TableB's primary key (PK). I want to avoid entries in TableA where TableA's column "ID" would equal TableB's column "ID" of the corresponding row (that is, when I join them on "Reference"="PK"). I don't know how to do that, either.
Any help would be appreciated.
I'm using PostgreSQL.
Thanks in advance. :)
I'm new to database programming, and I'm trying to set up my first database. I'm having a bit of trouble implementing a couple of constraints, my mind seems to be stuck even though it must be simple :confused:
Firstly, I have a table where ColumnA (primary key) is referenced by ColumnB. What I want is basicly two things:
a) I want ColumnA and ColumnB to not be equal. This one was easy to implement, no trouble here.
b) If there is an entry where ColumnA equals, say, 2 and ColumnB equals, say, 5 then there should be no entry where ColumnA=5 and ColumnB=2. This is where I need your help. :(
Secondly, I have another table, let's call it TableA, where one column (Reference) references TableB's primary key (PK). I want to avoid entries in TableA where TableA's column "ID" would equal TableB's column "ID" of the corresponding row (that is, when I join them on "Reference"="PK"). I don't know how to do that, either.
Any help would be appreciated.
I'm using PostgreSQL.
Thanks in advance. :)