Check Constraint - Calling function under Check constraint


/ Published in: SQL
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.