If this is just to get a unique index I would highly encourage you to use a system sequence, there is no sorting or ordering and it’s a single index scan in a single table
Here’s a walk through on doing that
// Bring in Ice.Lib.NextValue.dll
const string sequenceName = "InvcGrpIDAA";
var nextVal = new Ice.Lib.NextValue(Db);
int nextGroupID = nextVal.GetNextSequence(sequenceName);