为什么我不能在SQL数据库中的数字前输入零 [英] Why can't I enter zeros in front of a number in SQL Database

查看:109
本文介绍了为什么我不能在SQL数据库中的数字前输入零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL数据库,我有一个表来输入数据。在其中一个单元格的表格中,我输入了数字001234.当我进入下一个单元格时,它格式化为1234.为什么会发生这种情况并且我能纠正它吗?

I have a SQL database where I have a table to enter data. In the table in one of the cells I entered the numbers 001234. When I went to the next cell it formatted to 1234. Why did this happen and can I correct it?

推荐答案

数字是数字 - 在00123和123之间没有区别(视觉除外)...

SQL实际存储的是数字的实际值(而不是它的表示) - 123。 ..

如果该值实际上是一个数字,那么最好将其存储为数字并在显示时格式化(可能在您的UI中),如果该值是字母数字值而不是在SQL中更改其类型到VARCHAR / NVARCHAR它也会保留前导零...
Numbers are numbers - there is no difference (except visual) between 00123 and 123...
What SQL actually stores is the real value of the number (and not it's representation) - 123...
If the value is really a number than you better store it as a number and format it upon display (probably in your UI), if the value is an alphanumeric value than change its type in SQL to VARCHAR/NVARCHAR and it will preserve also the leading zeros...


为了能够添加前导零,使用文本字段(varchar,nvarchar)而不是数字。
To be able to add leading zeros, use text field (varchar, nvarchar) instead of numeric.


这篇关于为什么我不能在SQL数据库中的数字前输入零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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