I created the table on SQL Server as follows:
CREATE TABLE testPK
(
ID INT NOT NULL IDENTITY (1, 1) PRIMARY KEY,
NumVal NUMERIC (18, 4)
)
Now I want to add data to testPK from the R program using the RODBC function sqlSave()
, as shown below:
test.dt <- data.table(NumVal = 1.0)
myconn <- odbcDriverConnect(connectionString)
sqlSave(channel = myconn, dat = test.dt, tablename = 'testPK',
rownames = FALSE, append = TRUE)
odbcCloseAll()
However, this returns an error message
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'
I did not specify a value for the column identifier in my data table because I assume that the IDENTITY specification in this column of my SQL table causes SQL Server to generate a unique value when adding a new record. How can I achieve this result from R?
The same question was sent here , but without a decision.
source
share