At first, as marc_s says, it should only affect SELECT * queries, and not even all of them will necessarily be affected.
Secondly, you just need to specify all non-Null fields in INSERT , so if you make it NULL-compatible, you don’t have to worry about that. In addition, for the Created_Date -type column, it is typical to add the DEFAULT =GetDate() parameter, which will fill it for you if it is not specified.
Third, if you are still worried about the impact of your existing code base, follow these steps:
- Rename the table to something like a “physical table”.
- Create a view with the same name as your table that makes
SELECT .. FROM physicalTable , listing the columns explicitly and in the same order, but do not include the M_DateModified field in it. - Leave your code unmodified, now referring to the view, instead of directly accessing the table.
Now your code can safely interact with the table without any changes (SQL DML code cannot determine the difference between a table and a recordable representation like this).
Finally, this “ModifiedDate” column is a common need and is most often handled by first making it NULL-capable, and then adding the Insert and Update trigger, which installs it automatically:
UPDATE t SET M_DateModified = GetDate() FROM (SELECT * FROM physicalTable y JOIN inserted i ON y.PkId = i.PkId) As t
Therefore, the application does not have to support the field itself. As an added bonus, no application can install it incorrectly or falsely (this is the usual and acceptable use of triggers in SQL).
source share