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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 uniqueness of names

Author  Topic 

cool
Starting Member

2 Posts

Posted - 2007-08-07 : 15:00:09
hi

am new to sql...i need to write a query ..it is like two teams can play more than 1 game but on different dates..


so if i create the table like this

Create Table Games( TeamName1 char(30),
2 numGoals1 int,
3 TeamName2 char(30),
4 numGoals2 int,
5 play_date char(10),
6 primary key(TeamName1,TeamName2,play_date),
7 Check(TeamName1!=TeamName2)
8 );

this violates the constraint if i give the two teams on the same date..how to give the condition such that it checks for the violation of condition if the team names are interchanged.. for eg

if i give the values as
Insert Into Games values('chelsea',1,'arsenal',2,'17-1-2000');
and
Insert Into Games values('arsenal',1,'chelsea',2,'17-1-2000');


the above should violate the constraint ..how to do it

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-08-07 : 15:39:08
You could add a check constraint to force them to enter the the team names in order by name. Then you would have only one possible way to enter the data.
check ( TeamName1 < TeamName2 )

CODO ERGO SUM
Go to Top of Page

cool
Starting Member

2 Posts

Posted - 2007-08-07 : 17:01:37
thank u
Go to Top of Page
   

- Advertisement -