Hi, is it possible to change the order of attributes in a table? If not, how would I go about cloning a table into a new one, but with reordered attributes?
Solved! Go to Solution.
Hi @Meroni,
You cannot modify the order of table attributes at the database level, but you can change them at the LAYERS level at any time.
To modify the attributes' order at the database level, we recommend to clone and reorder the original attributes into a new table as
private static void CloneAndReorderFields(Geodatabase geodatabase, TableDefinition oldTableDefinition)
{
SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
// Old table description
TableDescription oldTableDescription = new TableDescription(oldTableDefinition);
// Old table's field descriptions
List<FieldDescription> oldTableFieldDescriptions = new List<FieldDescription>(oldTableDescription.FieldDescriptions);
// Reordered field descriptions
List<FieldDescription> reorderedFieldDescriptions = new List<FieldDescription>()
{
// Change the order of attribute fields from index 2, 1, 0 (old) to 0, 1, 2 in the new table
oldTableFieldDescriptions[2], oldTableFieldDescriptions[1], oldTableFieldDescriptions[0]
};
// Creating a new reordered table
TableDescription reorderdTableDescription = new TableDescription($"{oldTableDefinition.GetName()}_Reorder", reorderedFieldDescriptions);
// Build the new table
schemaBuilder.Create(reorderdTableDescription);
bool buildStatus= schemaBuilder.Build();
}
Hi @Meroni,
You cannot modify the order of table attributes at the database level, but you can change them at the LAYERS level at any time.
To modify the attributes' order at the database level, we recommend to clone and reorder the original attributes into a new table as
private static void CloneAndReorderFields(Geodatabase geodatabase, TableDefinition oldTableDefinition)
{
SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
// Old table description
TableDescription oldTableDescription = new TableDescription(oldTableDefinition);
// Old table's field descriptions
List<FieldDescription> oldTableFieldDescriptions = new List<FieldDescription>(oldTableDescription.FieldDescriptions);
// Reordered field descriptions
List<FieldDescription> reorderedFieldDescriptions = new List<FieldDescription>()
{
// Change the order of attribute fields from index 2, 1, 0 (old) to 0, 1, 2 in the new table
oldTableFieldDescriptions[2], oldTableFieldDescriptions[1], oldTableFieldDescriptions[0]
};
// Creating a new reordered table
TableDescription reorderdTableDescription = new TableDescription($"{oldTableDefinition.GetName()}_Reorder", reorderedFieldDescriptions);
// Build the new table
schemaBuilder.Create(reorderdTableDescription);
bool buildStatus= schemaBuilder.Build();
}