插入查询:为什么不包含列名是个坏主意? [英] Insert Query: Why is it a bad idea to not include column names?

查看:14
本文介绍了插入查询:为什么不包含列名是个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在上一个职位上被告知永远不要这样做;没有解释为什么.我知道它增加了出错的机会,但是如果只有几列并且我对它们的顺序很有信心,为什么我不能简写它并以正确的顺序插入值而不显式匹配列名?有很大的性能差异吗?如果是这样,它在小范围内是否重要?

I was told at my last position never to do this; it wasn't explained why. I understand it enhances the opportunity for mistakes, but if there are just a couple of columns and I'm confident of their order, why can't I shorthand it and just insert the values in the right order without explicitly matching up the column names? Is there a large performance difference? If so, does it matter on a small scale?

如果没有性能损失,而且这不是将保存以供其他人查看的查询,我为什么不呢?

If there's no performance hit and this isn't a query that will be saved for others to view, why shouldn't I?

提前致谢.

推荐答案

只有在您手动将查询键入交互式 DB 工具时才可接受.当您的 SQL 语句由您的程序执行时,您不能绝对确定表中列的顺序,除非您是唯一可以访问您的数据库的开发人员.换句话说,在任何团队环境中,都有可能有人会通过重新排序数据库中的列来破坏您的查询.从逻辑上讲,您的表将保持不变,但您的程序仍会中断.

This is acceptable only when you type your query by hand into an interactive DB tool. When your SQL statement is executed by your program, you cannot be absolutely confident about the order of columns in a table, unless you are the only developer who has access to your database. In other words, in any team environment there is an opportunity that someone would break your query simply by re-ordering columns in your database. Logically, your table would remain the same, but your program would still break.

这篇关于插入查询:为什么不包含列名是个坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