Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Tim
Starting Member
392 Posts |
Posted - 2003-04-27 : 02:34:07
|
| In tennis, a singles match;(A) can have zero or two players but not one player -- zero infers future match where players are unknown as yet(B) a player cannot be his/her own opponent.I get this far,M = primary key of the match entity.P = primary key of the player entity.now the match-player relationship...M,P doesn't enforce (A) but would enforce (B) if M,P was the composite primary keyM,P1,P2 doesn't enforce (B) but would enforce (A) if P1 and P2 were both mandatory.How to implement this with just the relational model? That is I can't have any triggers or stored procedures.It is driving me nuts.Edited by - tim on 04/27/2003 02:46:08 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-04-27 : 10:00:23
|
| Use B but set up a CHECK constraint saying P1 must not equal P2.EDIT: changed to allow for ZERO players:create table matches(M int primary key, P1 int, P2 int, CHECK ((P1 is Null AND p2 is Null) OR (P1 <> p2)))GOinsert into matches -- succeedsvalues (1,2,3)insert into matches -- failsvalues (2,2,2)insert into matches -- succeedsvalues (3, null, null)GODROP TABLE Matches- JeffEdited by - jsmith8858 on 04/27/2003 10:03:58 |
 |
|
|
Tim
Starting Member
392 Posts |
Posted - 2003-04-27 : 10:10:28
|
| Thanks Jeff, but is CHECK not a SQL Servver specific feature? (I don't know)I don't see how to do this in any datbase agnostic books on data modelling. That is, how is it possible at the logical level when DBMS implementation specifics cannot be assumed? |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-04-27 : 10:29:43
|
| The syntax might be specific to T-SQL (not sure either!) but I'm sure there must be an ANSI SQL standard for table row validation ...I did a quick search but didn't find anything right away ... I'm sure someone will help out.Or, I'm sure there's another way to do this ...- Jeff |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2003-04-27 : 12:12:17
|
| Check constraints is part of the ANSI sql specification and the syntax used by jsmith8858 is not specific for T-sql. |
 |
|
|
|
|
|
|
|