{"title":"Database.AlterKey(KeyRef, Boolean) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/database/database-alterkey-method/","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/methods-auto/database/database-alterkey-method, 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/methods-auto/database/database-alterkey-method","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":"Alter a table's key in SQL, either disabling or enabling it.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"Database.AlterKey(KeyRef, Boolean) Method","slug":"databasealterkeykeyref-boolean-method","at":0,"chars":1014},{"level":2,"title":"Syntax","slug":"syntax","at":512,"chars":147},{"level":2,"title":"Parameters","slug":"parameters","at":659,"chars":215},{"level":2,"title":"Related information","slug":"related-information","at":874,"chars":140}],"text":"# Database.AlterKey(KeyRef, Boolean) Method\n> Version: _Available or changed with runtime version 13.0._\nAlter a table's key in SQL, either disabling or enabling it. Any alteration only pertains to the current transaction and will be reverted at the end of the current transaction. Any alteration will fail if it's called on System or non-SQL based tables. Disabling clustered or unique keys is also not supported and will fail at runtime.\n> NOTE\n> This method is supported only in Business Central on-premises.\n## Syntax\n```al\n Database.AlterKey(KeyRef: KeyRef, Enable: Boolean)\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nKeyRef\nType: ../keyref/keyref-data-type\nA keyref of the key to alter.\nEnable\nType: ../boolean/boolean-data-type\nWhether to enable or disable a key. Keys that are created as disabled cannot be enabled.\n## Related information\ndatabase-data-type\nGetting Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}