Posted By

hairajeshk on 12/02/10


Tagged

check constraint


Versions (?)

Check Constraint - Calling function under Check constraint


 / Published in: SQL
 

If we don't have a primary key and unable to create a foreign key

  1. IF we don't have a primary key and unable to create a foreign key we need to wirte a function which validate the other table and call this in check constraint.
  2.  
  3. SIMPLY: Calling function under Check constraint.
  4.  
  5. alter table YourTable
  6. add constraint chk_CheckFunction
  7. check (dbo.CheckFunction() = 1)
  8.  
  9. create function dbo.CheckFunction()
  10. returns int
  11. as begin
  12. return (select 1)
  13. end

Report this snippet  

You need to login to post a comment.