My typescript azure function, interacts with my SQL Server database. I can use TVPs to insert data into the database, except for when the receiving table type contains an IDENTITY
column. My table has 3 columns, the first being an IDENTITY
column.
When I pass a TVP with 3 columns I get the following error:
INSERT into an identity column not allowed on table variables
When I omit the identity column from the TVP and only send the remaining 2 columns, then it throws the following error:
Trying to pass a table-valued parameter with 2 column(s) where the corresponding user-defined table type requires 3 column(s).
This is the definition of user defined table type on SQL Server:
[PropertyOrder] [INT] IDENTITY(1,1) NOT NULL,
[Name] [NVARCHAR](200) NOT NULL,
[Value] [NVARCHAR](MAX) NULL
The TVP that is created in TypeScript:
const tvp = new Table()
tvp.columns.add('PropertyOrder', Int)
tvp.columns.add('Name', NVarChar(200))
tvp.columns.add('Value', NVarChar(MAX))
tvp.rows.add(1, 'TestName', 'TestValue')
Software versions
- NodeJS: 8.10
- node-mssql: 5.1.0
- SQL Server: Azure SQL database