CockroachDB中SQL操作
程序员文章站
2022-03-22 17:31:17
...
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 | +----------+-------------+--------+-----+---------+-----------+---------+----------+
上一篇: 如何操作webpack处理文件
下一篇: 微信小程序实现与后台PHP交互