Start CockroachDB
If you haven’t already, . Then run the command:Show tables
To see all tables in the active database, use the statement or the\dt :
Create a table
Suppose that you want MovR to offer ride-sharing services, in addition to vehicle-sharing services. You’ll need to add a table for drivers to themovr database. To create a table, use followed by a table name, the column names, and the and , if any, for each column:
rowid column as the primary key.
To avoid an error in case the table already exists, you can include IF NOT EXISTS:
\d :
Insert rows
To insert a row into a table, use followed by the table name and then the column values listed in the order in which the columns appear in the table:name, dl, and address entries each contain their default value, in this case NULL:
Create an index
help locate data without having to look through every row of a table. They’re automatically created for the of a table and any columns with a . To create an index for non-unique columns, use followed by an optional index name and anON clause identifying the table and column(s) to index. For each column, you can choose whether to sort ascending (ASC) or descending (DESC).
INDEX keyword followed by an optional index name and the column(s) to index:
Show indexes
To show the indexes on a table, use followed by the name of the table:Query a table
To query a table, use followed by a comma-separated list of the columns to be returned and the table from which to retrieve the data. You can also use the clause to restrict the number of rows retrieved:* wildcard:
WHERE clause identifying the columns and values to filter on:
ORDER BY clause identifying the columns to sort by. For each column, you can choose whether to sort ascending (ASC) or descending (DESC).
Update rows
To update rows in a table, use followed by the table name, aSET clause identifying the columns to update and their new values, and a WHERE clause identifying the rows to update:
WHERE clause to reliably update specific rows; otherwise, each row matching the WHERE clause is updated. When there’s no WHERE clause, all rows in the table are updated.
Delete rows
To delete rows from a table, use followed by the table name and aWHERE clause identifying the rows to delete:
UPDATE statement, if a table has a primary key, you can use that in the WHERE clause to reliably delete specific rows; otherwise, each row matching the WHERE clause is deleted. When there’s no WHERE clause, all rows in the table are deleted.
Remove a table
When you no longer need a table, use followed by the table name to remove the table and all its data:What’s next?
- Explore all
- to execute statements from a shell or directly from the command line
- for your preferred language
- like automatic replication, rebalancing, and fault tolerance

