Forum Discussion
Could not find stored procedure 'OPTIMIZE' in Synapse
Hi Kam , yes, your suspicion is basically right, but the error also gives a clue about where the command is being run.
Could not find stored procedure 'OPTIMIZE' normally means Synapse is treating this as a T-SQL command, so you are likely running it from a Synapse SQL script, serverless SQL pool, or dedicated SQL pool. OPTIMIZE is a Delta/Spark table maintenance command, not a SQL stored procedure in Synapse SQL.
Try running it from a Spark notebook attached to a Synapse Spark pool, for example:
%%sql
OPTIMIZE delta.`/path/to/delta/table`
Or, if the Delta table is registered in the Spark catalog:
%%sql
OPTIMIZE database_name.table_name
Also note the syntax difference: use delta.\path`for a path-based Delta table, not justOPTIMIZE '/path/to/delta/table'`