MATLAB: Do I receive a ‘General error’ when trying to use INSERT with Database Toolbox 3.0 (R14)

databaseDatabase Toolboxerrorgeneralinsertkeyprimary

I am using INSERT to add a row to one of the tables in a database. This works the first time I call INSERT, but subsequent calls result in an error message. For example, my first call is:
insert(conn,'productTable',{'productNumber','unitCost'},{1004,3.45});
This call works, but subsequent calls to INSERT result in the following error:
??? Error using ==> database.insert
General error

Best Answer

This error results when the database has a primary key and you try to insert a row with a non-unique primary key. A primary key is a unique identifier in a table and prevents a row from being inserted that has the same primary key value as another row. A primary key can include values from one or more fields. When you try to add a row with a value in the primary key field that is the same as an existing value in a primary key field, the insert fails and an error appears.