If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Can I use 2 relationships in parent/child tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-02-07, 16:51
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Can I use 2 relationships in parent/child tables

I have an employee and employee performance table. I am trying to track the performance of employees. The performance table will be about an employee and his performance. I also want to log the employee doing the performance but I can't model this for some reason.

Code:
Create table employee_Performance (
	employee_Seq Int NOT NULL,
	type Char(20) NOT NULL,
	date Date NOT NULL,
	notes Blob NOT NULL,
	performance_Seq Int NOT NULL AUTO_INCREMENT,
	UNIQUE (performance_Seq),
 Primary Key (performance_Seq)) ENGINE = InnoDB;

Create table employee (
	f_Name Char(20) NOT NULL,
	l_Name Char(50) NOT NULL,
	address1 Char(20) NOT NULL,
	address2 Char(10) NOT NULL,
	ssn Char(11) NOT NULL,
	employee_Seq Int NOT NULL,
	UNIQUE (employee_Seq),
 Primary Key (employee_Seq)) ENGINE = MyISAM;

Create table employee_Performance_Type (
	type Char(20) NOT NULL,
	UNIQUE (type),
 Primary Key (type)) ENGINE = MyISAM;


Alter table employee_Performance add unique Alter_Key4 (employee_Seq,type,date);
Alter table employee add unique Alter_Key3 (l_Name,ssn);


Alter table employee_Performance add Foreign Key (employee_Seq) references employee (employee_Seq) on delete  restrict on update  restrict;
Alter table employee_Performance add Foreign Key (type) references employee_Performance_Type (type) on delete  restrict on update  restrict;
Can I create a second relationship between the employee and performance tables for the employee doing the performance and rename the PK column?

Sometimes a pic is worth a thousand words. I have changes the rolename to manager in the performance table.

Thanks,

Frank
Attached Thumbnails
Can I use 2 relationships in parent/child tables-export.jpg  

Last edited by Frunkie; 09-02-07 at 16:56.
Reply With Quote
  #2 (permalink)  
Old 09-02-07, 17:14
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I'm confused... how does an employee "do performance"?
Do you mean the person "appraising" the employee?

If the appraiser can only be another employee then store the appraisers "employee_Seq" against the performance record for the employee (this is assuming that an employee can only have one appraiser?)

If I've got the wrong end of the stick let me know!!
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 09-02-07, 17:19
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by georgev
I'm confused... how does an employee "do performance"?
Do you mean the person "appraising" the employee?

If the appraiser can only be another employee then store the appraisers "employee_Seq" against the performance record for the employee (this is assuming that an employee can only have one appraiser?)

If I've got the wrong end of the stick let me know!!
Hey George.

"Evaluator" would be a better word. So.. an Evaluator or in real life terms, manager will be doing an assessment of an employee.

I'm kind of lost on your suggestion tho..
Reply With Quote
  #4 (permalink)  
Old 09-02-07, 17:24
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Can one employee have one evaluator per performance record?
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 09-02-07, 17:28
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by georgev
Can one employee have one evaluator per performance record?
Yes, only one.
Reply With Quote
  #6 (permalink)  
Old 09-02-07, 17:33
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Then store the evaluators unique identifier against the performance record
Simple as that!
__________________
George
Twitter | Blog
Reply With Quote
  #7 (permalink)  
Old 09-02-07, 17:37
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by georgev
Then store the evaluators unique identifier against the performance record
Simple as that!
Uhh.. Thats what I thought I did. Did you look at the pic I uploaded? It is the "manager" FK. I just changed the rolename from employee_Seq to manager. I just want to know if this is acceptable or if there a better way to do this?
Reply With Quote
  #8 (permalink)  
Old 09-02-07, 17:49
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
I only read the code, missed the pic!
I also note your performance type table... Should it not have an auto incrementing identifier used as the foreign key in the performance table?
Quote:
I just want to know if this is acceptable or if there a better way to do this?
It's the way I'd do it... You can easily retrieve any information about the evaluator using a LEFT OUTER JOIN to the employee table.
__________________
George
Twitter | Blog
Reply With Quote
  #9 (permalink)  
Old 09-02-07, 18:01
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by georgev
I only read the code, missed the pic!
I also note your performance type table... Should it not have an auto incrementing identifier used as the foreign key in the performance table?

It's the way I'd do it... You can easily retrieve any information about the evaluator using a LEFT OUTER JOIN to the employee table.
The performance_Type table is just a table that will hold the value of the performance. I was going to just use the value itself as the PK. That was always a question I wanted to ask but never got around to doing.

I remember blindman once said something about not changing the column name for some reason or another, but I can't find the thread. He said that it was incorrect.
Reply With Quote
  #10 (permalink)  
Old 09-03-07, 03:17
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
So the type table is a lookup?
__________________
George
Twitter | Blog
Reply With Quote
  #11 (permalink)  
Old 09-03-07, 04:52
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Quote:
Originally Posted by georgev
So the type table is a lookup?
No. The only lookup table I have is the performance_Type table. I just went with changing the column name. It seems to work rather well.

I pulled out one of my old database books and I was able to find one of those generic models in the back of the book and found in one of the models that the designer had done the same thing. I read the DDL and the column name was changed also so I think I am ok.
Reply With Quote
  #12 (permalink)  
Old 09-03-07, 05:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by georgev
Should it not have an auto incrementing identifier used as the foreign key in the performance table?
noooooooooooooooo.............

shock! dismay!

oh grasshopper, you were coming along so nicely...
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 09-03-07, 05:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
frank, as a data modelling exercise, could you take a moment and draw another nice picture, this time without using "seq" columns as your PKs
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 09-03-07, 05:36
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Quote:
Originally Posted by r937
Quote:
Originally Posted by georgev
Should it not have an auto incrementing identifier used as the foreign key in the performance table?
noooooooooooooooo.............

shock! dismay!

oh grasshopper, you were coming along so nicely...
So a char(20) lookup value is a good thing?
__________________
George
Twitter | Blog
Reply With Quote
  #15 (permalink)  
Old 09-03-07, 05:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by georgev
So a char(20) lookup value is a good thing?
of course it is why wouldn't it be?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On