﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Database Design / Design Ideas and Questions  / DB Design Help / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 14:51:08 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>The data would be something likeName, TypeJoe     PlumberTim     Project ManagerTom    DeveloperEtc.Instead of what you're trying which is:PlumberName, Project Manager Name, DeveloperNameJoe               Tom                          Tim</description><pubDate>Tue, 21 Apr 2009 11:34:27 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>[quote][b]Grant Fritchey (3/6/2009)[/b][hr] 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.[/quote]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?</description><pubDate>Tue, 21 Apr 2009 10:48:47 GMT</pubDate><dc:creator>JJ-469859</dc:creator></item><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>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.</description><pubDate>Tue, 21 Apr 2009 00:30:41 GMT</pubDate><dc:creator>StephenMarais</dc:creator></item><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>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.</description><pubDate>Fri, 06 Mar 2009 06:59:26 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>[quote][b]Grant Fritchey (2/27/2009)[/b][hr]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.[/quote]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)ASBEGIN TRANINSERT INTO ChangeRequest(TargetSystem, Description)VALUES (@TargetSystem, @Description)DECLARE @ChangeRequestID intSELECT @ChangeRequestID = Scope_Identity()INSERT INTO ChangeRequestContact(ChangeRequestID, ContactID, ContactType)VALUES(@ChangeRequestID, @TechnicianID, 'Tech')INSERT INTO ChangeRequestContactVALUES(@ChangeRequestID, @ManagerID, 'Manager')INSERT INTO ChangeRequestContactVALUES(@ChangeRequestID, @DirectorID, 'Director')INSERT INTO ChangeRequestContactVALUES(@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 MainContactNameFROM ChangeRequest CRJOIN ChangeRequestContact CRC ON CR.ChangeRequestID = CRC.ChangeRequestID JOIN Contact CT ON CRC.ContactID = CT.ContactIDJOIN Contact CM ON CRC.ContactID = CM.ContactIDJOIN Contact CD ON CRC.ContactID = CD.ContactIDJOIN Contact CMC ON CRC.ContactID = CMC.ContactID--plus four more joins for departmentWHERE ScheduleDate is this month Does this sound right?</description><pubDate>Thu, 05 Mar 2009 11:44:08 GMT</pubDate><dc:creator>JJ-469859</dc:creator></item><item><title>RE: DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>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.</description><pubDate>Fri, 27 Feb 2009 06:01:53 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>DB Design Help</title><link>http://www.sqlservercentral.com/Forums/Topic665493-373-1.aspx</link><description>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.</description><pubDate>Thu, 26 Feb 2009 22:03:51 GMT</pubDate><dc:creator>JJ-469859</dc:creator></item></channel></rss>