Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 multiple users

Author  Topic 

PeterG
Posting Yak Master

156 Posts

Posted - 2005-09-30 : 11:41:41
I have a web app that uses these two tables:

tblProfile
profile_id
schoolname
address
...

tblUsers
profile_id
adminuser
...

Currently, each school (profile_id) has 1 adminuser. We're thinking of extending the functionality to accomodate multiple users in each school. How do I go about modifying the table design to efficiently and effectively accomodate this? My initial thoughts are just create multiple records in tblUsers, i.e., if profile_id has 5 users then there would be 5 records in the table for that profile_id. How would this impact deleting, adding and updating users?

Thanks for your input.

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-09-30 : 17:43:46
Can a User belong to more than one school?

Is AdminUser a bit?

Can a School have more than one admin?



Nathan Skerl
Go to Top of Page

PeterG
Posting Yak Master

156 Posts

Posted - 2005-09-30 : 17:54:44
The adminuser field is a varchar. An admin user can be in more than 1 school and a school can have more than 1 admin users.

I did my initial analysis on this and it appears that this is the best way to go. I'm going to make profile_id and adminuser as primary keys in my tblUsers table.

Please provide feedbcaks/suggestions. Thanks.
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-09-30 : 18:19:50
I was thinking something like this... if you want one user to be able to have differing roles per school (profile) you can move the roleID out of tblUser and into the tblUserSchool M:M:




declare @tblUser table (userID int, userName varchar(15), roleID int)
insert into @tblUser
select 1, 'Nathan', 3 union
select 2, 'Adam', 2 union
select 3, 'Natalie', 1

declare @tblRole table (roleID int, roleName varchar(25), roleDesc varchar(50))
insert into @tblRole
select 1, 'GuestUser', 'Guest role has read-only access only.' union
select 2, 'GeneralUser', 'User role can do some other stuff.' union
select 3, 'AdminUser', 'Administrator User can do anything.'

declare @tblSchool table (schoolID int, schoolName varchar(100), schoolAddress varchar(100))
insert into @tblSchool
select 1, 'Mission San Jose', '123 Main Street' union
select 2, 'Washington', '321 Main Street'

declare @tblUserSchool table (userID int, schoolID int)
insert into @tblUserSchool
select 1, 1 union
select 2, 1 union
select 3, 2


select u.userID,
u.userName,
s.schoolName,
r.roleName
from @tblUser u
inner join @tblRole r
on u.roleID = r.roleID
inner join @tblUserSchool us
on u.userID = us.userId
inner join @tblSchool s
on us.schoolID = s.schoolID


Nathan Skerl
Go to Top of Page
   

- Advertisement -