Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:47:48+00:00 2026-05-30T09:47:48+00:00

I have the following schema: Emp( eid int, ename varchar(50), salary float, email varchar(80))

  • 0

I have the following schema:

Emp(eid int, ename varchar(50), salary float, email varchar(80))

Works(eid int, did int, pct_time float)

Dept(did int, budget float, managerid int)

eid is for employee id.
did is for department id.
I’ve bolded primary keys.
managerid is a foreign key, as well as eid and did in Works.

Now, I’d like to add a “manager complex” assertion that ensure a manager will always have a higher salary than any employee that he/she manages.

Here’s what I’ve been thinking:

CREATE ASSERTION managerComplex
CHECK
( NOT EXISTS (SELECT  M.salary  
              FROM Dept D, Emp M 
              WHERE D.managerid = M.eid) <= 
                                           (SELECT E.salary
                                            FROM Works W, Emp E
                                            WHERE W.eid = E.eid) AND
                                                                     D.did = W.did);

Is this even close to right?
Also, maybe I should have just made a couple CHECKs instead of an insertion?
I feel like multiple CHECKs is sloppier but would probably be easier to get right.

EDIT: The main reason I am asking is because I don’t know if I’m correctly understanding NOT EXISTS

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:47:49+00:00Added an answer on May 30, 2026 at 9:47 am

    For NOT EXISTS ( SELECT ...) to be true, the SELECT ... must return no results.

    You want to create a SELECT statement that will return any employee with a salary higher than the manager listed for the department(s) they work for. See if you can write that query, and then place it inside the NOT EXISTS

    I’m not entirely sure what you wrote is even valid SQL, but it’s certainly not what you want. I have a potential answer for you, but as this was marked homework, I’d like to attempt to prod you in the right direction before providing a complete answer.


    As OP said the homework has been turned in…

    CREATE ASSERTION managerComplex
    CHECK
    (NOT EXISTS (SELECT E.salary
                 FROM Emp M, Dept D, Works W, Emp E
                 WHERE M.eid = D.managerid AND 
                       W.did = D.did AND
                       E.eid = W.eid AND
                       E.salary > M.salary))
    

    My NOT EXISTS has a query inside of it, that will return results if there are any employee salaries higher than their respective manager’s salary. I look at all employees who work for a department, and only pull them into the result set if their salary is higher than the manager for that department’s salary.

    I’m not even sure your SQL is valid, as you have a (SELECT ...) <= (SELECT ...) AND .... Comparing result sets with a <= doesn’t make any sense to me. It’s possible that’s just SQL I’ve never used, but… I’ve never used it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have the following schema table A: ID int primary key value varchar(255)
I have the following pseudo-SQL schema: table flight id int primary key date timestamp
I have the following DB schema: Users -Id (uniqueidentifier) -FirstName -LastName -Email AuthProviders -Id
In a table I have the following schema table1: playerID int primary key, nationalities
I have the following database relational schema that purports to model an EMP supertype
I have following table schema - CREATE TABLE [dbo].[TEST_TABLE] ( [TEST_TABLE_ID] [int] IDENTITY(1,1) NOT
I have the following schema, which I use to ensure that a person's PhoneNumber
Suppose I have the following schema t = {name: 'John', reviews: [{sid: 1, comment:
I have the following XML Schema: <Root> <EventSet> <Event> <id> //random id </id> <time>
I have 30m records of the following schema in couchdb. { countryIso: 'TR' ,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.