我现在没有地方来测试这个权利,我希望有人知道,所以我不必等到明天找出....这是否有效的“重复键”语法?
insert into item_properties (ItemID, PropID, Value, UpdateOn) values
(538, 25, 'some description stuff goes here', unix_timestamp()),
(541, 25, 'some description stuff goes here', unix_timestamp()),
(1276, 25, 'some description stuff goes here', unix_timestamp()),
(1319, 25, 'some description stuff goes here', unix_timestamp())
on duplicate key update
ItemID = values(ItemID),
PropID = values(PropID),
Value = values(Value),
UpdateOn = values(UpdateOn)
可以在重新写为:
insert into item_properties (ItemID, Value) values
(538, 'some description stuff goes here'),
(541, 'some description stuff goes here'),
(1276, 'some description stuff goes here'),
(1319, 'some description stuff goes here')
on duplicate key update
ItemID = values(ItemID),
Value = values(Value),
PropID = 25,
UpdateOn = unix_timestamp()
是吗?
或不,因为PropID
和UpdateOn
不能被on dup
零件访问而不在值列表中...?
我试图SQLFiddle,但它告诉我一些关于没有DDL或DML语句,只有选择。
所以我测试的filddle ...
insert into item_properties (ItemID, Value) values
(538, 'some description stuff goes here'),
(538, 'some other description stuff goes here'),
(1276, 'some description stuff goes here'),
(1319, 'some description stuff goes here')
on duplicate key update
ItemID = values(ItemID),
PropID = 26,
Value = values(Value),
UpdateOn = unix_timestamp()
变为:
ITEMID PROPID VALUE UPDATEON
538 26 some other description stuff goes here 1376952345
1276 (null) some description stuff goes here (null)
1319 (null) some description stuff goes here (null)
这是不想要的输出...
所以。 ..我猜这两件事真的是不要做s但我不需要按照我最初的建议重新编写代码。 它是有效的语法,但不正确的结果。
只是为了澄清(但我敢肯定,你可以通过初始on duplicate key
声明说),这是输出我应该结束了...
ITEMID PROPID VALUE UPDATEON
538 26 some other description stuff goes here 1376952345
1276 26 some description stuff goes here 1376952345
1319 26 some description stuff goes here 1376952345
感谢您的帮助!
“但它告诉我一些关于没有DDL或DML语句的东西”---然后以某种方式修复它。或者分享**确切的**错误信息。 – zerkms
@zerkms - ItemID不会更新为相同的值...?这几乎是我得到的确切的错误,而且与声明的有效性无关(这只是我说我为什么现在不能测试自己)......显然只是一个问题,将陈述放入测试运行。 –
SQLFiddle错误:在MySQL的查询面板中不允许使用DDL和DML语句;只允许SELECT语句。把DDL和DML放到模式面板中(通过将insert/on-dup-key语句移动到模式面板并在SQL面板中选择* select * from table)来解决这个问题) –