One Way To Track Row Changes In Place In SQL Server

Поділитися
Вставка
  • Опубліковано 11 вер 2024
  • Become a member! / @erikdarlingdata Click here for 50% off a health check: training.erikd...
    If you like what you see here, you'll love my advanced performance tuning training:
    training.erikd...

КОМЕНТАРІ • 29

  • @alexandermayerkirstein
    @alexandermayerkirstein Місяць тому +2

    More each day I find myself newly empowered by your videos selectively drawing on your valuable content. Just this morning I heard myself saying “screw you sql server” and smiled with you in mind. Days just wouldn’t be the same without your videos. Someone please hire this guy.

  • @jleiser22
    @jleiser22 Місяць тому +1

    Well Damn, that's an interesting nugget of information. We use a LastUpdate Column all the time with a default constraint, but of course the hole in that is an UPDATE without an explicit update to said column. And I'm embarrassed to admit we've been using temporal tables for probably 5 years now and I never ran across this temporal column usage without a temporal table.

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      HAHAHA, well there you go. I hope you can use this in your journeys~~

  • @mattcargile
    @mattcargile Місяць тому +1

    Pretty neat. Didn’t realize you could hide a column or utilize partial temporal table features.

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому +1

      Yeah, not something that gets a lot of attention.

  • @FlaggedStar
    @FlaggedStar Місяць тому +2

    One of these days, I'm going to need to figure out how to read the SQL Server documentation from cover to cover. There must be some sort of reading order I can use. You NEVER see features like these talked about anywhere else. I've read many SQL books and this hasn't been mentioned even once!

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      I think it's in T-SQL Querying (Itzik et al) but yeah, this isn't a feature that gets a lot of attention.

    • @FlaggedStar
      @FlaggedStar Місяць тому

      @@ErikDarlingData I don't think it's in that book, unless there's a second edition that I've not heard of.

  • @clerincg
    @clerincg Місяць тому +1

    Hey Erik - EXCELLENT video. I've been doing home-grown CDC incorrectly for a LONG time :) I have a couple of questions. I kinda do what you are with some subtle differences:
    * Why are you using [datetime2] vs [datetime] (higher precision)?
    * I've always used update triggers and you've accomplished the same without them. What triggers the [LastModified] column update without a trigger.
    * You didn't really talk about the need for [JunkDate] and its reference by the PERIOD FOR clause. Not sure what that does (I guess I could read the documentation but it's easier to ask you :) ).
    If I can accomplish my CDC without triggers, that would be AWESOME!!! Thanks again for this video. I'm sure I'm going to start refactoring my CDC stuff thanks to you

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому +1

      1. No particular reason other than some system functions use it, and the additional granularity is nice sometimes. Probably overkill here though.
      2. Temporal versioning handles this internally
      3. I do talk about this in the video, give it another watch. Temporal rows need both.

    • @clerincg
      @clerincg Місяць тому +1

      @@ErikDarlingData Thanks, Erik... I need to research more about Temporal features in SS (new to me).

  • @ianstoll
    @ianstoll Місяць тому

    Pretty cool way to keep a value updated without a trigger, but since the column is locked for adhoc updates, as soon as I implement it, someone will ask that they need to update it to a different value than what is generated.

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      Well, you shouldn't allow that anyway if it's being used for auditing. And of course, if you need it to be newer, just do a simple update to roll the date forward.

  • @douglascoats7081
    @douglascoats7081 Місяць тому +1

    I soft deleted my writing staff. Theyre still here just no longer in charge of writing bad sql jokes :|

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      Hopefully you can rebuild their confidence after the reorg.

  • @vasylpavuk391
    @vasylpavuk391 Місяць тому

    That is an interesting topic. How about using rowversion/timestamp for that?

  • @mumk
    @mumk Місяць тому

    Can you explain why would we prefer this method instead of create a trigger to update the lastModified date?

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      No big reasons. Not having to write a trigger or worry about someone disabling the trigger is nice I suppose.

  • @plsqldba
    @plsqldba Місяць тому +1

    is this version or compatibility specific - i could use this

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      SQL Server 2016 up, where temporal tables were introduced

    • @stephenlawrenson2380
      @stephenlawrenson2380 Місяць тому +1

      In that top 5 of SQL Server features has to be Notification Services - even MS UK didn’t understand how it worked properly!!!

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      @@stephenlawrenson2380 Oof. You're not kidding.

    • @stephenlawrenson2380
      @stephenlawrenson2380 Місяць тому +1

      @@ErikDarlingData we delivered a government project - using notification services back when it was released - I worked with Christian Bolton (MS then) but stayed away from it (NS) on pain of death. The DB’s were on my 3 Node Cluster!! I miss Clusters - AG’s have overheads - some have been addressed in 22 but yet to play with that but still prefer clusters 😀

    • @ErikDarlingData
      @ErikDarlingData  Місяць тому

      @@stephenlawrenson2380 I very much prefer clusters as well.