I have a table called Student
sno Name Course Fee Section
1 AAA BCA 10000 A
2 BBB BCom 9000 B
3 CCC BTech 12000 B
I created a temp table called Course_tvp_tbl
CREATE TYPE dbo.Course_tvp_tbl AS TABLE (course VARCHAR(25) NOT NULL PRIMARY KEY (course))
and inserted values into this temp table.
course
BTech
Now I want to delete values from student where the course in temp table course column. We can use the in clause directly but, the table volume is big and also my in clause will contain 1000's of course ids. Tried with creating index(non-clustered as we have clustered already) also having issue as its taking more time OR lock request time out is happening as the query run from multiple instances. I want to use the stored procedure with table value parameters.
CREATE PROCEDURE DBO.DELETE_STUDENTS
@section char(1),
@course_tbl dbo.Course_tvp_tbl READONLY
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM Student where section = @section and course IN (SELECT course FROM @course_tbl)
END
Is the stored procedure delete query having issue. how can I use the temp table course column in delete query In clause?
Followed the TVP Example and wants to use tvp column in deleting the rows from main table
PRINT @section;