From cdc585519d1be2fecad44b45585127239b0abca2 Mon Sep 17 00:00:00 2001 From: Icemap Date: Fri, 10 Jun 2022 13:34:28 +0800 Subject: [PATCH] [Debug] outdated code and table name --- develop/dev-guide-bookshop-schema-design.md | 2 +- develop/dev-guide-create-table.md | 2 +- develop/dev-guide-delete-data.md | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/develop/dev-guide-bookshop-schema-design.md b/develop/dev-guide-bookshop-schema-design.md index 2a878c2c8dec..118c9b6da448 100644 --- a/develop/dev-guide-bookshop-schema-design.md +++ b/develop/dev-guide-bookshop-schema-design.md @@ -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` ( diff --git a/develop/dev-guide-create-table.md b/develop/dev-guide-create-table.md index 93a399c14577..99f6248eee78 100644 --- a/develop/dev-guide-create-table.md +++ b/develop/dev-guide-create-table.md @@ -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" >}} diff --git a/develop/dev-guide-delete-data.md b/develop/dev-guide-delete-data.md index bb5a36748ec0..c4808b893152 100644 --- a/develop/dev-guide-delete-data.md +++ b/develop/dev-guide-delete-data.md @@ -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 万条,请参考[批量删除](#批量删除)。 @@ -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"; ``` @@ -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(); } @@ -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` 类型。