mysql - 与截断语句的标准定义混淆

标签 mysql sql-server database-migration

我在 MSSQL 服务器方面有相当多的经验。我们有一个从 MYSQL 到 SQL 服务器的数据库迁移。我从来没有使用过 MYSQL,所以我正在使用这个 link 来解决差异。 .

在页面的一个地方,下面是Truncate的定义..

The SQL standard defines the TRUNCATE TABLE tablename statement (optional feature ID F200, new in SQL:2008) as: Delete all rows of a base table without causing any triggered action.

Unfortunately, the standard doesn't specify
1. whether TRUNCATE TABLE should be allowed in a transaction involving other statements, or not
2. whether TRUNCATE TABLE should imply an immediate COMMIT, or not

对于 SQL 服务器,页面显示

Follows the standard.

In MSSQL, TRUNCATE TABLE is allowed in a transaction involving other operations, and TRUNCATE TABLE does not imply an immediate COMMIT operation.

对于MYSQL,页面说

MySQL has a TRUNCATE TABLE statement, but it doesn't always follow the standard.

Note that in some cases, MySQL's truncate command is really the equivalent of an unrestricted DELETE command (i.e.: potentially slow and trigger-invoking). Its behaviour depends on which storage engine the table is managed by.

When using InnoDB (transaction safe) tables, TRUNCATE TABLE is allowed in a transaction involving other operations, however TRUNCATE TABLE implies an immediate COMMIT operation.

在 SQLServer 中,当你截断一个表时
1.操作可能被最小化记录
2.只有页面解除分配发生并记录在事务日志中

所以我的问题是:
1.以下标准中的措辞是什么意思,SQL Server 是如何遵循标准而 MYSQL 不是。

whether TRUNCATE TABLE should imply an immediate COMMIT, or not

最佳答案

感谢来自 Clifton_h 的链接和对此 question 的回答...

我的问题是这个措辞是什么意思

whether TRUNCATE TABLE should imply an immediate COMMIT, or not

这一切都归结为您是否可以回滚截断..

对于 MYSQL 和 Oracle:
你不能回滚截断,因为那些 DBMS 确实在事务后应用隐式提交,只有在出错的情况下才会回滚,但用户不能这样做

对于 SQL 服务器:
您可以回滚截断,因为不应用立即提交..

关于mysql - 与截断语句的标准定义混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38090931/

相关文章:

php - 正确显示mysql时间戳

java - 在 MySQL 中插入来自 java 的日期时间字符串

c# - LINQ to Entities 中的 LastIndexOf

ruby-on-rails - 当多个应用程序在 Ruby 中共享同一个数据库时如何管理迁移?

java - Grails dbm-update失败:MySQLSyntaxErrorException:SQL语法有错误

mysql - SQL 多对多 JSON

MYSQL,对于非关联值不显示任何内容

sql-server - 重新编号连续值

sql - LTRIM/RTRIM - 但只有第一个/最后一个字符是空格时?

Django:如何从 ManyToMany 迁移到 ForeignKey?