Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Database Design
»
Design Ideas and Questions
»
DB Design Help
DB Design Help
Rate Topic
Display Mode
Topic Options
Author
Message
JJ-469859
JJ-469859
Posted Thursday, February 26, 2009 10:03 PM
Grasshopper
Group: General Forum Members
Last Login: Monday, April 08, 2013 8:51 AM
Points: 14,
Visits: 653
I am creating a change management system. Part of my design has a change request table and a contact table. Each change request has a technicianid, a managementid, a directorid, and a maincontactid. To find out all the info on the people for a change request, I have to join to the contact table four times.
From the contact table, I have a department table. So I have to join another four times to find the department of all the contacts for a single change.
Does this sound like a proper database design? Including the domain tables, I am up to 11 joins to find out the data I want on a particular change request.
Post #665493
Grant Fritchey
Grant Fritchey
Posted Friday, February 27, 2009 6:01 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
No, that's probably not a great way to go about it. Instead have a many-to-many join table between the two other tables. So you'll have a ChangeRequest table and a Contact table. Then you create a ChangeRequestContact table that has they key from each of the other two in it. This table should also have a link to a lookup table ContactType (or something, you name these things for your business). That way you can define how a given contact is associated with the change request. This will allow for you to add more and more contact types without having to redesign the system. I'd do the same thing for the department so that more than one department can be easily associated with a given request in varying roles. It makes for somewhat more complicated coding, but it's a lot more flexible and allows for change without having to re-structure your db and rewrite your code.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #665639
JJ-469859
JJ-469859
Posted Thursday, March 05, 2009 11:44 AM
Grasshopper
Group: General Forum Members
Last Login: Monday, April 08, 2013 8:51 AM
Points: 14,
Visits: 653
Grant Fritchey (2/27/2009)
No, that's probably not a great way to go about it. Instead have a many-to-many join table between the two other tables. So you'll have a ChangeRequest table and a Contact table. Then you create a ChangeRequestContact table that has they key from each of the other two in it. This table should also have a link to a lookup table ContactType (or something, you name these things for your business). That way you can define how a given contact is associated with the change request. This will allow for you to add more and more contact types without having to redesign the system. I'd do the same thing for the department so that more than one department can be easily associated with a given request in varying roles. It makes for somewhat more complicated coding, but it's a lot more flexible and allows for change without having to re-structure your db and rewrite your code.
1) For the old database design, writes are fast and reads would be a little slower since they have to do so many joins. I have to build a report each month that shows the changes for that month. I figure 100 rows a month selected. Wouldn't read performance on only 100 rows be acceptable even if the database starts holding tens of thousands of rows?
2) I realize the design you suggest is much more flexible. But wouldn't I still have to do the same amount of joins to select the data? Below would be the insert statement. (assuming I don't have the ContactType lookup table)
CREATE PROCEDURE InsertChangeRequest_sp
(@TargetSystem varchar(40), @Description varchar(1000),
@TechnicianID int, @ManagementID int,
@DirectorID int, @MainContactID int)
AS
BEGIN TRAN
INSERT INTO ChangeRequest
(TargetSystem, Description)
VALUES (@TargetSystem, @Description)
DECLARE @ChangeRequestID int
SELECT @ChangeRequestID = Scope_Identity()
INSERT INTO ChangeRequestContact
(ChangeRequestID, ContactID, ContactType)
VALUES
(@ChangeRequestID, @TechnicianID, 'Tech')
INSERT INTO ChangeRequestContact
VALUES
(@ChangeRequestID, @ManagerID, 'Manager')
INSERT INTO ChangeRequestContact
VALUES
(@ChangeRequestID, @DirectorID, 'Director')
INSERT INTO ChangeRequestContact
VALUES
(@ChangeRequestID, @MainContact, 'MainContact')
END TRAN
-------------
Then the select statement would be
SELECT CR.TargetSystem, CR.Description,
(CT.FirstName + CT.LastName) as TechnicianName,
(CM.FirstName + CM.LastName) as ManagerName,
(CD.FirstName + CD.LastName) as DirectorName,
(CMC.FirstName + CMC.LastName) as MainContactName
FROM ChangeRequest CR
JOIN ChangeRequestContact CRC ON CR.ChangeRequestID = CRC.ChangeRequestID
JOIN Contact CT ON CRC.ContactID = CT.ContactID
JOIN Contact CM ON CRC.ContactID = CM.ContactID
JOIN Contact CD ON CRC.ContactID = CD.ContactID
JOIN Contact CMC ON CRC.ContactID = CMC.ContactID
--plus four more joins for department
WHERE ScheduleDate is this month
Does this sound right?
Post #669487
Grant Fritchey
Grant Fritchey
Posted Friday, March 06, 2009 6:59 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
Yeah, you'll have a few joins, it's still not that many and the indexing should be very simple. The one thing I'd suggest, instead of trying to pivot the data into columns, return it as rows, you'll have fewer joins and simpler queries that way. You can change the layout on the client side so that it's pivoted.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #670173
StephenMarais
StephenMarais
Posted Tuesday, April 21, 2009 12:30 AM
Grasshopper
Group: General Forum Members
Last Login: Monday, April 11, 2011 4:44 AM
Points: 22,
Visits: 54
The ChangeRequestContact table is the best way to handle this type of data. As an added daat integrity measure i would place a constraint on the table only allowing one contact per role type per change request.
Stephen Marais
Integration Architect
Digiata Technologies
www.digiata.com
Post #701190
JJ-469859
JJ-469859
Posted Tuesday, April 21, 2009 10:48 AM
Grasshopper
Group: General Forum Members
Last Login: Monday, April 08, 2013 8:51 AM
Points: 14,
Visits: 653
Grant Fritchey (3/6/2009)
The one thing I'd suggest, instead of trying to pivot the data into columns, return it as rows, you'll have fewer joins and simpler queries that way. You can change the layout on the client side so that it's pivoted.
Can you explain this a little more? I am not following how I could pivot into columns instead of rows. What would my query look like?
Post #701674
Grant Fritchey
Grant Fritchey
Posted Tuesday, April 21, 2009 11:34 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
The data would be something like
Name, Type
Joe Plumber
Tim Project Manager
Tom Developer
Etc.
Instead of what you're trying which is:
PlumberName, Project Manager Name, DeveloperName
Joe Tom Tim
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #701717
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.