Why is SQL server throwing this error: Cannot insert the value NULL into column 'id'?

前端 未结 13 1461
鱼传尺愫
鱼传尺愫 2020-11-27 05:35

I\'m using the following query:

INSERT INTO role (name, created) VALUES (\'Content Coordinator\', GETDATE()), (\'Content Viewer\', GETDATE())
13条回答
  •  眼角桃花
    2020-11-27 06:28

    You can insert a value manually in the ID column (here I call it "PK"):

    insert into table1 (PK, var1, var2)
    values ((select max(PK)+1 from table1), 123, 456)
    

提交回复
热议问题