{"title":"AppSourceCop Error AS0009","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/appsourcecop-as0009/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0009, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0009","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"The list of fields for the primary key or for the clustered key must not be changed.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"AppSourceCop Error AS0009","slug":"appsourcecop-error-as0009","at":0,"chars":4138},{"level":2,"title":"Description","slug":"description","at":59,"chars":100},{"level":2,"title":"Remarks","slug":"remarks","at":159,"chars":459},{"level":2,"title":"How to fix this diagnostic?","slug":"how-to-fix-this-diagnostic","at":618,"chars":261},{"level":2,"title":"Code examples triggering the rule","slug":"code-examples-triggering-the-rule","at":879,"chars":2075},{"level":3,"title":"Example 1 - Modifying a field in the list","slug":"example-1---modifying-a-field-in-the-list","at":1458,"chars":516},{"level":3,"title":"Example 2 - Removing a field in the list","slug":"example-2---removing-a-field-in-the-list","at":1974,"chars":478},{"level":3,"title":"Example 3 - Adding a field in the list","slug":"example-3---adding-a-field-in-the-list","at":2452,"chars":502},{"level":2,"title":"Code example not triggering the rule","slug":"code-example-not-triggering-the-rule","at":2954,"chars":1037},{"level":2,"title":"Related information","slug":"related-information","at":3991,"chars":147}],"text":"# AppSourceCop Error AS0009\nKey fields must not be changed\n## Description\nThe list of fields for the primary key or for the clustered key must not be changed.\n## Remarks\nIt is not allowed to change the list of fields for the primary key or for the clustered key<../properties/devenv-clustered-property> because this will break upgrade of existing installations. For more information on table keys, see ../devenv-table-keys.\n> NOTE\n> This rule validates tables independently of their Accessibility or ObsoleteState, because tables are always used when synchronizing the schema defined in the extension to the database.\n## How to fix this diagnostic?\nTo fix this diagnostic, you must revert the changes done in the current version of your extension so that the list of fields for the primary key or the clustered key matches the one defined for the key in your baseline extension.\n## Code examples triggering the rule\nFor the following examples, version 1.0 of the extension defines the following table:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField, MyDateField) { }\n    }\n}\n```\nThese examples are demonstrating breaking changes done on the primary key. Similar examples could be done on the clustered key:\n```al\nkey(clusteredKey; MyIntegerField)\n{\n    Clustered = true;\n}\n```\n### Example 1 - Modifying a field in the list\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField, MyTextField) { }\n    }\n}\n```\nIn version 2.0, the field MyDateField has been replaced by the field MyTextField in the list of fields for the primary key. This change is not allowed by the synchronization engine.\n### Example 2 - Removing a field in the list\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n    }\n}\n```\nIn version 2.0, the field MyDateField has been removed from the list of fields for the primary key. This change is not allowed by the synchronization engine.\n### Example 3 - Adding a field in the list\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField, MyDateField, MyTextField) { }\n    }\n}\n```\nIn the version 2.0, the field MyTextField has been added to the list of fields for the primary key. This change is not allowed by the synchronization engine.\n## Code example not triggering the rule\nAny changes done on a key which is not the primary key or the clustered key are allowed, see the following examples.\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n        key(SimpleKey; MyDateField) { }\n    }\n}\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(1; MyIntegerField; Integer) { }\n        field(2; MyDateField; Date) { }\n        field(3; MyTextField; Text[50]) { }\n    }\n\n    keys\n    {\n        key(PK; MyIntegerField) { }\n        key(SimpleKey; MyTextField) { }\n    }\n}\n```\nIn version 2.0, the field MyDateField has been replaced by the field MyTextField in the list of fields for the key SimpleKey. This change is allowed by the synchronization engine because SimpleKey is not the primary key and is not the clustered key.\n## Related information\nAppSourceCop Analyzer<appsourcecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}