dbTalk Databases Forums  

Database Design Question

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Database Design Question in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael_Burgess
 
Posts: n/a

Default Database Design Question - 06-08-2007 , 06:12 AM






Hi there,

I'm fairly new to database design, having only really worked with
existing tables etc in the past.

Simple question this really...........

In a users table, is it wise to have a ManagerID column that is
effectively pointing to another user in the same table, with the
theory being that if that person is top dog, they will just have a
null entry in ManagerID.

I will check for circular references before entering the data.

Is there a better way of storing the data, or is this the only way?

Thanks,
Michael.


Reply With Quote
  #2  
Old   
M A Srinivas
 
Posts: n/a

Default Re: Database Design Question - 06-08-2007 , 06:57 AM






On Jun 8, 4:12 pm, Michael_Burgess <m... (AT) marsh-hall-studios (DOT) co.uk>
wrote:
Quote:
Hi there,

I'm fairly new to database design, having only really worked with
existing tables etc in the past.

Simple question this really...........

In a users table, is it wise to have a ManagerID column that is
effectively pointing to another user in the same table, with the
theory being that if that person is top dog, they will just have a
null entry in ManagerID.

I will check for circular references before entering the data.

Is there a better way of storing the data, or is this the only way?

Thanks,
Michael.
This is the way to store data , Otherwise you may require as many
tables as there are levels . You have to build a hierarchy column
for easy retrieval of child and parent



Reply With Quote
  #3  
Old   
Seribus Dragon
 
Posts: n/a

Default Re: Database Design Question - 06-08-2007 , 08:56 AM



I would Have A lookup Table because you may end up with a person having
more then one manager.
UserID|ManagerID
Michael_Burgess wrote:
Quote:
Hi there,

I'm fairly new to database design, having only really worked with
existing tables etc in the past.

Simple question this really...........

In a users table, is it wise to have a ManagerID column that is
effectively pointing to another user in the same table, with the
theory being that if that person is top dog, they will just have a
null entry in ManagerID.

I will check for circular references before entering the data.

Is there a better way of storing the data, or is this the only way?

Thanks,
Michael.


Reply With Quote
  #4  
Old   
Michael_Burgess
 
Posts: n/a

Default Re: Database Design Question - 06-08-2007 , 09:57 AM



On Jun 8, 2:56 pm, Seribus Dragon <Seribus.n... (AT) seribus (DOT) com> wrote:
Quote:
I would Have A lookup Table because you may end up with a person having
more then one manager.
UserID|ManagerID



Michael_Burgess wrote:
Hi there,

I'm fairly new to database design, having only really worked with
existing tables etc in the past.

Simple question this really...........

In a users table, is it wise to have a ManagerID column that is
effectively pointing to another user in the same table, with the
theory being that if that person is top dog, they will just have a
null entry in ManagerID.

I will check for circular references before entering the data.

Is there a better way of storing the data, or is this the only way?

Thanks,
Michael.- Hide quoted text -

- Show quoted text -
Would you be able to give me a very trivial example with some mini-
tables at all please? Sorry to put you out.

Thanks,
Michael.



Reply With Quote
  #5  
Old   
Jason Lepack
 
Posts: n/a

Default Re: Database Design Question - 06-08-2007 , 02:17 PM



-- try this

create table employees
(
employee_id tinyint identity(1,1) not null primary key,
employee_name [varchar](50) not null
)
go

create table management_hierarchy
(
employee_id tinyint not null,
manager_id tinyint null
)
go

-- foreign key - employee
alter table
management_hierarchy with check
add constraint fk_mh_employee foreign key(employee_id)
references employees(employee_id)
go
alter table
management_hierarchy
check constraint fk_mh_employee
go

-- foreign key - manager
alter table
management_hierarchy with check
add constraint fk_mh_manager foreign key(manager_id)
references employees(employee_id)
go
alter table
management_hierarchy
check constraint fk_mh_manager
go

-- insert sample data
insert into employees(employee_name) values ('Jason Lepack')
insert into employees(employee_name) values ('Bobsyer Uncle')
insert into employees(employee_name) values ('Sweet Lee')
go
insert into management_hierarchy(employee_id, manager_id)
values(1, null)
insert into management_hierarchy(employee_id, manager_id)
values(2,1)
insert into management_hierarchy(employee_id, manager_id)
values(3, 1)
go

-- output the data
select * from employees
go

select * from management_hierarchy

select
e.employee_name subordinate,
m.employee_name manager
from
management_hierarchy mh
inner join employees e
on e.employee_id = mh.employee_id
left join employees m
on m.employee_id = mh.manager_id
go

-- drop the tables
drop table management_hierarchy
drop table employees

On Jun 8, 10:57 am, Michael_Burgess <m... (AT) marsh-hall-studios (DOT) co.uk>
wrote:
Quote:
On Jun 8, 2:56 pm, Seribus Dragon <Seribus.n... (AT) seribus (DOT) com> wrote:





I would Have A lookup Table because you may end up with a person having
more then one manager.
UserID|ManagerID

Michael_Burgess wrote:
Hi there,

I'm fairly new to database design, having only really worked with
existing tables etc in the past.

Simple question this really...........

In a users table, is it wise to have a ManagerID column that is
effectively pointing to another user in the same table, with the
theory being that if that person is top dog, they will just have a
null entry in ManagerID.

I will check for circular references before entering the data.

Is there a better way of storing the data, or is this the only way?

Thanks,
Michael.- Hide quoted text -

- Show quoted text -

Would you be able to give me a very trivial example with some mini-
tables at all please? Sorry to put you out.

Thanks,
Michael.- Hide quoted text -

- Show quoted text -



Reply With Quote
  #6  
Old   
--CELKO--
 
Posts: n/a

Default Re: Database Design Question - 06-11-2007 , 09:48 PM



Quote:
Is there a better way of storing the data, or is this the only way?
Get a copy of TREES & HIERARCHIES IN SQL for several different ways to
do an organizational chart. What you have is teh adjacency list
model; look up the nested sets model.



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.