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 2000 Forums
 Transact-SQL (2000)
 urgent check constraint

Author  Topic 

rajkumarrai_bis
Yak Posting Veteran

78 Posts

Posted - 2005-06-06 : 10:36:25
pls help me out
i want to apply a check constraint on a field in a table
condition is the that the field value should always be greater or equal to a value stored in other table

in short , how can i use other table's field value in check constraint

thanks in advance

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-06 : 11:16:36
use instead of or after trigger, whichever suits you.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

rajkumarrai_bis
Yak Posting Veteran

78 Posts

Posted - 2005-06-07 : 01:41:56
thanks spirit1 for ur response

i know what u r telling ,
but the problem is that i dont know how to capture inserted values in a trigger , plz provide me the code in which u have captured inserted values in a trigger

i think after_insert trigger will be useful for me
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-06-07 : 02:12:00
the inserted values will be in "inserted"
example query:
select count(*) from inserted
which will you the number of records inserted at that moment

--------------------
keeping it simple...
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2005-06-07 : 04:35:00
This can be done with a view...
eg.


CREATE VIEW YourTable_CONSTRAINT
AS
Select <column list>
from YourTable Y
WHERE EXISTS (SELECT 1 from TargetTable TT WHERE Y.Value >= TT.Value AND <Key condition>)
WITH CHECK

Insert/update into this...

DavidM

A front-end is something that tries to violate a back-end.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-07 : 04:58:07
good call david. forgot about WITH CHECK on views...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

rajkumarrai_bis
Yak Posting Veteran

78 Posts

Posted - 2005-06-07 : 06:55:49
sorry to disturb the flow

i know that all u people have given me usefull tips

but now i have implemented check contraint in all the desired
locations as work was of urgent nature
currently i am using constant values , but needs to know how can i use other table's value in check constraint
eg. exename > 105
i want to use other table's field value in place of 105

Go to Top of Page
   

- Advertisement -