Writing data back to MSSQL table containing an identity column
I want to write back changes to a MSSQL database after reading information from a table.
The table is designed to provide a minimum working example and has two columns:
ID: ID column starting with 1, increments with 1
VALUE: column containing integer values.
I have managed to read from this database table, however, I want to be able to change a value in AIMMS and then write back the change using
write p_parameter(i_ID) to table db_TableName;
However, this gives me an error stating that I'm not allowed to insert manally into an ID column. This makes sense of course, but how do I prevent AIMMS from trying to insert into the ID column and replace old values by new ones instead?
Page 1 / 1
Hi Chris, that works! Thank you
Hi Bjorn,
Sorry, I didn't have a MS SQL ready to test with, that is why I used MySQL.
Would you mind trying the following:
block where database_foreign_key_handling := 'assume',
Hi Chris, thanks for you reply. Unfortunately I still get the same error (included at the bottom of this post). I started with creating a new sample table (in MSSQL):
INSERT INTO [tmp].[aimmsTest]([value]) VALUES (5); INSERT INTO [tmp].[aimmsTest]([value]) VALUES (6); INSERT INTO [tmp].[aimmsTest]([value]) VALUES (7); INSERT INTO [tmp].[aimmsTest]([value]) VALUES (8); INSERT INTO [tmp].[aimmsTest]([value]) VALUES (9);
And in AIMMS I made the exact same procedures, dbtable, parameter, set and index. Of course also the mapping in the dbtable is done in the same manner.
Reading data into the set and parameter worked as expected, however, when trying to run
write to table db in replace mode ;
I (still) get the following error: (in a spoiler because it is long)
Error writing to database table "db_GetData": ODBCB544] : 23000 0Microsoft]tSQL Server Native Client 11.0]0SQL Server]Cannot insert explicit value for identity column in table 'aimmsTest' when IDENTITY_INSERT is set to OFF. 23000 0Microsoft]tSQL Server Native Client 11.0]0SQL Server]Cannot insert explicit value for identity column in table 'aimmsTest' when IDENTITY_INSERT is set to OFF. 23000 0Microsoft]tSQL Server Native Client 11.0]0SQL Server]Cannot insert explicit value for identity column in table 'aimmsTest' when IDENTITY_INSERT is set to OFF. 23000 0Microsoft]tSQL Server Native Client 11.0]0SQL Server]Cannot insert explicit value for identity column in table 'aimmsTest' when IDENTITY_INSERT is set to OFF. 23000 0Microsoft]tSQL Server Native Client 11.0]0SQL Server]Cannot insert explicit value for identity column in table 'aimmsTest' when IDENTITY_INSERT is set to OFF.
The error message is one from MSSQL, which happens when you try to use the INSERT statement to insert values into an ID column.
I have not been able to set up a connection with a mySQL test table due to some other technical difficulties.