We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi, is it possible to insert into TVP which has identity field.
Now I get "INSERT into an identity column not allowed on table variables"
Code example
db, _ := createDbConn() defer db.Close()
createTVP := ` CREATE TYPE dbo.TestType AS TABLE ( id INT IDENTITY(1,1) PRIMARY KEY, counter INT );` _, err := db.Exec(createTVP) createProc := ` CREATE PROCEDURE dbo.TestProc @TVP dbo.TestType READONLY AS SELECT * from @TVP ` _, err = db.Exec(createProc) type TestType struct { Counter int } TestTableType := []TestType{ { Counter: 1, }, { Counter: 3, }, } tvpType := mssql.TVP{ TypeName: "TestType", Value: TestTableType, } _, err = db.Exec("exec dbo.TestProc @TVP;", sql.Named("TVP", tvpType)) if err != nil { fmt.Println(err) }
Error: mssql: Trying to pass a table-valued parameter with 1 column(s) where the corresponding user-defined table type requires 2 column(s).
Using SQL Server Directly: ` declare @tvp dbo.TestType
insert @tvp ([counter]) values (1),(2)
exec dbo.TestProc @tvp ` Works fine
The text was updated successfully, but these errors were encountered:
Hi, is it possible to insert into TVP which has identity field. Now I get "INSERT into an identity column not allowed on table variables" Code example db, _ := createDbConn() defer db.Close() createTVP := ` CREATE TYPE dbo.TestType AS TABLE ( id INT IDENTITY(1,1) PRIMARY KEY, counter INT );` _, err := db.Exec(createTVP) createProc := ` CREATE PROCEDURE dbo.TestProc @TVP dbo.TestType READONLY AS SELECT * from @TVP ` _, err = db.Exec(createProc) type TestType struct { Counter int } TestTableType := []TestType{ { Counter: 1, }, { Counter: 3, }, } tvpType := mssql.TVP{ TypeName: "TestType", Value: TestTableType, } _, err = db.Exec("exec dbo.TestProc @TVP;", sql.Named("TVP", tvpType)) if err != nil { fmt.Println(err) } Error: mssql: Trying to pass a table-valued parameter with 1 column(s) where the corresponding user-defined table type requires 2 column(s). Using SQL Server Directly: ` declare @tvp dbo.TestType insert @tvp ([counter]) values (1),(2) exec dbo.TestProc @tvp ` Works fine
Hi, check #771 my MR. How to use.
For field set tag at tvp:"@identity".
tvp:"@identity"
Loot at the example in test. https://github.com/denisenkom/go-mssqldb/pull/771/files#diff-190109b133bdf8751fdc477fd4431d277075488688e403feeb86b0e1858c4dbbR1352
Sorry, something went wrong.
No branches or pull requests
Hi, is it possible to insert into TVP which has identity field.
Now I get "INSERT into an identity column not allowed on table variables"
Code example
db, _ := createDbConn() defer db.Close()
Error: mssql: Trying to pass a table-valued parameter with 1 column(s) where the corresponding user-defined table type requires 2 column(s).
Using SQL Server Directly:
`
declare @tvp dbo.TestType
insert @tvp ([counter])
values (1),(2)
exec dbo.TestProc @tvp
`
Works fine
The text was updated successfully, but these errors were encountered: