Truncate a table using X++
· One min read
We can use the tableTruncate
method from SqlDataDictionary
to truncate a table in FinOps, useful for a huge SQL table.
public static void main(Args _args)
{
DictTable dictTable = new DictTable(tablenum(KA_TBYTDStaging));
if (dictTable && dictTable.enabled())
{
str sqlTableName = dictTable.name(DbBackend::Sql);
SqlDataDictionary sqlTable = new SqlDataDictionary();
if (sqlTable.tableExist(sqlTableName))
{
new SqlDataDictionaryPermission(methodstr(SqlDataDictionary, tableTruncate)).assert();
sqlTable.tableTruncate(tablenum(KA_TBYTDStaging), false);
CodeAccessPermission::revertAssert();
}
}
}