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

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

问题描述

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

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?

先谢谢了.

推荐答案

仅当您在交互式数据库工具中手动键入查询时,此方法才可接受.当您的程序执行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天全站免登陆