简体   繁体   English

SQL断言语句

[英]SQL Assertion statement

Consider the following two Relational Schema describing the EMPLOYEES and DEPARTMENTS of some organization (assume all names are unique). 考虑以下两个关系模式,它们描述了某个组织的雇员和部门(假设所有名称都是唯一的)。

EMPLOYEES (EmployeeName, Salary, DeptName)

DEPARTMENTS (DeptName, ManagerName, City)

Define at schema level, a constraint (SQL Assertion) which specifies that none of the salaries of the employees of any department located in 'San Francisco' is more than the salary of any employee in the 'Management' department. 在架构级别定义一个约束(SQL断言),该约束指定“旧金山”中任何部门的员工薪水均不超过“管理”部门中任何员工的薪水。

My approach: 我的方法:

create assertion CHECK_SALARY as CHECK
(   

not exists (select * from EMPLOYEES

where select salary from EMPLOYEES

where EMPLOYEES.DeptName = 'San Fransisco' <

select salary from EMPLOYEES

where EMPLOYEES.DeptName = 'Management'

)

this is the thing i wrote but it is not working properly, any suggestions are appreciated 这是我写的东西,但是不能正常工作,任何建议都值得赞赏

Try something like this: 尝试这样的事情:

CREATE ASSERTION check_salary AS CHECK (   
  NO EXTISTS ( SELECT * FROM employees
               WHERE ( SELECT MAX(salary) FROM employees
                       WHERE "DeptName" = 'San Fransisco' )
                   < ( SELECT MIN(salary) FROM employees
                       WHERE "DeptName" = 'Management' ) )
);

尝试这个。

CREATE ASSERTION check_salary AS CHECK (NO EXTISTS ( SELECT * FROM Employees ee, departments dd WHERE  ee.dept_name = dd.dept_name AND dd.city = 'San Francisco' AND ee.salary < (SELECT Max(salary_amount) FROM Employees e, Departments d WHERE e.dept_name =d.dept_name AND d.Dept_name = 'Management') ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM