diff --git a/src/content/doc-surrealql/statements/remove.mdx b/src/content/doc-surrealql/statements/remove.mdx index 8d9440265..5531be4dd 100644 --- a/src/content/doc-surrealql/statements/remove.mdx +++ b/src/content/doc-surrealql/statements/remove.mdx @@ -177,3 +177,45 @@ REMOVE PARAM IF EXISTS $author; REMOVE TABLE IF EXISTS article; ``` + +### Usage in table views + + + +A table used as a source for a table view cannot be removed until the table view itself has been removed. + +```surql +DEFINE TABLE pc; +DEFINE TABLE pc_agg AS SELECT count(), class FROM pc GROUP BY class; +CREATE |pc:3| SET class = "Wizard"; +CREATE |pc:10| SET class = "Warrior"; +SELECT * FROM pc_agg; +-- Error: pc_agg requires pc to work +REMOVE TABLE pc; +REMOVE TABLE pc_agg; +-- pc_agg is now gone, pc can be removed too +REMOVE TABLE pc; +``` + +The `SELECT * FROM pc_agg` query shows that the table view is pulling data from the `pc` table. As long as the `pc` table exists, `pc_agg` cannot be removed. + +```surql +-------- Query -------- + +[ + { + class: 'Warrior', + count: 10, + id: pc_agg:['Warrior'] + }, + { + class: 'Wizard', + count: 3, + id: pc_agg:['Wizard'] + } +] + +-------- Query -------- + +'Invalid query: Cannot delete table `pc` on which a view is defined, table(s) `pc_agg` are defined as a view on this table.' +``` \ No newline at end of file