Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Join Date
    Feb 2011
    Posts
    15

    Unanswered: need urgent homework help

    Consider the following relational database where the primary keys are as indicated

    person(person name, street, city) // records about all people (primary key is person name)

    works(person name, company name, annual salary) // records about employed people(primary key is person name)

    company(company name, founded)(primary key is company name)

    company location(company name, city) // companies and cities where they have offices(primary keys are company name and city)

    managed by(person name, manager name)(primary key is person name)

    Consider this schema . Write a check condition
    to ensure that an employee cannot be the manager of his/her manager. For example, if John isGeorge's manager, George cannot be John's manager.

  2. #2
    Join Date
    Jan 2011
    Posts
    19
    Research check constraint, I think it might do what you need from what I understand of your question.

    PostgreSQL: Documentation: Manuals: PostgreSQL 8.1: Constraints

    Did you come up with the primary keys or did the assignment?

  3. #3
    Join Date
    Feb 2011
    Posts
    15

    need urgent homework help

    Hi,
    Thanks for showing interest to help me. I will appreciate if you will help me immdiately for solution .
    The Primary keys are given by prof. in the HW Assignment the due date is today only please help me urgently.


    Thanks & Regards,

  4. #4
    Join Date
    Jan 2011
    Posts
    19
    General forum rule is that only suggest help topics for homework not to do the homework for a person.

    If you start writing a statement I can help you with the errors you are getting.

  5. #5
    Join Date
    Feb 2011
    Posts
    15

    need urgent homework help please

    Hi,
    I am using postgresql 9.0 I am trying to figure it out but it is giving me error please help me to correct this answer.

    CREATE Table managed_by (
    person_name varchar(30),
    manager_name varchar(30),
    CHECK (person_name = manager_name AND manager_name != person_name)
    CONSTRAINT managed_by_pk PRIMARY KEY(person_name),
    FOREIGN KEY(person_name) REFERENCES person(person_name)
    FOREIGN KEY(manager_name) REFERENCES person (person_name)
    );

    Thanks

  6. #6
    Join Date
    Feb 2011
    Posts
    15

    SQL Query

    Consider the following relational database where the primary keys are as indicated

    person(person name, street, city) // records about all people (primary key is person name)
    works(person name, company name, annual salary) // records about employed people(primary key is person name)
    company(company name, founded)(primary key is company name)
    company location(company name, city) // companies and cities where they have offices(primary keys are company name and city)
    managed by(person name, manager name)(primary key is person name)
    Give an expression in SQL for each of the following queries:

    Find the year in which the largest number of companies were founded.

  7. #7
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Show us what you have tried so far

  8. #8
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    And the error is?

  9. #9
    Join Date
    Feb 2011
    Posts
    15

    need urgent homework help

    ERROR: syntax error at or near "CONSTRAINT"
    LINE 5: CONSTRAINT managed_by_pk PRIMARY KEY(person_name),
    ^

  10. #10
    Join Date
    Feb 2011
    Posts
    15

    SQL Query

    SELECT * FROM (SELECT founded, COUNT(*)
    FROM company
    GROUP BY founded
    ORDER BY 2 DESC)
    WHERE ROWNUM < 2
    I am using posrgresSQL 9.0 and I am getting following error.

    ERROR: subquery in FROM must have an alias
    LINE 1: SELECT * FROM (SELECT founded, COUNT(*)
    ^
    HINT: For example, FROM (SELECT ...) [AS] foo.

    ********** Error **********

    ERROR: subquery in FROM must have an alias
    SQL state: 42601
    Hint: For example, FROM (SELECT ...) [AS] foo.
    Character: 15

  11. #11
    Join Date
    Jan 2011
    Posts
    19
    Little note maybe to help. You can write a select statement within a CHECK constraint.

  12. #12
    Join Date
    Feb 2011
    Posts
    15

    need urgent homework help

    Will you please explain me how use select statement within CHECK constraint I am really trying hard.

  13. #13
    Join Date
    Jan 2011
    Posts
    19
    SELECT *
    FROM (
    SELECT founded, COUNT(*) as mycount
    FROM company
    GROUP BY founded
    ORDER BY 2 DESC
    )
    WHERE ROWNUM < 2

    Plus I don't think that ORDER BY right.

  14. #14
    Join Date
    Feb 2011
    Posts
    15

    SQL Query

    I tried follwing way

    SELECT *
    FROM (
    SELECT founded, COUNT(*) as mycount
    FROM company
    GROUP BY founded
    )
    WHERE ROWNUM < 2
    i am getting following error please help me.

    ERROR: subquery in FROM must have an alias
    LINE 2: FROM (
    ^
    HINT: For example, FROM (SELECT ...) [AS] foo.

  15. #15
    Join Date
    Feb 2011
    Posts
    15

    need urgent homework help

    Hi,
    I also tried following way.

    CREATE Table managed_by (
    person_name varchar(30),
    manager_name varchar(30),

    CHECK (manager_name != (SELECT person_name FROM managed_by WHERE manager_name = person_name))

    CONSTRAINT managed_by_pk PRIMARY KEY(person_name),
    FOREIGN KEY(person_name) REFERENCES person(person_name)
    FOREIGN KEY(manager_name) REFERENCES person (person_name)
    );

    still I am getting same error
    ERROR: syntax error at or near "CONSTRAINT"
    LINE 7: CONSTRAINT managed_by_pk PRIMARY KEY(person_name),

    please help me.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •