Just find opinions on the following two scenarios.
We have a table where we store our outgoing sms messages. Every time one of our services sends a message with a high rate, it stores them in this table ... today all the important information that needs to be saved was in the same format.
SMSMessages ---------------------- ID int PK NOT NULL Identity Mobile nvarchar(50) -- the number we're sending to NetworkID int FK -> Table containing networks (voda, o2, etc...) ShortcodeID int FK -> Table containing our outbound shortcodes DateSent DateTime
Now one of the networks has implemented a completely new API, with which we need to integrate, which requires even more parameters. 1 of these additional options is Team. Depending on the command we are sending, there are 4 to 8 additional parameters that we must send. For simplicity, we will only say two teams there ... "InitialSend" and "AnniversarySend"
Obviously, the rather awful design of the database will simply add all these additional columns to the end of our existing table, so ... we think we have two options.
Option 1.
Create many new tables related to each team related to the original table.
SMSMessages_CommandTypes --Contains "InitialSend" & "AnniversarySend" + other commands -------------------------- CommandTypeID int PK Command nvarchar(50) SMSMessages_OddBallNetwork -------------------------- ID int PK, FK --> SMSMessages.ID CommandTypeID int FK ---> SMSMessages_CommandTypes SMSMessages_OddBallNetwork_InitialSend -------------------------------------- ID int PK, FK --> SMSMessages.ID Param1 nvarchar(50) Param6 nvarchar(50) Param9 nvarchar(50) Param14 nvarchar(50) SMSMessages_OddBallNetwork_AnniversarySend -------------------------------------- ID int PK, FK --> SMSMessages.ID Param1 nvarchar(50) Param2 nvarchar(50) Param7 nvarchar(50) Param9 nvarchar(50) Param12 nvarchar(50)
About it in accordance with our DBA all purists. Each possible combination is highly defined. The relationship is clear, and this is the best performer.
From my POV, the disadvantages are development time, the number of touch points, complex search rules / procedures for messages with different types of commands and the lack of reuse ... a new team in this mobile network or another network, the approach requires the development and implementation of a database level .. .not just code level.
Option 2
This parameter should try to create one dynamic implementation with fewer reusable structures.
SMSMessages_AdditionalParameterTypes ------------------------------------ ParamterTypeID int PK NOT NULL Identity ParamterType nvarchar(50) SMSMessages_AdditionalParameters -------------------------------- ID int PK NOT NULL Identity MessageID int FK --> SMS Messages ParamTypeID int FK --> SMSMessages_AdditionalParameterTypes Value nvarchar(255)
So the pros and cons on this one.
Cons: You have less obvious visibility of which parameters are related to which messages. There is also a small performance problem ... N inserts for each message instead of two
Pros: It is much easier to develop against (imho). You just get a list of parameter names -> Values back for a given message id
It can also be reused ... if the oddball network adds a new team, a new parameter in the team, or even if another network goes and implements a similar API “I want more information”, we don’t need any structural changes in our system.
SO ... What would you do?