• TheSQLGuru - Friday, January 26, 2018 2:08 PM

    Wait - am I seeing correctly that your sproc actually creates the log record? If so, why isn't it simply putting the database info in the row it creates?

    If it isn't, what is creating the initial error log row? Whatever it is should be populating ALL FIELDS! It is TERRIBLY inefficient to insert a row and then turn around an update it with data that you should have had on insert.

    Also, look up db_id() and db_name() system functions. 

    Oh. and why are you storing both the database name and the database id? Same goes for procedure name and object id, right?? Wasted storage with zero benefit.

    But the database_id and object_id can both change.  Thus, it's really required to store the name to be accurate.  And storing the existing id isn't that much space and so not necessarily a terrible idea, just for reference purposes.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.