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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Create custom constraint

Author  Topic 

librarocks
Starting Member

2 Posts

Posted - 2009-09-03 : 10:33:00
This is the create Table: data1 and data2 are not relevant to the problem but I have them here since they are in the orignal db.

CREATE TABLE [dbo].[temp3](
[id] [uniqueidentifier] NOT NULL,
[data1] [uniqueidentifier] NOT NULL,
[data2] [uniqueidentifier] NOT NULL,
[isValid] [bit] NULL,
CONSTRAINT [PK_temp3] PRIMARY KEY CLUSTERED
(
[id] ASC,
[data1] ASC,
[data2] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


So what I want is:

Valid input:

Guid1 , Guid2, Guid3, 1
Guid1 , Guid4, Guid3, 0
Guid1 , Guid4, Guid5, 0

Invalid Input:

Guid1 , Guid2, Guid3, 1
Guid1 , Guid4, Guid3, 1
Guid1 , Guid4, Guid5, 0

Although its a composite primary key, This constraint has to work with the Id column only. Other columns, data1 and data2 are not relevant to this constraint.

Please let me know if you have some idea on how to do it.

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2009-09-03 : 14:10:37
Um... What is the constraint that you are trying to impose?

=======================================
Men build too many walls and not enough bridges. -Isaac Newton, philosopher and mathematician (1642-1727)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-09-03 : 14:32:57
I think you have to use a trigger to enforce such a constraint.
Go to Top of Page

librarocks
Starting Member

2 Posts

Posted - 2009-09-04 : 14:40:41
Hi Guys,

I found the answer at
[url]http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/3700ebe4-60f3-4b28-9a18-2d64e740485b/[/url]

Thanks for replying.
Go to Top of Page
   

- Advertisement -