Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/current/v26.2/alter-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ Subcommand | Description | Can combine with other subcommands?
[`ALTER PRIMARY KEY`](#alter-primary-key) | Change the [primary key]({% link {{ page.version.version }}/primary-key.md %}) of a table. | Yes
[`CONFIGURE ZONE`](#configure-zone) | [Replication Controls]({% link {{ page.version.version }}/configure-replication-zones.md %}) for a table. | No
[`DISABLE ROW LEVEL SECURITY`](#disable-row-level-security) | Disable [row-level security]({% link {{ page.version.version }}/row-level-security.md %}) for a table. | Yes
[`DISABLE TRIGGER`](#disable-trigger) | Disable a [trigger]({% link {{ page.version.version }}/triggers.md %}) for a table. | Yes
[`DROP COLUMN`](#drop-column) | Remove columns from tables. | Yes
[`DROP CONSTRAINT`](#drop-constraint) | Remove constraints from columns. | Yes
[`ENABLE ROW LEVEL SECURITY`](#enable-row-level-security) | Enable [row-level security]({% link {{ page.version.version }}/row-level-security.md %}) for a table. | Yes
[`ENABLE TRIGGER`](#enable-trigger) | Enable a [trigger]({% link {{ page.version.version }}/triggers.md %}) for a table. | Yes
[`EXPERIMENTAL_AUDIT`](#experimental_audit) | Enable per-table audit logs, for security purposes. | Yes
[`FORCE / NO FORCE ROW LEVEL SECURITY`](#force-row-level-security) | Force the table owner to be subject to [row-level security]({% link {{ page.version.version }}/row-level-security.md %}) policies defined on a table. | Yes
[`OWNER TO`](#owner-to) | Change the owner of the table. | No
Expand Down Expand Up @@ -501,6 +503,18 @@ This statement disables [Row-level security]({% link {{ page.version.version }}/

For examples, refer to [Disable row-level security](#disable-row-level-security).

### `ENABLE TRIGGER`

This statement enables a [trigger]({% link {{ page.version.version }}/triggers.md %}) associated with a table. When a trigger is enabled for a table, it activates if its triggering event occurs on the table. Use `ENABLE TRIGGER ALL` or `ENABLE TRIGGER USER` to enable all triggers associated with a table.

For examples, refer to [Enable a trigger](#enable-a-trigger).

### `DISABLE TRIGGER`

This statement disables a [trigger]({% link {{ page.version.version }}/triggers.md %}) associated with a table. When a trigger is disabled for a table, it does not activate even if its triggering event occurs on the table. Use `DISABLE TRIGGER ALL` or `DISABLE TRIGGER USER` to disable all triggers associated with a table.
Comment on lines +506 to +514
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think readers will wonder what the difference is between DISABLE TRIGGER ALL and DISABLE TRIGGER USER.

I found the answer from the implementation PR (#161924).

In case it helps (maybe you were already aware!) in CockroachDB, ALL and USER do the exact same thing. These are both present for compatibility with PostgreSQL, which distinguishes between system and user triggers. In CRDB, both affect all triggers on the table, since we don't have system triggers.

Consider a callout like this?

ALL and USER are both available for compatibility with PostgreSQL syntax, though in CockroachDB they behave identically. (CockroachDB does not have system triggers.) Both keywords will enable/disable all triggers associated with the table.

I would probably include this again under Enable a trigger, so that users who end up there first will also see it.


For examples, refer to [Disable a trigger](#disable-a-trigger).

#### Required privileges

The user must be a member of the [`admin`]({% link {{ page.version.version }}/security-reference/authorization.md %}#roles) or [owner]({% link {{ page.version.version }}/security-reference/authorization.md %}#object-ownership) roles.
Expand Down Expand Up @@ -3415,6 +3429,48 @@ ALTER TABLE orders NO FORCE ROW LEVEL SECURITY;
Users with the `BYPASSRLS` [role option]({% link {{ page.version.version }}/security-reference/authorization.md %}#role-options) can still bypass RLS even when `ALTER TABLE ... FORCE ROW LEVEL SECURITY` is enabled.
{{site.data.alerts.end}}

### Enable a trigger

To enable a [trigger]({% link {{ page.version.version }}/triggers.md %}) associated with a table, use the following statement:

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> ENABLE TRIGGER <trigger_name>;
~~~
Comment on lines +3435 to +3439
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> ENABLE TRIGGER <trigger_name>;
~~~
{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> ENABLE TRIGGER <trigger_name>;
~~~
This requires an existing trigger. For information on creating a trigger, refer to [Triggers]({% link {{ page.version.version }}/triggers.md %}).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized this was implied throughout the updates but never explicit. One option for your consideration.


To enable all triggers associated with a table, use either of the following statements:

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> ENABLE TRIGGER ALL;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> ENABLE TRIGGER USER;
~~~

### Disable a trigger

To disable a [trigger]({% link {{ page.version.version }}/triggers.md %}) associated with a table, use the following statement:

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> DISABLE TRIGGER <trigger_name>;
~~~

To disable all triggers associated with a table, use either of the following statements:

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> DISABLE TRIGGER ALL;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
ALTER TABLE <table_name> DISABLE TRIGGER USER;
~~~

## See also

- [Multi-Region Capabilities Overview]({% link {{ page.version.version }}/multiregion-overview.md %})
Expand Down
Loading