Skip to content
Closed
Show file tree
Hide file tree
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: 4 additions & 52 deletions src/current/v23.1/alter-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen

## Required privileges

- To alter a sequence, the user must have the `CREATE` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the parent database.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, or to change the database of a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must also have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence.
- To alter a sequence, the user must be the owner of the sequence.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the new schema.
- To rename a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the sequence's database.

## Syntax

Expand All @@ -26,7 +27,7 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen
-----------|------------
`IF EXISTS` | Modify the sequence only if it exists; if it does not exist, do not return an error.
`sequence_name` | The name of the sequence.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>Note that `RENAME TO` can be used to move a sequence from one database to another, but it cannot be used to move a sequence from one schema to another. To change a sequence's schema, use `ALTER SEQUENCE ...SET SCHEMA` instead.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>`RENAME TO` only changes the name of the sequence; it cannot move the sequence to a different database or schema. To change a sequence's schema, use `ALTER SEQUENCE ... SET SCHEMA` instead.
`CYCLE`/`NO CYCLE` | The sequence will wrap around when the sequence value reaches the maximum or minimum value. `CYCLE` is not implemented. If `NO CYCLE` is set, the sequence will not wrap.
`OWNED BY column_name` | Associates the sequence to a particular column. If that column or its parent table is dropped, the sequence will also be dropped.<br><br>Specifying an owner column with `OWNED BY` replaces any existing owner column on the sequence. To remove existing column ownership on the sequence and make the column free-standing, specify `OWNED BY NONE`.<br><br>**Default:** `NONE`
`CACHE` | The number of sequence values to cache in memory for reuse in the session. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:** `1` (sequences are not cached by default)
Expand Down Expand Up @@ -112,55 +113,6 @@ In this example, we will change the name of sequence.
(1 row)
~~~

### Change the database of a sequence

In this example, we will move the sequence we renamed in the first example (`even_sequence`) from `defaultdb` (i.e., the default database) to a different database.

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> CREATE DATABASE mydb;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> ALTER SEQUENCE even_sequence RENAME TO mydb.even_sequence;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
(0 rows)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM mydb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

### Change the schema of a sequence

