我可以在 INSERT 语句中使用别名吗?
我们可以在 insert into 语法中使用别名吗?
以下均无效:
INSERT INTO tableblabla AS bla
INSERT INTO bla tableblabla
INSERT INTO tableblabla bla
我似乎找不到任何有关此的信息;有没有在 INSERT 语句中使用别名的有效方法?
Can we use aliases with insert into syntax?
None of the following work:
INSERT INTO tableblabla AS bla
INSERT INTO bla tableblabla
INSERT INTO tableblabla bla
I can't seem to find any information about this; is there a valid way to use aliases in an INSERT statement?
About the possible reasons:
http://bugs.mysql.com/bug.php?id=3275
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
唉,这是不可能的,正如 INSERT 语法 所示。注意它只是说
[INTO] tbl_name
而没有提及[AS]别名
,而更新语法,它允许别名,表示“table_reference”和 进一步文档指出这可以扩展到table_factor,其中包括tbl_name [AS]别名
。不幸的是,因为能够在 INSERT 上使用表别名对于
INSERT ... ON DUPLICATE KEY UPDATE
语句。特别是在对列执行检查时,如本示例所示:如果表名称发生更改,则与在查询中使用的开头有一个别名相比,必须修改大量代码行。
Alas, it's not possible as can be seen by the INSERT syntax. Note how it just says
[INTO] tbl_name
with no mention of[AS] alias
, whereas the Update syntax, which does allow aliases, says "table_reference" and further documentation states this can expand to table_factor which includestbl_name [AS] alias
.It's unfortunate because having the ability to use table aliases on INSERTs would be very useful for
INSERT ... ON DUPLICATE KEY UPDATE
statements. Especially when performing checks on the columns like in this example:If the table name changes, one has to modify lots of lines of code compared to just having an alias at the beginning which is used in the query.
INSERT
语法 不允许别名。无论如何,为什么在 INSERT 语句中需要一个呢?您一次只能INSERT
到一张表中。The
INSERT
syntax doesn't allow for aliases. Why would you need one in an INSERT statement anyways? You can onlyINSERT
into one table at a time.