2014-02-23 62 views
-1

我試圖在固定長度列中插入數據,但是出現錯誤。在固定長度列sql服務器中插入數據

表看起來是這樣的:

CREATE TABLE [dbo].[zam_pcinfo](
    [Id] [decimal] identity NOT NULL, 
    [employe_name] [nvarchar](50) NOT NULL, 
    [location_id] [decimal] NOT NULL, 
    [department_id] [decimal] NOT NULL, 
    [computer_name] [nvarchar](25) NOT NULL, 
    [user_name] [nvarchar](25) NOT NULL, 
    [teamviewer_id] [nvarchar](25) NULL check (DATALENGTH(teamviewer_id) = 9), 
    [lan_ip] [nvarchar](20) NULL, 
    [policy] [nvarchar](25) NOT NULL, 
    [os] [nvarchar](25) NOT NULL, 
    [pctype] [nvarchar](25) NOT NULL, 
    [note] [nvarchar](50) NULL, 
    [password] [nvarchar](25) NOT NULL, 
    [tmngr] [bit] NOT NULL, 
    [type_user] [nvarchar] (25) Not null, 
    [w-internal-mac-address] [nvarchar](50) null) 

我使用DATALENGTH功能teamviewer_id列,當我試圖將數據插入到該列就顯示了這個錯誤:

insert statement is conflict with check constraint "nameoftheconstraint" the conflict occurred in database "nameofdatabase", table "nameoftable" column teamviewer_id

燦你幫助我嗎?檢查約束在這種情況下是否正確?

+0

哪些數據是你想插入teamviewer_id列?違反約束的例外情況表明數據長度不是9個字符。 – Andrew

+0

你需要'LEN'嗎? – Milen

+2

當您將長度限制爲9時,爲什麼要使用VARCHAR(25)? – dnoeth

回答

1

我使用Len,而不是和它的工作,謝謝