首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我得到"arthemtic error converting to data type int?

为什么我得到"arthemtic error converting to data type int?
EN

Stack Overflow用户
提问于 2014-08-06 01:11:59
回答 3查看 16.2K关注 0票数 0
代码语言:javascript
复制
Create table COSTUMER(
[Costumer ID] int,
[Costumer Phone number] int,
[Costumer Date of Birth] int,
[Costumer Address] text,
[Costumer Name] varchar(40),
[Costumer Buisness if applicable] varchar(40)
);

我已经创建了上面的表及其相关的列和行,并尝试通过插入以下代码将一些数据插入到表中,但仍然得到消息8115,Level 16,State 2,Line 1 "arthemtic error converting to data type int“语句已终止错误。

我一定是做错了什么,但我就是看不出来。

代码语言:javascript
复制
INSERT INTO COSTUMER 
      ([Costumer ID],[Costumer Phone number],[Costumer Date of Birth],[Costumer Address]
     ,[Costumer Name],[Costumer Buisness if applicable]) 
VALUES (24,07956485211,27/08/1993,'311 Fullwell avenue','Mohamed Ahmed','TESCO')

请帮帮忙

EN

回答 3

Stack Overflow用户

发布于 2014-08-06 01:22:37

对于要存储的数据,请始终使用适当的数据类型。在本例中,应该对Date of Birth列使用DATEDATETIME数据类型。

表定义

代码语言:javascript
复制
Create table COSTUMER(
[Costumer ID]                     INT,
[Costumer Phone number]           VARCHAR(100),  --<-- mostly numbers has a leading Zero INT will not respect that
[Costumer Date of Birth]          DATE,          --<--  DATE data type
[Costumer Address]                VARCHAR(MAX),  --<-- avoid using text it has been deprecated in newer versions
[Costumer Name]                   varchar(40),
[Costumer Buisness if applicable] varchar(40)
);

INSERT语句

代码语言:javascript
复制
INSERT INTO COSTUMER 
      ([Costumer ID],[Costumer Phone number],[Costumer Date of Birth],[Costumer Address]
     ,[Costumer Name],[Costumer Buisness if applicable]) 
VALUES (24,'07956485211','19930827','311 Fullwell avenue','Mohamed Ahmed','TESCO')

备注

也可以使用多个列来存储地址,使用像.....

代码语言:javascript
复制
AddressLine1 , AddressLine2, AddressLine3, County/Region, City, PostCode, Country

您当前的架构违反了数据库规范化的基本规则。

票数 3
EN

Stack Overflow用户

发布于 2014-08-06 01:16:43

这是因为您正在尝试将电话号码作为INT插入。它可能应该是VARCHAR/NVARCHAR值。

正如user2989408所说,出生日期应该是日期或日期时间。

票数 1
EN

Stack Overflow用户

发布于 2014-08-06 01:50:20

算术溢出错误是因为您试图将数据填充到一个列中,该列的数据类型不够“大”,无法容纳您试图放入的数据。换句话说,数据类型INT的最大值为2,147,483,647 (如下所示)。

根据电话号码的使用方式,我会将其存储为bigint而不是int。Bigint将占用8字节的存储空间(如下所示),而对于11位数字的电话号码(在您的帖子07956485211中),CHAR数据类型将占用11字节,varchar将占用13字节(如下所示)

参考文献:

http://msdn.microsoft.com/en-us/library/ms187745.aspx

http://msdn.microsoft.com/en-us/library/ms176089.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25144599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档