数据类型在SQL Server中应该是2的幂的大小吗? [英] Should Data types be sizes of powers of 2 in SQL Server?

查看:118
本文介绍了数据类型在SQL Server中应该是2的幂的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server中数据类型的大小是什么?当定义列时,我看到大小为50的数据类型作为默认大小之一(例如:nvarchar(50),binary(50))。 50的意义是什么?我想使用2的权力大小,是更好还是只是无用?



更新1 你的输入家伙。我只想知道为列定义数据类型大小的最好方法。

解决方案

长度为50是SQL Server默认为50作为长度是一个问题的大多数数据类型的长度。



如上所述,字段的长度应该适合于存储在那里的数据,而不是因为SQL Server中单个记录的长度有限制(约8000字节)。



此外,字段的长度可以被视为您的文档的一部分。我不知道有多少次,我遇到了懒惰的程序员谁声称他们不需要文档,因为代码是自我记录,然后他们不打扰做的东西,使代码自我记录。 p>

What are good sizes for data types in SQL Server? When defining columns, i see data types with sizes of 50 as one of the default sizes(eg: nvarchar(50), binary(50)). What is the significance of 50? I'm tempted to use sizes of powers of 2, is that better or just useless?

Update 1 Alright thanks for your input guys. I just wanted to know the best way of defining the size of a datatype for a column.

解决方案

The reason so many fields have a length of 50 is that SQL Server defaults to 50 as the length for most data types where length is an issue.

As has been said, the length of a field should be appropriate to the data that is being stored there, not least because there is a limit to the length of single record in SQL Server (it's ~8000 bytes). It is possible to blow past that limit.

Also, the length of your fields can be considered part of your documentation. I don't know how many times I've met lazy programmers who claim that they don't need to document because the code is self documenting and then they don't bother doing the things that would make the code self documenting.

这篇关于数据类型在SQL Server中应该是2的幂的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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