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

前端 未结 13 1493
鱼传尺愫
鱼传尺愫 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:25

    I'm assuming that id is supposed to be an incrementing value.

    You need to set this, or else if you have a non-nullable column, with no default value, if you provide no value it will error.

    To set up auto-increment in SQL Server Management Studio:

    • Open your table in Design
    • Select your column and go to Column Properties
    • Under Indentity Specification, set (Is Identity)=Yes and Indentity Increment=1

提交回复
热议问题