You can create a new integer field AttributeNum. You can override the insert() or the initValue() on the table depending on you requirement. Choose initValue() over insert() if you would like to keep your set-based operation fast on this table.
In the overriden method you can use query to aggregate and count the number of attributes per your current record.
Edit:
Alternately you can just override the validateWrite()
method on the table.
boolean validateWrite()
{
TableA tableA;
boolean ret = super();
#define.MaxAttributes(5) // consider using setup
if (ret && !this.RecId)
{
select count(RecId) from tableA where tableA.PlayerId == this.PlayerId;
if (tableA.RecId >= #MaxAttributes)
{
ret = checkFailed("Error message goes here");
}
}
return ret;
}
You didn't specify if the attributes should be unique per player or not but you should also consider creating the appropriate index in order to enforce data integrity.
You can find more information here:
Maintain Fast SQL Operations [AX 2012]
Speeding Up SQL Operations [AX 2012]
Maintaining Data Integrity [AX 2012]