I have two tables personaltbl and coursetbl .
In both table p_id is common field column
I want to add record inside coursetbl if p_id value not present inside coursetbl but present inside the personaltbl.
But I am facing problem to check p_id value inside the personaltbl but same p_id value not present inside coursetbl. if this p_id value is not present inside the coursetbl then I want to insert record inside coursetbl.
For example:
personaltbl coursetbl
p_id int pk c_id int
p_name char c_name char
p_add char c_fees bigint
p_id Fk
some records
personaltbl coursetbl
p_id p_name p_add | c_id c_name c_add p_id
1 xyz abc | 1 qqqq yyyyy 1
3 pqr def | 2 eeee mmm 7
7 ert hgh |
Here p_id value 3 is present inside personaltbl but it absent in coursetbl . I want to insert record inside coursetbl having p_id value 3 by checking p_id value inside coursetbl.
shortly I want to insert record inside coursetbl by checking p_id value if present inside personaltbl but absent in coursetbl.
please suggest sql query or procedure or trigger or cursor. thank you.