非常简单的插入选择不工作?

时间:2014-09-23 13:01:54

标签: sql select sqlite insert bulkinsert

我所做的就是重新制作一个表,并在列上添加空约束和默认值:

原始表格结构(现已重命名):

CREATE TABLE "CARTWEIGHTS_old" (
  EntryTime DateTime, 
  Employee TEXT, 
  PLUGS NUMERIC,
  ID INTEGER PRIMARY KEY, 
  PO NUMERIC, 
  FUSER INTEGER, 
  REMAN INTEGER, 
  OEM INTEGER, 
  DIGITEK INTEGER, 
  LEXMARK INTEGER, 
  PDW INTEGER, 
  TRASH INTEGER, 
  CART TEXT,
  "Voided" BOOL NOT NULL  DEFAULT 0
)

新表:

CREATE TABLE CARTWEIGHTS (
  EntryTime DateTime,
  Employee TEXT,
  PLUGS NUMERIC NOT NULL DEFAULT 0,
  ID INTEGER PRIMARY KEY,
  PO NUMERIC,
  FUSER INTEGER NOT NULL  DEFAULT 0, 
  REMAN INTEGER NOT NULL  DEFAULT 0,
  OEM INTEGER NOT NULL  DEFAULT 0, 
  DIGITEK INTEGER NOT NULL  DEFAULT 0,
  LEXMARK INTEGER NOT NULL  DEFAULT 0, 
  PDW INTEGER NOT NULL  DEFAULT 0,
  TRASH INTEGER NOT NULL  DEFAULT 0,
  CART TEXT, 
  "Voided" BOOL NOT NULL  DEFAULT 0
)

然后当我尝试跑步时:

insert into CARTWEIGHTS 
select * from CARTWEIGHTS_old

CARTWEIGHTS表未随信息更新。 SQLite也没有给我任何错误。

1 个答案:

答案 0 :(得分:2)

您的问题在于ID序列生成器。请勿尝试将PK插入目标表:

INSERT INTO "CARTWEIGHTS"  
"EntryTime","Employee","PLUGS","PO","FUSER","REMAN","OEM","DIGITEK","LEXMARK",
"P‌​DW","TRASH","CART","Voided"  
SELECT "EntryTime","Employee","PLUGS","PO","FUSER","REMAN","OEM","DIGITEK","LEXMARK",
"P‌​DW","TRASH","CART","Voided" FROM "CARTWEIGHTS_old"