Skip to content

Statements

/

ALTER

ALTER TABLE

The ALTER TABLE statement is used to alter a defined table.

SurrealQL Syntax
ALTER TABLE [
	[ IF EXISTS ] @name
		[ DROP COMMENT ]
        [ DROP CHANGEFEED ]
        [ DROP INLINE EDGES ]
        [ DROP INLINE REFERENCES ]
        [ COMPACT ]
		[ SCHEMAFULL | SCHEMALESS ]
		[ TYPE [ ANY | NORMAL | RELATION [ [ IN | FROM ] @table ] [ [ OUT | TO ] @table ] [ ENFORCED ] [ LIGHTWEIGHT ]]]
		[ PERMISSIONS [ NONE | FULL
			| FOR select @expression
			| FOR create @expression
			| FOR update @expression
			| FOR delete @expression
		] ]
    [ CHANGEFEED @duration [ INCLUDE ORIGINAL ] ]
    [ COMMENT @string ] 
    [ INLINE EDGES @number ]
    [ INLINE REFERENCES @number ]
]

Available since: v3.0.0

Performs storage compaction on a specific table keyspace. To compact other resources, use ALTER SYSTEM to compact the entire datastore, ALTER NAMESPACE to compact the current namespace keyspace, or ALTER DATABASE to compact the current database keyspace.

The actual compaction used will depend on the datastore, such as RocksDB or SurrealKV.

This clause will not work with in-memory storage which has nothing persistent to compact, producing the following error:

'The storage layer does not support compaction requests.'

A successful compaction will return NONE.

ALTER TABLE user COMPACT;
Output
NONE

Available since: v3.3.0

INLINE EDGES @number and INLINE REFERENCES @number set or change the cap of a table's adjacency and reference caches, from 0 to 256. DROP INLINE EDGES and DROP INLINE REFERENCES remove a cap, which turns that cache off. One statement can set one cap and drop the other:

ALTER TABLE person INLINE EDGES 8 DROP INLINE REFERENCES;

Any change to a cap discards the table's existing caches of that kind. They are rebuilt as edges or references are written.

Was this page helpful?