June 20, 2018 at 5:42 pm
DesNorton - Wednesday, June 20, 2018 2:20 PMJeff Moden - Wednesday, June 20, 2018 11:01 AMChris Harshman - Wednesday, June 20, 2018 10:56 AMGrant Fritchey - Tuesday, June 19, 2018 2:29 AMOnly concern I have is that looks like a big transaction. Will there be multiple copies of this running at the same time? If so, you could see a lot of blocking across all the tables affected.Also of note, since you have one big transaction for the whole script, if it rolls back you will have lost anything you tried to log as well.
There's a trick to that. Store the log in a Table Valued Variable. Don't write to a permanent table until an error occurs of the run successfully completes.
Another trick that I use is to write it out to a TAB delimited file using xp_CmdShell. There's no chance of it being rolled back then even if the machine were to suddenly lose power. If you need to have the log in a table when your done, just BULK INSERT the data from the file.
Another trick is to use a Loopback Linked Server, and writing outside your session.
Ooooo... that sounds awesome. Didn't know about that one. Makes perfect sense and sounds a lot more resilient than logging to a table variable. Certainly, it's also easier than writing out to a file. Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 21, 2018 at 2:15 am
A simple way to get around the issue of modified_on and modified_by causing records to expand is
a) Use an ID for people (e.g. an int) so it is always small and fixed width - perhaps rename column to modified_by_id
b) Always set modified_on and modified_by_id to the same value as created_on and created_by_id when the record is created
Now, when somebody updates a status_id field or whatever along with modified_on and modified_by_id there is no change in record size.
June 21, 2018 at 8:58 am
mhtanner - Thursday, June 21, 2018 2:15 AMA simple way to get around the issue of modified_on and modified_by causing records to expand is
a) Use an ID for people (e.g. an int) so it is always small and fixed width - perhaps rename column to modified_by_id
b) Always set modified_on and modified_by_id to the same value as created_on and created_by_id when the record is created
Now, when somebody updates a status_id field or whatever along with modified_on and modified_by_id there is no change in record size.
I totally agree with that (it was one of the things I identified in my extended writeup above) but it doesn't help existing "systems" unless people are willing to make the changes in both managed code, in the T-SQL that exists, and in the database itself. For new stuff, it's definitely the way to go.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply