I am trying to insert the following into SQL
INSERT INTO Customers (contactname, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway');
When I do this, I get an error :
Cannot insert the value NULL into column 'CustomerID', table 'Northwind.dbo.Customers'; column does not allow nulls. INSERT fails.
I tried to change the properties of the customer id to allow null values but it says "null property cannot be set on a column which is part of the primary key"?
Does anyone have an idea?
CodePudding user response:
you can move primary to contact name if you want to try make customerID null, but always remember one of caracteristics from primary key is must be uniq value
CodePudding user response:
Primary keys must be unique and cannot be null. They're the individuating column(s) for a given table.
You won't need to worry about manually setting the CustomerID
column if you set it to auto increment, which is best practice for integer keys.