From 18c62901a33243c49ba88f07e6b538bb92e0cc6b Mon Sep 17 00:00:00 2001
From: Jesse Seldess
referenced by:
referenced by: +
referenced by: +
referenced by: +
referenced by:
referenced by: +
referenced by: +
referenced by: -
referenced by:
referenced by: -
referenced by: +
referenced by: +
referenced by:
referenced by: +
referenced by:
referenced by: +
referenced by:
referenced by: +
referenced by: +
referenced by: +
beta-20160629
are not be compatible with earlier versions of CockroachDB.{{site.data.alerts.end}}
+
+
+
+## Overview
+
+When a row is inserted into a table with column families, CockroachDB stores the values for each column family as a single key-value pair. For example, consider a table with 2 columns, where the columns are grouped into a column family:
+
+~~~ sql
+CREATE TABLE t1 (
+ a STRING PRIMARY KEY,
+ b INT,
+ FAMILY f1 (a, b)
+);
+~~~
+
+Inserting 10 rows into this table would create 10 underlying key-value pairs, 1 per row. In contrast, if the table's columns were not grouped into a family, each column and value would be a distinct key-value pair; thus, inserting 10 rows would create 20 underlying key-value pairs, 2 per row.
+
+## Using Column Families
+
+Column families are defined at [table creation](create-table.html). Currently, when you create a table, each column is implicitly its own column family, for example:
+
+~~~ sql
+CREATE TABLE t2 (
+ a STRING PRIMARY KEY,
+ b INT
+);
+
+SHOW CREATE TABLE t2;
++-------+--------------------------------------------+
+| Table | CreateTable |
++-------+--------------------------------------------+
+| t2 | CREATE TABLE t2 ( |
+| | a STRING NOT NULL, |
+| | b INT NULL, |
+| | CONSTRAINT "primary" PRIMARY KEY (a), |
+| | FAMILY "primary" (a), |
+| | FAMILY fam_2_b (b) |
+| | ) |
++-------+--------------------------------------------+
+(1 row)
+~~~
+
+To group columns into multi-column families, you must use the `FAMILY` keyword, for example:
+
+~~~ sql
+CREATE TABLE t3 (
+ a STRING PRIMARY KEY,
+ b INT,
+ FAMILY f1 (a, b)
+);
+
+SHOW CREATE TABLE t3;
++-------+--------------------------------------------+
+| Table | CreateTable |
++-------+--------------------------------------------+
+| t3 | CREATE TABLE t3 ( |
+| | a STRING NOT NULL, |
+| | b INT NULL, |
+| | CONSTRAINT "primary" PRIMARY KEY (a), |
+| | FAMILY f1 (a, b) |
+| | ) |
++-------+--------------------------------------------+
+(1 row)
+~~~
+
+## Upcoming Improvements
+
+In an upcoming release, you won't need to define column families manually. Instead, CockroachDB will group columns into families for you when a table is created. CockroachDB's default groupings will ensure optimal storage and performance, but you will still have the option to define your own groups using the `FAMILY` keyword, as show above.
+
+## See Also
+
+- [`CREATE TABLE`](create-table.html)
+- [Data Definition](data-definition.html)
\ No newline at end of file
diff --git a/create-table.md b/create-table.md
index 45ae31ea74d..b737f857f13 100644
--- a/create-table.md
+++ b/create-table.md
@@ -79,7 +79,8 @@ Parameter | Description
`any_name` | The name of the table to create, which must be unique within its database and follow these [identifier rules](keywords-and-identifiers.html#identifiers). When the parent database is not set as the default, the name must be formatted as `database.name`.SHOW INDEX
.{{site.data.alerts.end}}
-~~~
-> CREATE TABLE logon (user_id INT, logon_date DATE);
+~~~ sql
+> CREATE TABLE logon (
+ user_id INT,
+ logon_date DATE
+ );
CREATE TABLE
> SHOW COLUMNS FROM logon;
diff --git a/data-definition.md b/data-definition.md
index 8f5bad23cb8..dfb61904b3d 100644
--- a/data-definition.md
+++ b/data-definition.md
@@ -8,5 +8,6 @@ Click a topic for details.
- [Keywords & Identifiers](keywords-and-identifiers.html)
- [Constraints](constraints.html)
-- [NULL Handling](null-handling.html)
+- [Column Families](column-families.html)
- [Indexes](indexes.html)
+- [NULL Handling](null-handling.html)
diff --git a/frequently-asked-questions.md b/frequently-asked-questions.md
index ced8d58ee5d..2fb52943fd9 100644
--- a/frequently-asked-questions.md
+++ b/frequently-asked-questions.md
@@ -145,7 +145,7 @@ Not yet, but this is on our long-term roadmap.
## Can I use CockroachDB as a key-value store?
-CockroachDB is a distributed SQL database built on a transactional and strongly-consistent key-value store. At this time, it is not possible to access the key-value store directly. As an alternative, you can [create a SQL table](create-table.html) with two columns, `k` and `v`, and set `k` as the primary key.
+CockroachDB is a distributed SQL database built on a transactional and strongly-consistent key-value store. At this time, it is not possible to access the key-value store directly. As an alternative, you can [create a SQL table](create-table.html) with two columns, `k` and `v`, and set `k` as the primary key. Note that if you group these columns into a single [column family](column-families.html), each row will be stored as a single key-value pair in the underlying key-value store.
## Have questions that weren’t answered?
From 2aec0b34cabb003fc044cb6e58c2f9d4234421fa Mon Sep 17 00:00:00 2001
From: Jesse Seldess beta-20160629
are not be compatible with earlier versions of CockroachDB.{{site.data.alerts.end}}
+{{site.data.alerts.callout_info}}New tables created with multi-column families will not be compatible with versions of CockroachDB earlier than beta-20160630
.{{site.data.alerts.end}}
## Overview
-When a row is inserted into a table with column families, CockroachDB stores the values for each column family as a single key-value pair. For example, consider a table with 2 columns, where the columns are grouped into a column family:
+When a row is inserted into a table with column families, CockroachDB stores a single key-value pair per family. For example, consider a table with 2 columns, where the columns are grouped into a column family:
~~~ sql
CREATE TABLE t1 (
@@ -22,7 +22,7 @@ CREATE TABLE t1 (
);
~~~
-Inserting 10 rows into this table would create 10 underlying key-value pairs, 1 per row. In contrast, if the table's columns were not grouped into a family, each column and value would be a distinct key-value pair; thus, inserting 10 rows would create 20 underlying key-value pairs, 2 per row.
+Inserting 10 rows into this table would create 10 underlying key-value pairs, 1 per row. This is a significant improvement over earlier versions of CockroachDB, where inserting 10 rows would have created 30 underlying key-value pairs, 3 per row: one key-value pair per column plus an extra key-value pair per row.
## Using Column Families
@@ -74,7 +74,7 @@ SHOW CREATE TABLE t3;
## Upcoming Improvements
-In an upcoming release, you won't need to define column families manually. Instead, CockroachDB will group columns into families for you when a table is created. CockroachDB's default groupings will ensure optimal storage and performance, but you will still have the option to define your own groups using the `FAMILY` keyword, as show above.
+In an upcoming release, you won't need to define column families manually. Instead, CockroachDB will group columns into families for you when a table is created. CockroachDB's default groupings will ensure reasonable storage and performance, but you will still have the option to define your own groups using the `FAMILY` keyword, as show above.
## See Also
From 7897c692b835e103604554a06eb534d407568179 Mon Sep 17 00:00:00 2001
From: Jesse Seldess beta-20160630
.{{site.data.alerts.end}}
@@ -31,7 +31,9 @@ Column families are defined at [table creation](create-table.html). Currently, w
~~~ sql
CREATE TABLE t2 (
a STRING PRIMARY KEY,
- b INT
+ b INT,
+ c BOOL,
+ d TIMESTAMP
);
SHOW CREATE TABLE t2;
@@ -41,9 +43,13 @@ SHOW CREATE TABLE t2;
| t2 | CREATE TABLE t2 ( |
| | a STRING NOT NULL, |
| | b INT NULL, |
+| | c BOOL NULL, |
+| | d TIMESTAMP NULL, |
| | CONSTRAINT "primary" PRIMARY KEY (a), |
| | FAMILY "primary" (a), |
-| | FAMILY fam_2_b (b) |
+| | FAMILY fam_2_b (b), |
+| | FAMILY fam_3_c (c), |
+| | FAMILY fam_4_d (d) |
| | ) |
+-------+--------------------------------------------+
(1 row)
@@ -54,24 +60,37 @@ To group columns into multi-column families, you must use the `FAMILY` keyword,
~~~ sql
CREATE TABLE t3 (
a STRING PRIMARY KEY,
- b INT,
- FAMILY f1 (a, b)
+ b INT,
+ c BOOL,
+ d TIMESTAMP,
+ FAMILY f1 (a, b),
+ FAMILY f2 (c, d)
);
SHOW CREATE TABLE t3;
+-------+--------------------------------------------+
| Table | CreateTable |
+-------+--------------------------------------------+
-| t3 | CREATE TABLE t3 ( |
+| t30 | CREATE TABLE t30 ( |
| | a STRING NOT NULL, |
| | b INT NULL, |
+| | c BOOL NULL, |
+| | d TIMESTAMP NULL, |
| | CONSTRAINT "primary" PRIMARY KEY (a), |
-| | FAMILY f1 (a, b) |
+| | FAMILY f1 (a, b), |
+| | FAMILY f2 (c, d) |
| | ) |
+-------+--------------------------------------------+
(1 row)
~~~
+## Column Family Recommendations
+
+When defining column families for a table, keep the following in mind:
+
+- Since column families reduce the number of underlying keys, it's best for performance to use as few families as is reasonable.
+- Try to avoid grouping columns that get updated a lot with columns that don't. If a small column that gets updated frequently is grouped with a big column that gets updated seldomly, the big column will be rewritten every time the small one is updated.
+
## Upcoming Improvements
In an upcoming release, you won't need to define column families manually. Instead, CockroachDB will group columns into families for you when a table is created. CockroachDB's default groupings will ensure reasonable storage and performance, but you will still have the option to define your own groups using the `FAMILY` keyword, as show above.
@@ -79,4 +98,4 @@ In an upcoming release, you won't need to define column families manually. Inste
## See Also
- [`CREATE TABLE`](create-table.html)
-- [Data Definition](data-definition.html)
\ No newline at end of file
+- [Data Definition](data-definition.html)
From 5c40c733d2e21c56aca8434be3a0be91406caeb2 Mon Sep 17 00:00:00 2001
From: Jesse Seldess SHOW INDEX
.{{site.data.alerts.end}}
-~~~ sql
-> CREATE TABLE logon (
- user_id INT,
- logon_date DATE
- );
+~~~
+> CREATE TABLE logon (user_id INT, logon_date DATE);
CREATE TABLE
> SHOW COLUMNS FROM logon;
@@ -105,6 +102,7 @@ CREATE TABLE
| logon_date | DATE | true | NULL |
| rowid | INT | false | unique_rowid() |
+------------+------+-------+----------------+
+(3 rows)
> SHOW INDEX FROM logon;
+-------+---------+--------+-----+--------+-----------+---------+
@@ -112,14 +110,22 @@ CREATE TABLE
+-------+---------+--------+-----+--------+-----------+---------+
| logon | primary | true | 1 | rowid | ASC | false |
+-------+---------+--------+-----+--------+-----------+---------+
+(1 row)
~~~
### Create a Table (Primary Key Defined)
In this example, we create a table with three columns. One column is the [`PRIMARY KEY`](constraints.html#primary-key), another is given the [`UNIQUE`](constraints.html#unique) constraint, and the third has no constraints. The primary key and column with the `UNIQUE` constraint are automatically indexed.
+Also, since all three columns are likely to be small, we group them into a single [column family](column-families.html). As a result, each row inserted will be stored as a single key-value pair in the underlying key-value layer, thus reducing the storage overhead and improving performance during data manipulation.
+
~~~
-> CREATE TABLE logoff (user_id INT PRIMARY KEY, user_email STRING UNIQUE, logoff_date DATE);
+> CREATE TABLE logoff (
+ user_id INT PRIMARY KEY,
+ user_email STRING UNIQUE,
+ logoff_date DATE,
+ FAMILY f1 (user_id, user_email, logoff_date)
+);
CREATE TABLE
> SHOW COLUMNS FROM logoff;
@@ -130,6 +136,7 @@ CREATE TABLE
| user_email | STRING | true | NULL |
| logoff_date | DATE | true | NULL |
+-------------+--------+-------+---------+
+(3 rows)
> SHOW INDEX FROM logoff;
+--------+-----------------------+--------+-----+------------+-----------+---------+
@@ -138,6 +145,7 @@ CREATE TABLE
| logoff | primary | true | 1 | user_id | ASC | false |
| logoff | logoff_user_email_key | true | 1 | user_email | ASC | false |
+--------+-----------------------+--------+-----+------------+-----------+---------+
+(2 rows)
~~~
### Create a Table With Secondary Indexes
@@ -176,15 +184,16 @@ CREATE TABLE
| product_information | supp_id_prod_status_idx | false | 1 | supplier_id | ASC | false |
| product_information | supp_id_prod_status_idx | false | 2 | product_status | ASC | false |
+---------------------+--------------------------------------+--------+-----+----------------+-----------+---------+
+(6 rows)
~~~
An alternate way to create secondary indexes would be to use [`CREATE INDEX`](create-index.html) statements once the table has been created:
~~~
-CREATE INDEX date_added_idx ON product_information (date_added);
+> CREATE INDEX date_added_idx ON product_information (date_added);
CREATE INDEX
-CREATE INDEX supp_id_prod_status_idx ON product_information (supplier_id, product_status);
+> CREATE INDEX supp_id_prod_status_idx ON product_information (supplier_id, product_status);
CREATE INDEX
~~~
@@ -193,12 +202,20 @@ CREATE INDEX
To show the definition of a table, use the `SHOW CREATE TABLE` statement. The contents of the `CreateTable` column in the response is a string with embedded line breaks that, when echoed, produces formatted output.
~~~
-> SHOW CREATE TABLE logon;
-+-------+------------------------------------------------------------------------+
-| Table | CreateTable |
-+-------+------------------------------------------------------------------------+
-| logon | "CREATE TABLE logon (\n\tuser_id INT NULL,\n\tlogon_date DATE NULL\n)" |
-+-------+------------------------------------------------------------------------+
+> SHOW CREATE TABLE logoff;
++--------+-------------------------------------------------------+
+| Table | CreateTable |
++--------+-------------------------------------------------------+
+| logoff | CREATE TABLE logoff ( |
+| | user_id INT NOT NULL, |
+| | user_email STRING NULL, |
+| | logoff_date DATE NULL, |
+| | CONSTRAINT "primary" PRIMARY KEY (user_id), |
+| | UNIQUE INDEX logoff_user_email_key (user_email), |
+| | FAMILY f1 (user_id, user_email, logoff_date) |
+| | ) |
++--------+-------------------------------------------------------+
+(1 row)
~~~
## See Also
diff --git a/delete.md b/delete.md
index fa230a49141..807eb36675e 100644
--- a/delete.md
+++ b/delete.md
@@ -49,15 +49,15 @@ Successful `DELETE` statements return one of the following:
You can delete all rows from a table by not including a `WHERE` clause in your `DELETE` statement.
-~~~ sql
-DELETE FROM account_details;
+~~~
+> DELETE FROM account_details;
DELETE 7
~~~
This is roughly equivalent to [`TRUNCATE`](truncate.html).
-~~~ sql
-TRUNCATE account_details;
+~~~
+> TRUNCATE account_details;
TRUNCATE
~~~
@@ -73,9 +73,8 @@ Using your table's `PRIMARY KEY` or `UNIQUE` columns to delete rows ensures your
In this example, `account_id` is our `PRIMARY KEY` and we want to delete the row where it equals 1. Because we're positive no other rows have that value in the `account_id` column, there's no risk of accidentally removing another row.
-~~~ sql
-DELETE FROM account_details WHERE account_id = 1 RETURNING *;
-
+~~~
+> DELETE FROM account_details WHERE account_id = 1 RETURNING *;
+------------+---------+--------------+
| account_id | balance | account_type |
+------------+---------+--------------+
@@ -87,9 +86,8 @@ DELETE FROM account_details WHERE account_id = 1 RETURNING *;
Deleting rows using non-unique columns removes _every_ row that returns `TRUE` for the `WHERE` clause's `a_expr`. This can easily result in deleting data you didn't intend to.
-~~~ sql
-DELETE FROM account_details WHERE balance = 30000 RETURNING *;
-
+~~~
+> DELETE FROM account_details WHERE balance = 30000 RETURNING *;
+------------+---------+--------------+
| account_id | balance | account_type |
+------------+---------+--------------+
@@ -107,9 +105,8 @@ To see which rows your statement deleted, include the `RETURNING` clause to retr
#### Use All Columns
By specifying `*`, you retrieve all columns of the delete rows.
-~~~ sql
-DELETE FROM account_details WHERE balance < 23000 RETURNING *;
-
+~~~
+> DELETE FROM account_details WHERE balance < 23000 RETURNING *;
+------------+---------+--------------+
| account_id | balance | account_type |
+------------+---------+--------------+
@@ -121,9 +118,8 @@ DELETE FROM account_details WHERE balance < 23000 RETURNING *;
To retrieve specific columns, name them in the `RETURNING` clause.
-~~~ sql
-DELETE FROM account_details WHERE account_id = 5 RETURNING account_id, account_type;
-
+~~~
+> DELETE FROM account_details WHERE account_id = 5 RETURNING account_id, account_type;
+------------+--------------+
| account_id | account_type |
+------------+--------------+
@@ -135,9 +131,8 @@ DELETE FROM account_details WHERE account_id = 5 RETURNING account_id, account_t
When `RETURNING` specific columns, you can change their labels using `AS`.
-~~~ sql
-DELETE FROM account_details WHERE balance < 22500 RETURNING account_id, balance AS final_balance;
-
+~~~
+> DELETE FROM account_details WHERE balance < 22500 RETURNING account_id, balance AS final_balance;
+------------+---------------+
| account_id | final_balance |
+------------+---------------+
@@ -145,7 +140,6 @@ DELETE FROM account_details WHERE balance < 22500 RETURNING account_id, balance
+------------+---------------+
~~~
-
## See Also
- [`INSERT`](insert.html)
diff --git a/drop-database.md b/drop-database.md
index 6344992e00f..81b23945699 100644
--- a/drop-database.md
+++ b/drop-database.md
@@ -33,7 +33,7 @@ DROP DATABASE IF EXISTS db1;
## Example
~~~
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -41,16 +41,16 @@ SHOW DATABASES;
| system |
+----------+
-DROP DATABASE db1;
+> DROP DATABASE db1;
DROP DATABASE
-DROP DATABASE db2;
+> DROP DATABASE db2;
pq: database "db2" does not exist
-DROP DATABASE IF EXISTS db2;
+> DROP DATABASE IF EXISTS db2;
DROP DATABASE
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -64,4 +64,4 @@ SHOW DATABASES;
- [`SHOW DATABASES`](show-databases.html)
- [`RENAME DATABASE`](rename-database.html)
- [`SET DATABASE`](set-database.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)
diff --git a/drop-table.md b/drop-table.md
index fa560c0235e..71377652bb6 100644
--- a/drop-table.md
+++ b/drop-table.md
@@ -33,7 +33,7 @@ DROP TABLE IF EXISTS db1.table1, db1.table2;
## Example
~~~
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
@@ -42,10 +42,10 @@ SHOW TABLES FROM db1;
| table3 |
+--------+
-DROP TABLE db1.table1, db1.table2;
+> DROP TABLE db1.table1, db1.table2;
DROP TABLE
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
@@ -62,4 +62,4 @@ SHOW TABLES FROM db1;
- [`SHOW COLUMNS`](show-columns.html)
- [`SHOW TABLES`](show-tables.html)
- [`UPDATE`](update.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)
diff --git a/grant.md b/grant.md
index 3bc5a59eff9..729b501c4cd 100644
--- a/grant.md
+++ b/grant.md
@@ -83,7 +83,7 @@ where `excluded
. This example demonstrates how you use the columns in the temporary excluded
table to apply updates on conflict:
~~~
-INSERT INTO accounts (id, balance)
+> INSERT INTO accounts (id, balance)
VALUES (8, 500.50)
ON CONFLICT (id)
DO UPDATE SET balance = excluded.balance;
INSERT 1
-SELECT * FROM accounts WHERE id = 8;
+> SELECT * FROM accounts WHERE id = 8;
+----+---------+
| id | balance |
+----+---------+
@@ -204,27 +204,27 @@ SELECT * FROM accounts WHERE id = 8;
In this example, we get an error from a uniqueness conflict:
~~~
-SELECT * FROM accounts WHERE id = 8;
+> SELECT * FROM accounts WHERE id = 8;
+----+---------+
| id | balance |
+----+---------+
| 8 | 500.5 |
+----+---------+
-INSERT INTO accounts (id, balance) VALUES (8, 125.50);
+> INSERT INTO accounts (id, balance) VALUES (8, 125.50);
pq: duplicate key value (id)=(8) violates unique constraint "primary"
~~~
In this example, we use `ON CONFLICT DO NOTHING` to ignore the uniqueness error and prevent the affected row from being updated:
~~~
-INSERT INTO accounts (id, balance)
+> INSERT INTO accounts (id, balance)
VALUES (8, 125.50)
ON CONFLICT (id)
DO NOTHING;
INSERT 1
-SELECT * FROM accounts WHERE id = 8;
+> SELECT * FROM accounts WHERE id = 8;
+----+---------+
| id | balance |
+----+---------+
@@ -235,13 +235,13 @@ SELECT * FROM accounts WHERE id = 8;
In this example, `ON CONFLICT DO NOTHING` prevents the first row from updating while allowing the second row to be inserted:
~~~
-INSERT INTO accounts (id, balance)
+> INSERT INTO accounts (id, balance)
VALUES (8, 125.50), (10, 450)
ON CONFLICT (id)
DO NOTHING;
INSERT 2
-SELECT * FROM accounts WHERE id in (8, 10);
+> SELECT * FROM accounts WHERE id in (8, 10);
+----+---------+
| id | balance |
+----+---------+
@@ -253,4 +253,4 @@ SELECT * FROM accounts WHERE id in (8, 10);
## See Also
- [`UPSERT`](upsert.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)
diff --git a/rename-database.md b/rename-database.md
index 3b6813fc62d..d2944971932 100644
--- a/rename-database.md
+++ b/rename-database.md
@@ -27,7 +27,7 @@ Parameter | Description
### Rename a Database
~~~
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -36,10 +36,10 @@ SHOW DATABASES;
| system |
+----------+
-ALTER DATABASE db1 RENAME TO db3;
+> ALTER DATABASE db1 RENAME TO db3;
RENAME DATABASE
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -52,7 +52,7 @@ SHOW DATABASES;
### Rename Fails (New Name Already In Use)
~~~
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -61,7 +61,7 @@ SHOW DATABASES;
| system |
+----------+
-ALTER DATABASE db2 RENAME TO db3;
+> ALTER DATABASE db2 RENAME TO db3;
pq: the new database name "db3" already exists
~~~
@@ -71,4 +71,4 @@ pq: the new database name "db3" already exists
- [`SHOW DATABASES`](show-databases.html)
- [`SET DATABASE`](set-database.html)
- [`DROP DATABASE`](drop-database.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)
diff --git a/rename-table.md b/rename-table.md
index 3ed82c715cb..96911bc05f4 100644
--- a/rename-table.md
+++ b/rename-table.md
@@ -41,7 +41,7 @@ ALTER TABLE db1.table1 RENAME TO db2.table1
### Rename a table
~~~
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
@@ -49,10 +49,10 @@ SHOW TABLES FROM db1;
| table2 |
+--------+
-ALTER TABLE db1.table1 RENAME TO db1.tablea
+> ALTER TABLE db1.table1 RENAME TO db1.tablea
RENAME TABLE
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
@@ -64,7 +64,7 @@ SHOW TABLES FROM db1;
### Move a table
~~~
-SHOW DATABASES;
+> SHOW DATABASES;
+----------+
| Database |
+----------+
@@ -73,7 +73,7 @@ SHOW DATABASES;
| system |
+----------+
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
@@ -81,23 +81,23 @@ SHOW TABLES FROM db1;
| tablea |
+--------+
-SHOW TABLES FROM db2;
+> SHOW TABLES FROM db2;
+-------+
| Table |
+-------+
+-------+
-ALTER TABLE db1.tablea RENAME TO db2.tablea
+> ALTER TABLE db1.tablea RENAME TO db2.tablea
RENAME TABLE
-SHOW TABLES FROM db1;
+> SHOW TABLES FROM db1;
+--------+
| Table |
+--------+
| table2 |
+--------+
-SHOW TABLES FROM db2;
+> SHOW TABLES FROM db2;
+--------+
| Table |
+--------+
diff --git a/show-databases.md b/show-databases.md
index d85a6c028fc..62f5b0d2547 100644
--- a/show-databases.md
+++ b/show-databases.md
@@ -16,22 +16,19 @@ The `SHOW DATABASES` [statement](sql-statements.html) lists all database in the
No [privileges](privileges.html) are required to list the databases in the CockroachDB cluster.
-## Usage
+## Example
-To list all databases in the cluster, use the `SHOW DATABASES` statement:
-
-~~~ sql
-SHOW DATABASES;
-~~~
~~~
+> SHOW DATABASES;
+----------+
| Database |
+----------+
| bank |
| system |
+----------+
+(2 rows)
~~~
## See Also
-[SQL Statements](sql-statements.html)
\ No newline at end of file
+[SQL Statements](sql-statements.html)
diff --git a/show-index.md b/show-index.md
index 576be62d253..6990eede9bc 100644
--- a/show-index.md
+++ b/show-index.md
@@ -8,9 +8,9 @@ The `SHOW INDEX` [statement](sql-statements.html) returns index information for
-## Synopsis
+## Required Privileges
-{% include sql/diagrams/show_index.html %}
+No [privileges](privileges.html) are required to show indexes for a table.
## Aliases
@@ -19,17 +19,15 @@ In CockroachDB, the following are aliases for `SHOW INDEX`:
- `SHOW INDEXES`
- `SHOW KEYS`
-## Required Privileges
-
-No [privileges](privileges.html) are required to show indexes for a table.
+## Synopsis
-## Usage
+{% include sql/diagrams/show_index.html %}
-To show indexes for a table, use the `SHOW INDEX FROM` statement followed by the table name in `database.table` format:
+## Parameters
-~~~ sql
-SHOW INDEX FROM db1.table1;
-~~~
+Parameter | Description
+----------|------------
+`var_name` | The name of the table for which you want to show indexes.
## Response
@@ -48,24 +46,27 @@ Field | Description
## Examples
~~~
-CREATE TABLE db1.table1 (
+> CREATE TABLE t1 (
a INT PRIMARY KEY,
b DECIMAL,
c TIMESTAMP,
d STRING
-);
+ );
+CREATE TABLE
-CREATE INDEX b_c_idx ON db1.table1 (b, c) STORING (d);
+> CREATE INDEX b_c_idx ON t1 (b, c) STORING (d);
+CREATE INDEX
-SHOW INDEX FROM db1.table1;
+> SHOW INDEX FROM t1;
+--------+---------+--------+-----+--------+-----------+---------+
| Table | Name | Unique | Seq | Column | Direction | Storing |
+--------+---------+--------+-----+--------+-----------+---------+
-| table1 | primary | true | 1 | a | ASC | false |
-| table1 | b_c_idx | false | 1 | b | ASC | false |
-| table1 | b_c_idx | false | 2 | c | ASC | false |
-| table1 | b_c_idx | false | 3 | d | N/A | true |
+| t1 | primary | true | 1 | a | ASC | false |
+| t1 | b_c_idx | false | 1 | b | ASC | false |
+| t1 | b_c_idx | false | 2 | c | ASC | false |
+| t1 | b_c_idx | false | 3 | d | N/A | true |
+--------+---------+--------+-----+--------+-----------+---------+
+(4 rows)
~~~
## See Also
@@ -73,4 +74,4 @@ SHOW INDEX FROM db1.table1;
- [`CREATE INDEX`](create-index.html)
- [`DROP INDEX`](drop-index.html)
- [`RENAME INDEX`](rename-index.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)
diff --git a/upsert.md b/upsert.md
index 1766c2d1686..816a286e11d 100644
--- a/upsert.md
+++ b/upsert.md
@@ -50,7 +50,7 @@ INSERT INTO t (a, b, c)
In this example, the `id` column is the primary key. Because the inserted `id` value does not conflict with the `id` value of any existing row, the `UPSERT` statement inserts a new row into the table.
~~~
-SELECT * FROM accounts;
+> SELECT * FROM accounts;
+----+----------+
| id | balance |
+----+----------+
@@ -58,10 +58,10 @@ SELECT * FROM accounts;
| 2 | 20000.75 |
+----+----------+
-UPSERT INTO accounts (id, balance) VALUES (3, 6325.20);
+> UPSERT INTO accounts (id, balance) VALUES (3, 6325.20);
INSERT 1
-SELECT * FROM accounts;
+> SELECT * FROM accounts;
+----+----------+
| id | balance |
+----+----------+
@@ -76,7 +76,7 @@ SELECT * FROM accounts;
In this example, the `id` column is the primary key. Because the inserted `id` value is not unique, the `UPSERT` statement updates the row with the new `balance`.
~~~
-SELECT * FROM accounts;
+> SELECT * FROM accounts;
+----+----------+
| id | balance |
+----+----------+
@@ -85,10 +85,10 @@ SELECT * FROM accounts;
| 3 | 6325.2 |
+----+----------+
-UPSERT INTO accounts (id, balance) VALUES (3, 7500.83);
+> UPSERT INTO accounts (id, balance) VALUES (3, 7500.83);
INSERT 1
-SELECT * FROM accounts;
+> SELECT * FROM accounts;
+----+----------+
| id | balance |
+----+----------+
@@ -103,7 +103,7 @@ SELECT * FROM accounts;
`UPSERT` will not update rows when the uniquness conflict is on columns not in the primary key. In this example, the `a` column is the primary key, but the `b` column also has the [`UNIQUE`](constraints.html#unique) constraint. Because the inserted `b` value is not unique, the `UPSERT` fails.
~~~
-SELECT * FROM unique_test;
+> SELECT * FROM unique_test;
+---+---+
| a | b |
+---+---+
@@ -112,17 +112,17 @@ SELECT * FROM unique_test;
| 3 | 3 |
+---+---+
-UPSERT INTO unique_test VALUES (4, 1);
+> UPSERT INTO unique_test VALUES (4, 1);
pq: duplicate key value (b)=(1) violates unique constraint "unique_test_b_key"
~~~
In such a case, you would need to use the [`INSERT ON CONFLICT`](insert.html) statement to specify the `b` column as the column with the `UNIQUE` constraint.
~~~
-INSERT INTO unique_test VALUES (4, 1) ON CONFLICT (b) DO UPDATE SET a = excluded.a;
+> INSERT INTO unique_test VALUES (4, 1) ON CONFLICT (b) DO UPDATE SET a = excluded.a;
INSERT 1
-SELECT * FROM unique_test;
+> SELECT * FROM unique_test;
+---+---+
| a | b |
+---+---+
@@ -135,4 +135,4 @@ SELECT * FROM unique_test;
## See Also
- [`INSERT`](insert.html)
-- [Other SQL Statements](sql-statements.html)
\ No newline at end of file
+- [Other SQL Statements](sql-statements.html)