Skip to content

Commit

Permalink
[Debug] outdated code and table name
Browse files Browse the repository at this point in the history
  • Loading branch information
Icemap committed Jun 10, 2022
1 parent 52be7c5 commit cdc5855
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion develop/dev-guide-bookshop-schema-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ CREATE TABLE `bookshop`.`ratings` (
PRIMARY KEY (`book_id`,`user_id`) CLUSTERED,
UNIQUE KEY `uniq_book_user_idx` (`book_id`,`user_id`)
) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
ALTER TABLE `bookshop`.`rating` SET TIFLASH REPLICA 1;
ALTER TABLE `bookshop`.`ratings` SET TIFLASH REPLICA 1;

DROP TABLE IF EXISTS `bookshop`.`users`;
CREATE TABLE `bookshop`.`users` (
Expand Down
2 changes: 1 addition & 1 deletion develop/dev-guide-create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ CREATE TABLE `bookshop`.`ratings` (

如需在列上设置默认值,请使用 `DEFAULT` 约束。默认值将可以使你无需指定每一列的值,就可以插入数据。

你可以将 `DEFAULT`[支持的 SQL 函数](/basic-features.md#数据类型函数和操作符)结合使用,将默认值的计算移出应用层,从而节省应用层的资源(当然,计算所消耗的资源并不会凭空消失,只是被转移到了 TiDB 集群中)。常见的,希望实现数据插入时,可默认填充默认的时间。还是使用 `rating` 作为示例,可使用以下语句:
你可以将 `DEFAULT`[支持的 SQL 函数](/basic-features.md#数据类型函数和操作符)结合使用,将默认值的计算移出应用层,从而节省应用层的资源(当然,计算所消耗的资源并不会凭空消失,只是被转移到了 TiDB 集群中)。常见的,希望实现数据插入时,可默认填充默认的时间。还是使用 `ratings` 作为示例,可使用以下语句:

{{< copyable "sql" >}}

Expand Down
15 changes: 9 additions & 6 deletions develop/dev-guide-delete-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ DELETE FROM {table} WHERE {filter}
{{< copyable "sql" >}}

```sql
SELECT COUNT(*) FROM `rating` WHERE `rating_at` >= "2022-04-15 00:00:00" AND `rating_at` <= "2022-04-15 00:15:00";
SELECT COUNT(*) FROM `ratings` WHERE `rated_at` >= "2022-04-15 00:00:00" AND `rated_at` <= "2022-04-15 00:15:00";
```

- 若返回数量大于 1 万条,请参考[批量删除](#批量删除)
Expand All @@ -61,7 +61,7 @@ SELECT COUNT(*) FROM `rating` WHERE `rating_at` >= "2022-04-15 00:00:00" AND `r
{{< copyable "sql" >}}

```sql
DELETE FROM `rating` WHERE `rating_at` >= "2022-04-15 00:00:00" AND `rating_at` <= "2022-04-15 00:15:00";
DELETE FROM `ratings` WHERE `rated_at` >= "2022-04-15 00:00:00" AND `rated_at` <= "2022-04-15 00:15:00";
```

</div>
Expand All @@ -74,15 +74,18 @@ DELETE FROM `rating` WHERE `rating_at` >= "2022-04-15 00:00:00" AND `rating_at`
// ds is an entity of com.mysql.cj.jdbc.MysqlDataSource

try (Connection connection = ds.getConnection()) {
PreparedStatement pstmt = connection.prepareStatement("DELETE FROM `rating` WHERE `rating_at` >= ? AND `rating_at` <= ?");
String sql = "DELETE FROM `bookshop`.`ratings` WHERE `rated_at` >= ? AND `rated_at` <= ?";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);

calendar.set(2022, Calendar.APRIL, 15, 0, 0, 0);
pstmt.setTimestamp(1, new Timestamp(calendar.getTimeInMillis()));
preparedStatement.setTimestamp(1, new Timestamp(calendar.getTimeInMillis()));

calendar.set(2022, Calendar.APRIL, 15, 0, 15, 0);
pstmt.setTimestamp(2, new Timestamp(calendar.getTimeInMillis()));
preparedStatement.setTimestamp(2, new Timestamp(calendar.getTimeInMillis()));

preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -133,7 +136,7 @@ func main() {

> **注意:**
>
> `rating_at` 字段为[日期和时间类型](/data-type-date-and-time.md) 中的 `DATETIME` 类型,你可以认为它在 TiDB 保存时,存储为一个字面量,与时区无关。而 `TIMESTAMP` 类型,将会保存一个时间戳,从而在不同的[时区配置](/configure-time-zone.md)时,展示不同的时间字符串。
> `rated_at` 字段为[日期和时间类型](/data-type-date-and-time.md) 中的 `DATETIME` 类型,你可以认为它在 TiDB 保存时,存储为一个字面量,与时区无关。而 `TIMESTAMP` 类型,将会保存一个时间戳,从而在不同的[时区配置](/configure-time-zone.md)时,展示不同的时间字符串。
>
> 另外,和 MySQL 一样,`TIMESTAMP` 数据类型受 [2038 年问题](https://zh.wikipedia.org/wiki/2038%E5%B9%B4%E9%97%AE%E9%A2%98)的影响。如果存储的值大于 2038,建议使用 `DATETIME` 类型。
Expand Down

0 comments on commit cdc5855

Please sign in to comment.