I have the following statements to create my conceptual model:
EMPLOYEE belongs to one DEPARTMENT;
EMPLOYEE can work in many PROJECTs of his DEPARTMENT;
PROJECT is managed by only one DEPARTMENT;
DEPARTMENT can have many PROJECTs;
So 1 EMPLOYEE can work in N PROJECTs as long as those PROJECTs belongs to his DEPARTMENT. How can i guarantee that the EMPLOYEE and the PROJECT belongs to the same DEPARTMENT using a ternary relationship?
Making some test I found out that using a ternary relantionship I can have an EMPLOYEE in a PROJECT that does not belongs to the same PROJECT
Example:
As shown in the image, the second and third line is allowed, but it is not valid considering that the PROJECT and the EMPLOYEE is from DEPARTMENT 1.
The second line says that the EMPLOYEE is from DEPARTMENT 2 but it's previously define DEPARTMENT 1.
The third line says PROJECT 1 is from DEPARTMENT 2 but it is also defined to be from DEPARTMENT 1 in the first line.
What do i do to solve this problem?
You said EMPLOYEE belongs to one DEPARTMENT and PROJECT is managed by only one DEPARTMENT but didn't model those requirements. Once you do, you can add foreign key constraints to WORK for (EMPLOYEE, DEPARTMENT) as well as (PROJECT, DEPARTMENT).
https://drive.google.com/file/d/0B9mDH6Q_ERUTNWZfaUx3RmpFSWEyOERmRnluaUprbUdUM2hJ/view?usp=sharing
It is the link for the ER diagram which I have drawn. The diagram corresponds to this question
COMPANY has departments
Department has name, number, manager
Manager is an employee
Manager has starting date
Department has several locations
Department controls projects
Project has name, number, location
Employee has name, social security, number, address, salary, sex, birthdate.
Employee is in one department and works strictly on several projects belonging to that department
Hours each employee works on each project
Employee has supervisor
Employee has dependents with name, sex, birthdate, and relationship to employee.
Related
Let's say that works-in is a relationship between entity types Employee and Department and the cardinality is many to one. Does total participation of Employee in the works-in relationship in other words mean that if I ever put an employee in my database, I must provide a Department that the employee works in? In mathematical terms: Employee is put in a table <=> Employee has associated Department. Can someone explain this in simple terms involving the sets of the entities and that of the relationship? Thanks.
You're question isn't entirely clear based on the information you gave.
For example: if an employee must have a department and each department must have an employee then it's total participation on both sides. (You cannot delete a department if it has an employee. And cannot delete an employee if it has a department with no other employees). Basically this means that those foreign keys cannot be null
However, if a department must have an employee but an employee doesnt have to have a department then the department has total participation and the employee has partial participation. Basically this means these foreign keys can be set to null.
Consider a system where employee record is kept. The database should store employee name,department etc. Every employee has a reporting manager to whom he has to report.
There are 4 levels of employee –
Junior Engineer
Senior Engineer
Team Lead
Senior Team Lead
Every junior engineer has to report to Senior engineer. Every senior Developer has to report to team lead. Every team lead has to report to senior team lead.
I came to this idea:-
There will be two table
1.Employee
2.Reporting
Employee table would contain necessary information like EmployeeID,Employee Name,Department Name etc.; primary key is EmployeeID
Reporting Table would contain two columns EmployeeID and ReportingMangerID ;EmployeeID is foreign key related to Primarykey of Employee Table.
I dont know if I am correct.
If the following is true:
one employee reports to 0..1 other employees
one employee has 0..n reports
Then you can have "manager" as an attribute for the employee table.
If the following is true:
one employee reports to 0..n other employees
one employee has 0..n reports
Then you need to have your structure.
I want to create an entity relationship diagram for a three way relationship in the following contrived situation:
Each COMPANY has many DEPARTMENTS. An EMPLOYEE can work simultaneously for many DEPARTMENTs. However, an EMPLOYEE can work for only one DEPARTMENT of a COMPANY. In other words, the EMPLOYEE works for as many DEPARTMENTS as COMPANYs.
What kind of associations and relationships will such a diagram have? My purpose is not to create tables in a database but just as an aid to understanding.
Thanks in advance for your help!
COMPANY_EMPLOYEE_DEPARTMENT:
COMPANY (PK)
EMPLOYEE (PK)
DEPARTMENT
Each combination of company and employee, can only be associated with one department. That is, an employee can only work for one department in each company.
This should work as long as a department does not belong to more than one company, and that the COMPANY_EMPLOYEE_DEPARTMENT relation does not link a department of one company with another company.
I'm trying to achieve 3NF using the data I have but I'm getting confused. These are the tables I have:
FACULTY table DEPARTMENT table STUDSGROUP table STUDENT table
FACULTY_ID DEPARTMENT_ID STUDSGROUP_ID STUDENT_ID
FACULTY_NAME DEPARTMENT_NAME ACADEMIC YEAR STUDENTS_NAME
FACULTY_DEAN HEAD OF DEPARTMENT COURSE/SPECIALITY STUDENTS_GROUP
COURSE/SPECIALITY
DOB/DATE OF BIRTH
I am thinking I can do it like this below, though I think I'm not right.
FACULTY table
FACULTY_ID,PK
DEAN
DEPARTMENT table
DEPARTMENT_ID,PK
FACULTY_ID,fk
DEPARTMENT_NAME
HEAD OF DEPARTMENT
STUDSGROUP table
STUDSGROUP_ID, pk
ACADEMIC YEAR
SPECIALITY
STUDENTS table
STUDENT_ID, pk
FACULTY_NAME,FK
STUDSGROUP_ID,FK
FIRST_NAME
LAST_NAME
DOB
Normalization requires that you know how the various parts of the schema are related. Up to 3NF and BCNF (almost, but not quite the same thing — though you'd be hard-pushed to find a practical example of 3NF that is not also in BCNF), the most important feature is the functional dependency.
Another key point is 'conservation'; you shouldn't lose columns altogether. For example, your original Faculty table has an ID number, a name and a dean. Your revised version is missing the faculty name; that is a bug in your redesign.
You've identified that each department belongs to a faculty, which seems plausible enough.
Your revised Student Groups table seems to be the same as in the original. That's probably OK, though maybe the course/speciality part of that means that a student group is associated with a department, and hence a faculty. If so, then the you might need a courses/specialities table that identifies the course/speciality and the department, leaving the student group to identify a particular year group within the course/speciality.
Your original students table has a course/speciality and also a student group; this leaves open the possibility that the data will say Student X is doing Archaeology in the Students table, but the Student Group indicates that Student X is doing Music. Is that allowed? If not, would you be best served by just having the Student Group in the Students table, leaving that to identify course/speciality, and year, and department, and hence faculty? Your revised schema adds a faculty ID to the students table (but does remove the course/speciality); that still leaves opportunities for conflict within the data.
Do you need a table to identify valid academic years? Possibly not. Should there be a table for staff, so that you can identify deans and department heads. Can the dean of a faculty be a department head? Of departments outside their faculty?
I have a problem with a many-to-many relation in my tables, which is between an employee and instructor who work in a training centre. I cannot find the link between them, and I don't know how to get it. The employee fields are:
employee no.
employee name
company name
department job title
business area
mobile number
ext
ranking
The Instructors fields are
instructor name
institute
mobile number
email address
fees
in a many-to-many relationship the relationships will be in a 3rd table, something like
table EmployeeInstructor
EmployeeID
InstructorID
to find all the employees for a specific instructor, you'd use a join against all three tables.
Or more likely there will be classes involved --
Employee takes Class
Instructor teaches Class
so you'll have and EmployeeClass table,
an InstructorClass table,
and join through them. And Class needs to be unique, or else you'll need
Class is taught in Quarter on ClassSchedule
and end up joining EmplyeeClassSchedule to InstructorClassSchedule.
This ends up being one of your more interesting relational designs pretty quickly. If you google for "Terry Halpin" and "Object Role Modeling", this is used as an illustrative situation in the tutorial.
First of all, you will need a unique key in both tables. The employee number may work for the employee table, but you will need another for the instructor table. Personally, I tend to use auto incrementing identity fields called ID in my tables. This is the primary key.
Second, create a new table, InstructorEmployee. This table has two columns, InstructorID and EmployeeID. Both fields should be indexed. Now you can create an association between any Employee and any Instructor by creating a record which contains the two IDs.