# ALTER INDEX Modifies the structure of an existing `` on a user `` or ``. ``` ::= ALTER [ UNIQUE ] [ NONCLUSTERED | CLUSTERED ] INDEX [ ] ON {
| } [ ( [ ASC | DESC ] [ ,...n ] ) ] { DISABLE | RESUME} ``` ## API ``` +$ alter-index $: %alter-index name=qualified-object object=qualified-object columns=(list ordered-column) action=index-action == ``` ## Arguments **`UNIQUE`** Specifies that no two rows are permitted to have the same index key value. **`NONCLUSTERED | CLUSTERED`** `CLUSTERED` creates an index in which the logical order of the key values determines the physical order of the corresponding rows in a table. A `
` or `` can have only one clustered index at a time. **`[ ]`** Specifies the target index. **`
| `** Name of the underlying object of the index. **` [ ASC | DESC ] [ ,...n ] `** List of column names in the target table. This list represents the sort hierarchy and optionally specifies the sort direction for each level. The default sorting is `ASC` (ascending). **`DISABLE | RESUME`** Used to disable an active index or resume a disabled index. ## Remarks This command mutates the state of the Obelisk agent. Cannot alter primary key and foreign key indices. `RESUME` will rebuild the index if the underlying object is dirty. Note: Further investigation into hoon ordered maps is needed to determine what exactly "clustered" means in hoon. ## Produced Metadata update `.sys.indices` ## Exceptions index name does not exist for table table does not exist column does not exist UNIQUE specified and existing values are not unique for the column(s) specified # ALTER NAMESPACE Transfer an existing user `
` or `` to another ``. ``` ::= ALTER NAMESPACE [ . ] TRANSFER { TABLE | VIEW } [ ]{
| } ``` ## API ``` +$ alter-namespace $: %alter-namespace database-name=@tas source-namespace=@tas object-type=object-type target-namespace=@tas target-name=@tas == ``` ## Arguments **``** Name of the target namespace into which the object is to be transferred. **`TABLE | VIEW`** Indicates the type of the target object. **`
| `** Name of the object to be transferred to the target namespace.. ## Remarks This command mutates the state of the Obelisk agent. Objects cannot be transferred in or out of namespace *sys*. ## Produced Metadata update `.sys.tables` update `.sys.views` ## Exceptions namespace does not exist `
` or `` does not exist # ALTER PROCEDURE TBD ``` ::= ALTER { PROC | PROCEDURE } [] [ { # } ] [ ,...n ] AS { ; | *hoon } [ ;...n ] ``` # ALTER TABLE Modify the columns and/or ``s of an existing `
`. ``` ::= ALTER TABLE [ ]{
} { ADD COLUMN ( [ ,... n ] ) | ALTER COLUMN ( [ ,... n ] ) | DROP COLUMN ( [ ,... n ] ) | ADD FOREIGN KEY ( [ ,... n ]) REFERENCES [.]
( [ ,... n ]) [ ON DELETE { NO ACTION | CASCADE } ] [ ON UPDATE { NO ACTION | CASCADE } ] [ ,... n ] | DROP FOREIGN KEY ( [ ,... n ] } ) ``` Example: ``` ALTER TABLE my-table DROP FOREIGN KEY fk-1, fk-2 ``` ## API ``` +$ alter-table $: %alter-table table=qualified-object alter-columns=(list column) add-columns=(list column) drop-columns=(list @tas) add-foreign-keys=(list foreign-key) drop-foreign-keys=(list @tas) == ``` ## Arguments **`
`** Name of `
` to alter. **`ADD | ALTER COLUMN ( [ ,... n ] )`** Denotes a list of user-defined column names and associated auras. `ALTER` is used to change the aura of an existing column. Names must follow the Hoon term naming standard. See [ref-ch02-types](ref-ch02-types.md) **`DROP COLUMN ( [ ,... n ] )`** Denotes a list of existing column names to delete from the `
` structure. **`[ NONCLUSTERED | CLUSTERED ] ( [ ,... n ]`** These are column names in the required unique primary index. Defining the index as `CLUSTERED` is optional. **`ADD | DROP`** The action is to add or drop a foreign key. **` ( [ ASC | DESC ] [ ,... n ]`** This is a user-defined name for ``. It must adhere to the hoon term naming standard. This list comprises column names in the table for association with a foreign table along with sort ordering. Default is `ASC` (ascending). **`
( [ ,... n ]`** Referenced foreign `
` and columns. Count and associated column auras must match the specified columns from the new `
` and comprise a `UNIQUE` index on the referenced foreign `
`. **`ON DELETE { NO ACTION | CASCADE | SET DEFAULT }`** This argument specifies the action to be taken on the rows in the table that have a referential relationship when the referenced row is deleted from the foreign table. * NO ACTION (default) The Obelisk agent raises an error and the delete action on the row in the parent foreign table is aborted. * CASCADE Corresponding rows are deleted from the referencing table when that row is deleted from the parent foreign table. * SET DEFAULT All the values that make up the foreign key in the referencing row(s) are set to their bunt (default) values when the corresponding row in the parent foreign table is deleted. The Obelisk agent raises an error if the parent foreign table has no entry with bunt values. **`ON UPDATE { NO ACTION | CASCADE | SET DEFAULT }`** This argument specifies the action to be taken on the rows in the table that have a referential relationship when the referenced row is updated in the foreign table. * NO ACTION (default) The Database Engine raises an error and the update action on the row in the parent table is aborted. * CASCADE Corresponding rows are updated in the referencing table when that row is updated in the parent table. * SET DEFAULT All the values that make up the foreign key in the referencing row(s) are set to their bunt (default) values when the corresponding row in the parent foreign table is updated. The Obelisk agent raises an error if the parent foreign table has no entry with bunt values. ## Remarks This command mutates the state of the Obelisk agent. `FOREIGN KEY` constraints ensure data integrity for the data contained in the column or columns. They necessitate that each value in the column exists in the corresponding referenced column or columns in the referenced table. `FOREIGN KEY` constraints can only reference columns that are subject to a `PRIMARY KEY` or `UNIQUE INDEX` constraint in the referenced table. ## Produced Metadata update `.sys.table-columns` update `.sys.table-columns` update `.sys.table-ref-integrity` ## Exceptions alter a column that does not exist add a column that does exist drop a column that does not exist table referenced by FOREIGN KEY does not exist table column referenced by FOREIGN KEY does not exist aura mis-match in FOREIGN KEY # ALTER TRIGGER TBD ``` ::= ALTER TRIGGER { [ ]{ } | ALL } ON { SERVER | |
| } [ ENABLE | DISABLE ] ``` # ALTER VIEW Alter the structure of an existing ``. ``` ::= ALTER VIEW [ ]{ } ( { [.] } [ ,...n ] ) AS ``` ## API ``` +$ alter-view $: %alter-view view=qualified-object transform == ``` ## Arguments **``** Specifies the name of the view to alter. **``** Refers to the `` producing the output ``. ## Remarks This command mutates the state of the Obelisk agent. ## Produced Metadata UPDATE `.sys.views` UPDATE `.sys.view-columns` ## Exceptions view does not exist.