小编use*_*247的帖子

插入记录的顺序不匹配

请检查下面的表结构和要插入该表的记录。

CREATE TABLE [tabGeneraltable](
   id int identity,
   [codGenLedger] [uniqueidentifier] NOT NULL,
   [codInvoice] [numeric](18, 0) NULL,
   [accountValue] [numeric](18, 2) NULL,
   [articleValue] [nvarchar](50) NULL,
   [codFinAccount] [int] NULL,
   [documentNbr] [nvarchar](50) NULL,
   [valueDate] [datetime] NULL,
   [insertDate] [datetime] NULL,
   CONSTRAINT [PK_tabGeneralLedger] PRIMARY KEY CLUSTERED([codGenLedger] ASC)
)


insert into [tabGeneraltable]([codGenLedger],[codInvoice], [codFinAccount],
                              [accountValue],[insertDate])
select NEWID(),1,11,232,getdate()
union all
select NEWID(),10,45,214,getdate()
union all
select NEWID(),9,425,410,getdate()
union all
select NEWID(),14,475,356,getdate()
Run Code Online (Sandbox Code Playgroud)

插入所有记录后,当在这个表上执行一个简单的选择语句时

select * from tabGeneraltable
Run Code Online (Sandbox Code Playgroud)

标识列 ID 的顺序不正确或记录是随机插入的。(insertDate如果单独插入所有记录,请检查列值。)

为什么会发生这种情况?

sql-server insert

4
推荐指数
1
解决办法
1760
查看次数

标签 统计

insert ×1

sql-server ×1