Posts

Choosing SEQUENCE instead of IDENTITY? Watch your step.

Image
On the nice sunny day getting this error message can be really frustrating. In fact, it is frustrating on any day. Especially if you are doing something really simple. Most of you at this moment yell at your monitor “DDL Trigger!!!!” . Yes. I have a simple DDL trigger for auditing purposes. If you use the script below for the auditing table, any DDL statement will get pretty red notification to discard the results. CREATE DATABASE  TestDB ; USE  TestDB ; CREATE  SEQUENCE  GetNextNumber  AS  int  START  WITH  1 INCREMENT  BY  1 ; CREATE  TABLE  dbo . TestAuditTable (         ID             int  NOT  NULL  DEFAULT  NEXT  VALUE  FOR  GetNextNumber  PRIMARY  KEY ,         ChangeDate     datetime ,  ...

Grouping events into intervals using hedgehog rolling style

Image
- I have a challenging SQL problem for you, – yelled one of my coworkers one morning entering my office and dropping on his way a few pictures, SQL server system views map and a visitors chair. – Much more interesting than all your alerts and twitter conversations! ( “Well”, I thought to myself, “it might beat the alerts but not the twitter conversations” ) The problem presented by him is as follows: There is a table containing information about a device’s, like phones or tablets, history of connections to hotspots as shown below: The idea was to bind together the above mentioned events into groups. Each group, or we can call it - an interval, should represent the time that any device was connected to the specific access point. Each time the device has moved to the new access point, a new interval should start. If there were no events for the specific device longer than 30 min, the next event should start a new interval even if the new event was reported on the same access p...