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“语句已终止错误。
我一定是做错了什么,但我就是看不出来。
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')请帮帮忙
发布于 2014-08-06 01:22:37
对于要存储的数据,请始终使用适当的数据类型。在本例中,应该对Date of Birth列使用DATE或DATETIME数据类型。
表定义
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语句
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')备注
也可以使用多个列来存储地址,使用像.....
AddressLine1 , AddressLine2, AddressLine3, County/Region, City, PostCode, Country您当前的架构违反了数据库规范化的基本规则。
发布于 2014-08-06 01:16:43
这是因为您正在尝试将电话号码作为INT插入。它可能应该是VARCHAR/NVARCHAR值。
正如user2989408所说,出生日期应该是日期或日期时间。
发布于 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
https://stackoverflow.com/questions/25144599
复制相似问题