Skip to content

Instantly share code, notes, and snippets.

@sploiselle
Last active August 29, 2017 16:50
Show Gist options
  • Save sploiselle/bdf40869230253645299641f65457c14 to your computer and use it in GitHub Desktop.
Save sploiselle/bdf40869230253645299641f65457c14 to your computer and use it in GitHub Desktop.
Simple SQL commands to use CockroachDB

Applications you build with CockroachDB use SQL to interact with your data. Use this simple guide to help you get started with some basic SQL statements.

Write data with INSERT

Implicit columns

INSERT INTO tbl_name VALUES (1, 'a'), (2, 'b'), (3, 'a');

Explicit columns

INSERT INTO tbl_name (id, val) VALUES (1, 'a'), (2, 'b'), (3, 'a');

Read data with SELECT

Select all columns

SELECT * FROM tbl_name;

Select specific columns

SELECT id, val FROM tbl_name;

Select specific rows

SELECT * FROM tbl_name WHERE id = 2;

Change data with UPDATE

UPDATE tbl_name SET col = 'newVal' WHERE col = 'oldVal';

Remove data with DELETE

Delete specific rows

DELETE FROM tbl_name WHERE col = 'specificVal';

Delete all rows

DELETE FROM tbl_name;

Advanced Operations

Check out our SQL documentation at https://cockroachlabs.com/docs/stable/sql-statements.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment