TransWikia.com

Windows Azure Table Row Key strategy, what makes a useful RowKey?

Database Administrators Asked by Adam Heeg on December 19, 2021

I read somewhere that the row key should be useful – which is why auto numbers are not supported. However, for all 3 tables I’ve started saving I can’t think of anything better to save in the row key column besides a nice, neat auto number.

So let’s discuss a specific case now. I want to log the clients who access my service and simply track their IP address and the requested service and the date of the request.

No single piece of data is unique, and what point is there in creating a Key that blends multiple pieces of data into a single column? I can run a string operation to extract the individual pieces when I get the data and append them when I save it. This seems beyond dumb. I could also create a guid for each entry, but that seems like a more difficult way to use an auto number.

What concept am I missing about saving my entities to a table that will match the RowKey requirement and be meaningful?

my entity looks like so:

public class AccessLog : TableEntity
{
    public AccessLog() { }

    public AccessLog(string partitionKey, string rowKey)
        : base(partitionKey, rowKey)
    {
        this.RowKey = rowKey;
        this.PartitionKey = partitionKey;
    }
    public string ServiceCalled { get; set; }
    public string UserAccount { get; set; }
    public string IpAddress { get; set; }
}

Edit

There is not a correct tag in the list of tags. This is for a
Microsoft Azure -> Storage Account -> Table object.

The question is really a general question. I have gone with using a GUID, but I don’t like it. Timestamp is an idea, but there is already a timestamp column auto generated by the Azure Table mechanics and who knows if 2 people would at any point in time over years have their request processed at the same millisecond.

At the end of the day I think the concept of a row key I found is no more than an ideal which simply doesn’t exist in every practical setting nicely.

One Answer

It's just a requirement of TableStorage that a unique row identifier has to exist. I would probably make the RowKey just a timestamp like DateTime.UtcNow.Ticks.ToString() because you can then sort the records by time. Or you could always use a Guid.NewGuid().ToString() if you're worried about conflicts.

Answered by Jarvis on December 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP