`

CockroachDB中SQL操作

    博客分类:
  • DB
阅读更多

1、多行数据插入

 

INSERT INTO accounts VALUES
    (3, 8100.73),
    (4, 9400.10);

 对应列没有值以NULL代替或使用DEFAULT

 

INSERT INTO accounts (id, balance) VALUES    (5);
INSERT INTO accounts (id, balance) VALUES    (6, DEFAULT);
SELECT * FROM accounts WHERE id in (5, 6);
+----+---------+
| id | balance |
+----+---------+
|  5 | NULL    |
|  6 | NULL    |
+----+---------+
(2 rows)

 

2、创建索引

CREATE INDEX balance_idx ON accounts (balance DESC);
或
CREATE TABLE accounts (
    id INT PRIMARY KEY,
    balance DECIMAL,
    INDEX balance_idx (balance)
);

查询索引

SHOW INDEX FROM accounts;

+----------+-------------+--------+-----+---------+-----------+---------+----------+
|  Table   |    Name     | Unique | Seq | Column  | Direction | Storing | Implicit |
+----------+-------------+--------+-----+---------+-----------+---------+----------+
| accounts | primary     | true   |   1 | id      | ASC       | false   | false    |
| accounts | balance_idx | false  |   1 | balance | DESC      | false   | false    |
| accounts | balance_idx | false  |   2 | id      | ASC       | false   | true     |
+----------+-------------+--------+-----+---------+-----------+---------+----------+

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics