如何将一个表的列数据复制到另一个表

时间:2016-03-05 13:39:41

标签: sql

我正在使用以下代码:

Insert into JV(PurchaseID)
    select PurchaseID from PurchaseReturnDetail

但是当我执行查询时,它会出错:

  

无法将值NULL插入列'column1',表'database.table1';列不允许空值。

然后我的INSERT失败了。可能是什么问题?

2 个答案:

答案 0 :(得分:0)

错误表示该列对列具有非空约束。要将列更改为允许空值,请运行此查询(对于Oracle DB):

var group = L.featureGroup().addTo(map);

L.circle(
  [46.765735535841024, 23.58344078063965], 5, {
    color: "blue"
  }
).addTo(group);
// more L.circle's...

group.on("click", function (e) {
    var clickedCircle = e.layer; // e.target is the group itself.

  // do something, like:
  clickedCircle.bindPopup("some content").openPopup();
});

答案 1 :(得分:0)

如果第一列是标识列,请确保为该列启用了自动增量。

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[JV](
    [JVID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
    [JVInvoiceNo] [nvarchar](50) NULL,
    [JVDate] [datetime] NULL,
    [StoreID] [numeric](18, 0) NULL,
    [BusinessID] [numeric](18, 0) NULL,
    [UserID] [numeric](18, 0) NULL,
    [Currency] [nvarchar](50) NULL,
    [Rate] [decimal](18, 10) NULL,
    [DueDate] [datetime] NULL,
    [Reference] [nvarchar](50) NULL,
    [RefID] [numeric](18, 0) NULL,
    [Narration] [nvarchar](max) NULL,
    [InvoiceRef] [nvarchar](50) NULL,
    [Status] [nvarchar](50) NULL,
    [Type] [nvarchar](50) NULL,
    [PurchaseID] [numeric](18, 0) NULL,
 CONSTRAINT [PK_JV] PRIMARY KEY CLUSTERED 
(
    [JVID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO