2013-05-08 78 views
0

這應該是一個簡單的過程,但我遇到了問題。我有一個插入命令。其中一個值需要= = -1。該字段被定義爲一個小整數,所以它應該接受正值和負值。設置變量等於負數

INSERT語句

insert into MasterData2 ([Ad],[Phase],[Page Type] , [Page], [Percent] , [Change Type],[UserName], [Timestamp], [Qty]) 
values(@Ref, @PhaseName , @PageType , @Page , @Percent ,@ChngType, @UserName, @Timestamp, -1) 

領域[數量]必須-1

+5

什麼是錯誤訊息? – Patashu 2013-05-08 03:11:58

回答

1

如果你需要存儲正反兩方面的值,可以用最小的整數類型是SMALLINT。 TINYINT是爲僅正值0至255

MSDN參考:tinyint, smallint, int, bigint

Data type | Range 
====================== 
bigint | -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807) 
int  | -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) 
smallint | -2^15 (-32,768) to 2^15-1 (32,767) 
tinyint | 0 to 255 

見例如:

create table #tmp (t tinyint, x smallint) 
insert #tmp select 1,-1 

-- OK 

insert #tmp select -1,-1 

-- 
Msg 220, Level 16, State 2, Line 1 
Arithmetic overflow error for data type tinyint, value = -1. 
The statement has been terminated. 
相關問題