nulls与? [英] nulls versus ?
问题描述
有没有人知道一个资源,该资源讨论了使用nulls
与特定未知的优点。值?例如,我应该使用null吗?对于
未知或未设置的日期,还是应该使用最小值?对于字符串(例如名称)
我应该使用null还是空字符串?等等。
(我工作的应用程序中出现了很多这类问题,而b $ b主要涉及在Web界面上显示数据,以及阅读和写作
进出数据库)。
谢谢,
彼得
Hi,
does anyone know of a resource which discusses the merits of using "nulls"
versus a specific "unknown" value? For example, should I use "null" for an
unknown or unset date, or should I use min-value? For a string (eg a name)
should I use null or an empty string? And so on.
(These sorts of issues crop up a lot in the applications I work on which
mostly involve presenting data on a web interface, and reading and writing
to and from a database).
Thanks,
Peter
推荐答案
我认为这取决于语义。但是我喜欢
的一般规则如下:
数据库中未知的空值。
默认值设置为字段未完成时的编辑器。
例如如果名称未完成,我将一个空字符串放入数据库。
或在查找表中我添加一个值未设置并从编辑器我
设置为默认值
Tasos
I think that these depends on the semantics. But a general rule I like
to follow is this:
Null in the database for unknown.
Default values set by the editor when the fields are not completed.
e.g. if name was not completed I put an empty string to the db.
or in the lookuptables I add a value "Not set" and from the editor I
set this as a default value
Tasos
嗨彼得,
我总是在数据库中创建我的表,以便所有字段都是
不可为空且必须具有有效值。
对于字符串,我使用空字符串,数值取决于
的含义,对于日期,我将使用特定日期/时间或
与记录中的另一个日期相同的值。
MS SQL表中的可空字段会降低性能,但是另一个
不允许空值的好处是,你不必检查它们。
Paul
Peter Kirk写道:
Hi Peter,
I always create my tables in the database so that all fields are
non-nullable and must have a valid value.
For strings I use an empty string, numeric values vary depending on what
it is for, and for dates I will either use a specific date/time or the
same value as another date in the record.
Nullable fields in a MS SQL table degrades performance, but another
advantage of not allowing null values, is you don''t have to check for them.
Paul
Peter Kirk wrote:
有没有人知道讨论使用nulls
与特定未知的优点的资源。值?例如,我应该使用null吗?对于
未知或未设置的日期,还是应该使用min-value?对于字符串(例如名称)
我应该使用null还是空字符串?等等。
(这些问题在我工作的应用程序中出现了很多问题,主要涉及在Web界面上显示数据,以及读取和写入
从数据库中获取。
谢谢,
Peter
Hi,
does anyone know of a resource which discusses the merits of using "nulls"
versus a specific "unknown" value? For example, should I use "null" for an
unknown or unset date, or should I use min-value? For a string (eg a name)
should I use null or an empty string? And so on.
(These sorts of issues crop up a lot in the applications I work on which
mostly involve presenting data on a web interface, and reading and writing
to and from a database).
Thanks,
Peter
HI,
" Paul Cheetham" < PA ****** @ dsl.pipex.com>在留言中写道
新闻:uy ************** @ TK2MSFTNGP02.phx.gbl ...
"Paul Cheetham" <PA******@dsl.pipex.com> wrote in message
news:uy**************@TK2MSFTNGP02.phx.gbl...
你好Peter,
我总是在数据库中创建表,以便所有字段都是不可为空的,并且必须具有有效值。
你用日期栏做什么?在一个场景中,
SQL接受的任何日期是否为可接受的值?
唯一的方法是使用null。
和对于日期,我将使用特定的日期/时间或相同的值作为记录中的另一个日期。
所以你使用不正确的数据,只是为了避免处理null?
MS SQL表中的可空字段会降低性能
Hi Peter,
I always create my tables in the database so that all fields are
non-nullable and must have a valid value.
What you do with a date column? in a escenario where any date accepted by
SQL is an accepted value?
The only way is using null.
and for dates I will either use a specific date/time or the same value as
another date in the record.
So you use incorrect data, only to avoid dealing with null?
Nullable fields in a MS SQL table degrades performance
如何?这是我第一次听到这个
-
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
How ? This is the first time I hear this
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
这篇关于nulls与?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!