English 中文(简体)
我们应使用浮动作为 sql- server 的主密钥
原标题:should we use float as primary key in sql-server

有人建议我最好用浮点子作为一张桌子的主要钥匙, 而不是使用BIGINT。

最佳回答

考虑因素:

  • you CAN make a float field primary key.
  • you CANT make a float field IDENTITY. Identity columns must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0
  • you ABSOLUTELY SHOULD NOT use a float field as a PK. Again, you CAN, SQL Server will allow you but its not recommended mainly because floats are inaccurate as @Andy said.

您为什么需要一个 PK 的浮标? 您需要3, 1234235234534 这样的值来识别您的行吗?

问题回答

请注意,如果你真的漂浮 a=1f 和漂浮 b=1f 它们都是相同的权利吗?

但是,如果(a==b)由于浮标不准确,则可能不属实。

为何不对主密钥使用大数据类型 :

尽量缩小索引的“ 宽度 ” 。 这将缩小索引的大小, 并减少读取索引所需的磁盘 I/ O 读数, 提高性能 。

如果可能的话, 请尝试在有整数值而不是字符的列上创建索引。 整数值比字符值少。

在主键上不要使用FLOAT或真实数据类型,因为它们会增加不必要的间接费用,并可能损害性能。

窄列上的索引比宽列上的索引要好。 越小的索引, SQL 服务器的条目越多,数据页面上就可以适应的数据页,这反过来又会减少访问数据所需的I/O数量。

减少键的大小,从而在加入过程中减少读I/O,提高总体业绩。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签