SQL Server, can't insert null into primary key

2020-01-29 07:24发布

I'm about ready to rip my hair out on this one. I'm fairly new to MS SQL, and haven't seen a similar post anywhere.

When I try to do a statement like this:

INSERT INTO qcRawMatTestCharacteristic 
VALUES(NULL, 1,1,1,1,1,1,1,'','','', GETDATE(), 1)

I get the following:

Cannot insert the value NULL into column 'iRawMatTestCharacteristicId', table 'Intranet.dbo.qcRawMatTestCharacteristic'; column does not allow nulls. INSERT fails.

I understand the error, but the null value is for my my primary field with an int data type.

Any ideas!?

8条回答
孤傲高冷的网名
2楼-- · 2020-01-29 08:21

You probably don't have (you forgot to add) autoincrement set on your integer primary key.

查看更多
劫难
3楼-- · 2020-01-29 08:22

you can use 0 instead of null for only 1 unique row, null is not possible for PK. Or you can omit PK and use and auto increament PK field

查看更多
登录 后发表回答