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
 Custom check

Author  Topic 

borowik80
Starting Member

4 Posts

Posted - 2012-09-10 : 02:40:48
Hi,

I've got table with the following fields:

Cube_Id|Cube_RT|CubeName|Project_Id

Cube_Id is the PK
Project_Id is the FK

Cube_ST,CubeName and Project_Id are not unique.

while inserting and updating data I need to check if combination
Cube_RT and Project_Id already exists in the table. If so, then constraint must prevent updating table because this combination has to be unique.

How can I achive that?

Regards,
Luk



sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-10 : 06:50:17
If I am reading your requirement correctly, adding a unique constraint on Cube_RT and Project_ID should achieve what you are looking for. http://msdn.microsoft.com/en-us/library/ms177420(v=sql.105).aspx

But, what gives me pause is that you said Cube_ST, CubeName and Project_ID are not unique. Is Cube_ST another column in the table? If so, how does Cube_RT + Project_ID being unique impact that?
Go to Top of Page

borowik80
Starting Member

4 Posts

Posted - 2012-09-30 : 07:07:45
Thanks sunitabeck this is what I was looking for.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-09-30 : 18:45:02
You are quite welcome :)
Go to Top of Page
   

- Advertisement -