Sql-Server
當 ANSI_WARNINGS 關閉時,即使使用 nvarchar,也無法將其插入到我的特殊字元表中
我想在我的表中插入一個數據行,名稱為:DSKWOR00,但出現此錯誤:
字元串或二進制數據將被截斷。
所以我關閉了 ANSI_WARNINGS 並插入了行但結果不是我的值
這是我的 T-SQL :
1 - 創建我的表:
CREATE TABLE [dbo].[DSKWOR00]( [DSW_ID] [nvarchar](10) NULL, [DSW_YY] [float] NOT NULL, [DSW_MM] [float] NOT NULL, [DSW_LISTNO] [nvarchar](12) NULL, [DSW_ID1] [nvarchar](8) NULL, [DSW_FNAME] [nvarchar](60) NULL, [DSW_LNAME] [nvarchar](60) NULL, [DSW_DNAME] [nvarchar](60) NULL, [DSW_IDNO] [nvarchar](15) NULL, [DSW_IDPLC] [nvarchar](30) NULL, [DSW_IDATE] [nvarchar](8) NULL, [DSW_BDATE] [nvarchar](8) NULL, [DSW_SEX] [nvarchar](3) NULL, [DSW_NAT] [nvarchar](10) NULL, [DSW_OCP] [nvarchar](50) NULL, [DSW_SDATE] [nvarchar](8) NULL, [DSW_EDATE] [nvarchar](8) NULL, [DSW_DD] [float] NULL, [DSW_ROOZ] [float] NULL, [DSW_MAH] [float] NULL, [DSW_MAZ] [float] NULL, [DSW_MASH] [float] NULL, [DSW_TOTL] [float] NULL, [DSW_BIME] [float] NULL, [DSW_PRATE] [float] NULL, [DSW_JOB] [nvarchar](6) NULL, [PER_NATCOD] [nvarchar](10) NOT NULL, CONSTRAINT [PK_DSKWOR00] PRIMARY KEY CLUSTERED( [DSW_YY] ASC, [DSW_MM] ASC, [PER_NATCOD] Asc ) ON [PRIMARY]) ON [PRIMARY]
2 - 在我的表中插入一行:
INSERT INTO dbo.DSKWOR00 (DSW_ID,DSW_YY,DSW_MM,DSW_LISTNO,DSW_ID1,DSW_FNAME,DSW_LNAME,DSW_DNAME,DSW_IDNO,DSW_IDPLC,DSW_IDATE,DSW_BDATE,DSW_SEX,DSW_NAT,DSW_OCP,DSW_SDATE,DSW_EDATE,DSW_DD,DSW_ROOZ,DSW_MAH,DSW_MAZ,DSW_MASH,DSW_TOTL,DSW_BIME,DSW_PRATE,DSW_JOB,PER_NATCOD) VALUES ('6773790024',1401,1,1,'80079349','¤ç¬ üóä','ö‘þõþîž','‘®¤þóä','1011','¢¥þ','0','¢¤õ','ü÷¤þ',' ñõ‘ä ¤þ¢õ',0,0,'0','0','0','0','0','0','0','0',0,'OZ0509','4430928460')
3 - 如果我使用 ANSI_WARNINGS ON 插入錯誤:
Msg 8152, Level 16, State 30, Line 3 String or binary data would be truncated. --Note: My insert is correct I don't know why I'm seeing this error
4 - 所以為了修復錯誤,我這樣做了:
SET ANSI_WARNINGS OFF INSERT INTO dbo.DSKWOR00 (DSW_ID,DSW_YY,DSW_MM,DSW_LISTNO,DSW_ID1,DSW_FNAME,DSW_LNAME,DSW_DNAME,DSW_IDNO,DSW_IDPLC,DSW_IDATE,DSW_BDATE,DSW_SEX,DSW_NAT,DSW_OCP,DSW_SDATE,DSW_EDATE,DSW_DD,DSW_ROOZ,DSW_MAH,DSW_MAZ,DSW_MASH,DSW_TOTL,DSW_BIME,DSW_PRATE,DSW_JOB,PER_NATCOD) VALUES ('6773790024',1401,1,1,'80079349','¤ç¬ üóä','ö‘þõþîž','‘®¤þóä','1011','¢¥þ','0','¢¤õ','ü÷¤þ',' ñõ‘ä ¤þ¢õ',0,0,'0','0','0','0','0','0','0','0',0,'OZ0509','4430928460') SET ANSI_WARNINGS ON
5 -最後我的行將插入,但它不是我插入表中的值!
---- My Values in Inser : ('6773790034',1401,1,1,'80069349','¤ç¬ üóä','ö‘þõþîž','‘®¤þóä','1011','¢¥þ','0','¢¤õ','ü÷¤þ',' ñõ‘ä ¤þ¢õ',0,0,'0','0','0','0','0','0','0','0',0,'OZ0509','4430928444') ---- What did Insert : 6773790034 1401 1 1 80069349 ¤ç¬? ü?? ?‘???î? ‘®¤??? 1011 ¢¥? 0 ¢¤? ü÷? ??‘? ¤?¢? 0 0 0 0 0 0 0 0 0 0 0 OZ0509 4430928444
檢查表結構
$$ DSKWOR00 $$桌子。我想您會發現一個或多個欄位的長度不足以容納您嘗試插入的數據。我懷疑 DSW_SEX