0

I have some problem creating a check constraint on SQL server. Summarizing I have two tables: employee and min_salary

EMPLOYEE (
   SALARY DECIMAL
   . 
   . 
   . 
) 

MIN_SALARY (
   MIN_SALARY DECIMAL
)

I need to CHECK when insert a new Employee if the employee salary is greater than min_salary.

I have tried with functions and constraint check but i've not succeeded.

forpas
  • 160,666
  • 10
  • 38
  • 76
Luis Quijada
  • 3
  • 1
  • 5
  • Have a try with this [answer](https://stackoverflow.com/a/3880853/2451726) – Arulkumar Jun 17 '19 at 07:02
  • It is far better to post what you did try and the errors you experienced. What you did post is not even tsql code and it appears that you have two tables - which complicates the logic. – SMor Jun 17 '19 at 11:27
  • @LuisQuijada . . . If you want to do this with a check constraint, you will need to add a helper function to get the minimum salary. The alternative is to use a trigger. – Gordon Linoff Jun 17 '19 at 11:53

1 Answers1

0

I don't know if this will help you, but try this one.

 Select case when T0.Salary > T1.Min_Salary then 'Message here if greater than' else 'Message here if less than' end [Evaluation of salary] From Employee T0 Inner Join [dbo].[Min_Salary] T1 on T0.employeeId = T1.Id