简体   繁体   English

在 SQL Db 中将 smallint 更改为 int 时会丢失任何数据吗? 这只是一个大小存储问题吗?

[英]Will I lose any data when changing smallint to int in SQL Db? Is it just a size storage issue?

I have a database that uses an access front-end.我有一个使用访问前端的数据库。 The users have asked to change the data that is entered in one column to incorporate a larger number over the Small INT (32,767) size.用户已要求更改在一列中输入的数据,以包含比 Small INT (32,767) 大小更大的数字。 If i were to change the type to Int is there likely to be any loss of data or any other issues?如果我将类型更改为 Int 是否可能会丢失任何数据或任何其他问题?

Since both the datatypes are of similar types, you won't face any issues.由于这两种数据类型的类型相似,因此您不会遇到任何问题。 And you're changing from small int to INT(larger number storage), so there won't be any loss of data.并且您正在从 small int 更改为 INT(更大的数字存储),因此不会丢失任何数据。

@Ste Willis, from my personal experience, it shouldn't have any effect really other than creating more room to hold much bigger values. @Ste Willis,根据我的个人经验,除了创造更多空间来容纳更大的价值之外,它应该没有任何影响。 So it should be advantageous rather than otherwise.所以它应该是有利的而不是其他的。 SQL Server INT Data Types are BIGINT, INT, SMALLINT, TINYINT SQL Server INT 数据类型有 BIGINT、INT、SMALLINT、TINYINT

BIGINT  -263 (-9,223,372,036,854,775,808) to 263-1 (9,223,372,036,854,775,807)  8 Bytes
INT -231 (-2,147,483,648) to 231-1 (2,147,483,647)  4 Bytes
SMALLINT    -215 (-32,768) to 215-1 (32,767)    2 Bytes
TINYINT 0 to 255    1 Byte

This means int is much bigger in size than smallint (atleast twice as big), so changing from smallint to int should not make you lose any data instead it creates more room for more data.这意味着 int 的大小比 smallint 大得多(至少大两倍),因此从 smallint 更改为 int 不应该让您丢失任何数据,而是为更多数据创造了更多空间。

If you were to do the opposite, say from int to smallint, then you may lose data.如果你做相反的事情,比如从 int 到 smallint,那么你可能会丢失数据。

I stand to be corrected.我站着被纠正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM