use ApressFinancial
go
INSERT INTO CustomerDetails.CustomerProducts
(
CustomerId,
FinancialProductId,
AmountToCollect,
Frequency,
LastCollected,
LastCollection
)
VALUES(1,1,100,0,'8/24/2005','8/26/2005')运行后显示的错误是:不能将值 NULL 插入列 'CustomerFinancialProductId',表 'ApressFinancial.CustomerDetails.CustomerProducts';列不允许有空值。INSERT 失败。
语句已终止。
但是那个 CustomerFinancialProductId 的值我在 VALUES 中已经设为 1 错误在哪里呢? 期望您的回复,非常感谢!!

解决方案 »

  1.   

    系统提示的列名:CustomerFinancialProductId
    你指定的是列:FinancialProductId,而不是:CustomerFinancialProductId
      

  2.   

    LZ再查查, 估计CustomerFinancialProductId还是没有指定缺省值.
      

  3.   

    use ApressFinancial 
    go 
    INSERT INTO CustomerDetails.CustomerProducts 
    (
    CustomerFinancialProductId, 
    CustomerId, 
    FinancialProductId, 
    AmountToCollect, 
    Frequency, 
    LastCollected, 
    LastCollection 

    VALUES(1,1,1,100,0, '8/24/2005 ', '8/26/2005 ') 
      

  4.   

    语句没有问题】
     CustomerDetails.CustomerProducts 是表名吗?
    其他问题~例~
    create table tt(id int,groups nvarchar(10),InActive int)insert into tt (id,groups,InActive) values(1,1,1)
    insert tt select 1,'1',1
      

  5.   

    CustomerFinancialProductId 是主键,系统怎么不自动填充呢?比如填充为1或2..
      

  6.   

     charry0110 :CustomerDetails.CustomerProducts 是表名吗? -----------------------------------------------------------------
    CustomerDetails 是架构名,CustomerProducts 是表名
      

  7.   

    这是Robin Dewson的《SQL Server 2005 基础教程》中的一个例子,人民邮电出版,他直接通过T-SQL 来设置主键的,在添加数据的时候是像我问题中所写的那样编写代码的,所以有点奇怪,主键CustomerFinancialProductId 没有自动填写,这本书的前面在插入数据的时候也是这样的,都是在主键列让系统自动填写,不知道这里为什么不行?有人看过这本书吗,这个问题出在这本书的第221页
      

  8.   

    CustomerFinancialProductId列有not null约束,也没有指定default值。insert 语句中没有给这一列赋值。