Suppose you [create a sequence]({% link {{ page.version.version }}/create-sequence.md %}) that you would like to add to a new schema called `cockroach_labs`:
Expand Down
2 changes: 1 addition & 1 deletion src/current/v23.1/alter-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ For examples, see [Rename tables](#rename-tables).

#### Required privileges

The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database. When moving a table from one database to another, the user must have the `CREATE` privilege on both the source and target databases.
The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database.

#### Parameters

Expand Down
6 changes: 3 additions & 3 deletions src/current/v23.1/alter-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The `ALTER VIEW` [statement]({% link {{ page.version.version }}/sql-statements.m

## Required privileges

- To alter a view, the user must have the `CREATE` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the parent database.
- To change the schema of a view with `ALTER VIEW ... SET SCHEMA`, or to change the name of a view with `ALTER VIEW ... RENAME TO`, the user must also have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view.
- To change the schema of a view with `ALTER VIEW ... SET SCHEMA`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view and the `CREATE` privilege on the new schema.
- To rename a view with `ALTER VIEW ... RENAME TO`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view and the `CREATE` privilege on the view's database.

## Syntax

Expand Down Expand Up @@ -81,7 +81,7 @@ WITH x AS (SHOW TABLES) SELECT * FROM x WHERE type = 'view';
(1 row)
~~~

Note that `RENAME TO` can be used to move a view from one database to another, but it cannot be used to move a view from one schema to another. To change a view's schema, [use the `SET SCHEMA` clause](#change-the-schema-of-a-view). In a future release, `RENAME TO` will be limited to changing the name of a view, and will not have the ability to change a view's database.
Note that `RENAME TO` only changes the name of the view; it cannot move the view to a different database or schema. To change a view's schema, [use the `SET SCHEMA` clause](#change-the-schema-of-a-view).

### Change the schema of a view

Expand Down
56 changes: 4 additions & 52 deletions src/current/v23.2/alter-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen

## Required privileges

- To alter a sequence, the user must have the `CREATE` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the parent database.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, or to change the database of a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must also have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence.
- To alter a sequence, the user must be the owner of the sequence.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the new schema.
- To rename a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the sequence's database.

## Syntax

Expand All @@ -26,7 +27,7 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen
-----------|------------
`IF EXISTS` | Modify the sequence only if it exists; if it does not exist, do not return an error.
`sequence_name` | The name of the sequence.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>Note that `RENAME TO` can be used to move a sequence from one database to another, but it cannot be used to move a sequence from one schema to another. To change a sequence's schema, use `ALTER SEQUENCE ...SET SCHEMA` instead.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>`RENAME TO` only changes the name of the sequence; it cannot move the sequence to a different database or schema. To change a sequence's schema, use `ALTER SEQUENCE ... SET SCHEMA` instead.
`CYCLE`/`NO CYCLE` | The sequence will wrap around when the sequence value reaches the maximum or minimum value. `CYCLE` is not implemented. If `NO CYCLE` is set, the sequence will not wrap.
`OWNED BY column_name` | Associates the sequence to a particular column. If that column or its parent table is dropped, the sequence will also be dropped.<br><br>Specifying an owner column with `OWNED BY` replaces any existing owner column on the sequence. To remove existing column ownership on the sequence and make the column free-standing, specify `OWNED BY NONE`.<br><br>**Default:** `NONE`
`CACHE` | The number of sequence values to cache in memory for reuse in the session. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:** `1` (sequences are not cached by default)
Expand Down Expand Up @@ -112,55 +113,6 @@ In this example, we will change the name of sequence.
(1 row)
~~~

### Change the database of a sequence

In this example, we will move the sequence we renamed in the first example (`even_sequence`) from `defaultdb` (i.e., the default database) to a different database.

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> CREATE DATABASE mydb;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> ALTER SEQUENCE even_sequence RENAME TO mydb.even_sequence;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
(0 rows)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM mydb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

### Change the schema of a sequence

Suppose you [create a sequence]({% link {{ page.version.version }}/create-sequence.md %}) that you would like to add to a new schema called `cockroach_labs`:
Expand Down
2 changes: 1 addition & 1 deletion src/current/v23.2/alter-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ For examples, see [Rename tables](#rename-tables).

#### Required privileges

The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database. When moving a table from one database to another, the user must have the `CREATE` privilege on both the source and target databases.
The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database.

#### Parameters

Expand Down
6 changes: 3 additions & 3 deletions src/current/v23.2/alter-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The `ALTER VIEW` [statement]({% link {{ page.version.version }}/sql-statements.m

## Required privileges

- To alter a view, the user must have the `CREATE` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the parent database.
- To change the schema of a view with `ALTER VIEW ... SET SCHEMA`, or to change the name of a view with `ALTER VIEW ... RENAME TO`, the user must also have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view.
- To change the schema of a view with `ALTER VIEW ... SET SCHEMA`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view and the `CREATE` privilege on the new schema.
- To rename a view with `ALTER VIEW ... RENAME TO`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the view and the `CREATE` privilege on the view's database.

## Syntax

Expand Down Expand Up @@ -81,7 +81,7 @@ WITH x AS (SHOW TABLES) SELECT * FROM x WHERE type = 'view';
(1 row)
~~~

Note that `RENAME TO` can be used to move a view from one database to another, but it cannot be used to move a view from one schema to another. To change a view's schema, [use the `SET SCHEMA` clause](#change-the-schema-of-a-view). In a future release, `RENAME TO` will be limited to changing the name of a view, and will not have the ability to change a view's database.
Note that `RENAME TO` only changes the name of the view; it cannot move the view to a different database or schema. To change a view's schema, [use the `SET SCHEMA` clause](#change-the-schema-of-a-view).

### Change the schema of a view

Expand Down
56 changes: 4 additions & 52 deletions src/current/v24.1/alter-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen

## Required privileges

- To alter a sequence, the user must have the `CREATE` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the parent database.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, or to change the database of a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must also have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence.
- To alter a sequence, the user must be the owner of the sequence.
- To change the schema of a sequence with `ALTER SEQUENCE ... SET SCHEMA`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the new schema.
- To rename a sequence with `ALTER SEQUENCE ... RENAME TO`, the user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the sequence and the `CREATE` privilege on the sequence's database.

## Syntax

Expand All @@ -26,7 +27,7 @@ The `ALTER SEQUENCE` [statement]({% link {{ page.version.version }}/sql-statemen
-----------|------------
`IF EXISTS` | Modify the sequence only if it exists; if it does not exist, do not return an error.
`sequence_name` | The name of the sequence.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>Note that `RENAME TO` can be used to move a sequence from one database to another, but it cannot be used to move a sequence from one schema to another. To change a sequence's schema, use `ALTER SEQUENCE ...SET SCHEMA` instead.
`RENAME TO sequence_name` | Rename the sequence to `sequence_name`, which must be unique to its database and follow these [identifier rules]({% link {{ page.version.version }}/keywords-and-identifiers.md %}#identifiers). Name changes do not propagate to the table(s) using the sequence.<br><br>`RENAME TO` only changes the name of the sequence; it cannot move the sequence to a different database or schema. To change a sequence's schema, use `ALTER SEQUENCE ... SET SCHEMA` instead.
`CYCLE`/`NO CYCLE` | The sequence will wrap around when the sequence value reaches the maximum or minimum value. `CYCLE` is not implemented. If `NO CYCLE` is set, the sequence will not wrap.
`OWNED BY column_name` | Associates the sequence to a particular column. If that column or its parent table is dropped, the sequence will also be dropped.<br><br>Specifying an owner column with `OWNED BY` replaces any existing owner column on the sequence. To remove existing column ownership on the sequence and make the column free-standing, specify `OWNED BY NONE`.<br><br>**Default:** `NONE`
`CACHE` | The number of sequence values to cache in memory for reuse in the session. A cache size of `1` means that there is no cache, and cache sizes of less than `1` are not valid.<br><br>**Default:** `1` (sequences are not cached by default)
Expand Down Expand Up @@ -112,55 +113,6 @@ In this example, we will change the name of sequence.
(1 row)
~~~

### Change the database of a sequence

In this example, we will move the sequence we renamed in the first example (`even_sequence`) from `defaultdb` (i.e., the default database) to a different database.

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> CREATE DATABASE mydb;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> ALTER SEQUENCE even_sequence RENAME TO mydb.even_sequence;
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM defaultdb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
(0 rows)
~~~

{% include_cached copy-clipboard.html %}
~~~ sql
> SHOW SEQUENCES FROM mydb;
~~~

~~~
sequence_schema | sequence_name
------------------+----------------
public | even_sequence
(1 row)
~~~

### Change the schema of a sequence

Suppose you [create a sequence]({% link {{ page.version.version }}/create-sequence.md %}) that you would like to add to a new schema called `cockroach_labs`:
Expand Down
2 changes: 1 addition & 1 deletion src/current/v24.1/alter-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ For examples, see [Rename tables](#rename-tables).

#### Required privileges

The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database. When moving a table from one database to another, the user must have the `CREATE` privilege on both the source and target databases.
The user must have the `DROP` [privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#managing-privileges) on the table and the `CREATE` on the parent database.

#### Parameters

Expand Down
Loading
Loading