我正在做这些:
insert into table_name(maxdate) values
((select max(date1) from table1)), -- goes in row1
((select max(date2) from table2)), -- goes in row2
.
.
.
((select max(date500) from table500));--goes in row500
在插入时,插入顺序是否可能会改变?例如,当我会这样做时
select maxdate from table_name limit 500;
我会得到这些 日期 1 日期 2 。 。日期253 日期191 ...日期500
最佳答案
简短回答:
不,不可能。
如果您想仔细检查:
mysql> create table letest (f1 varchar(50), f2 varchar(50));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into letest (f1,f2) values
( (SELECT SLEEP(5)), 'first'),
( (SELECT SLEEP(1)), 'second');
Query OK, 2 rows affected, 1 warning (6.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from letest;
+------+--------+
| f1 | f2 |
+------+--------+
| 0 | first |
| 0 | second |
+------+--------+
2 rows in set (0.00 sec)
mysql>
SLEEP(5) 是5秒后插入的第一行,
SLEEP(1) 是 5+1 秒后插入的第二行
这就是查询需要 6 秒的原因。
您看到的警告是
mysql> show warnings;
+-------+------+-------------------------------------------------------+
| Level | Code | Message |
+-------+------+-------------------------------------------------------+
| Note | 1592 | Statement may not be safe to log in statement format. |
+-------+------+-------------------------------------------------------+
1 row in set (0.00 sec)
只有当您使用主从设置时,这才会影响您,因为复制二进制日志不安全。有关此的更多信息 http://dev.mysql.com/doc/refman/5.1/en/replication-rbr-safe-unsafe.html
稍后编辑:如果您发现此答案没有用,请考虑发表评论。
关于Mysql-如果我同时在表的一列中插入多个值,值的插入顺序是否可能会改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279345/