Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table (template_colour_t) with two columns. Those two columns are combination of primery key.

> template_id colour_id

> -------------|-------------

> tp0001 | 0001
> tp0001 | 0003
> tp0002 | 0002
> tp0003 | 0001

I want a procedure which will maintain insert and update code in this single procedure.

More info:

Template_id 'tp0001' is connected with multiple colour_id (0001, 0005, 0003)

I want to add and remove some colur_id with this template_id.

Example:

After add and remove the template_id 'tp0001' should have (0001, 0005, 0004, 0009, 0008) this many colour_id.


Inside the procedure we need to check what and all exsist and what are the new one and if any one is not exist then need to delete.

Based on that we need to delete, insert the row.

Please help me to get that code.

Advanced thanks to all.
Posted

1 solution

You can check if a row with particular values exists by using IF EXISTS

EXISTS (Transact-SQL)[^]

sql - Check if a row exists, otherwise insert - Stack Overflow[^]

Or MERGE if your version of SQL supports it (example also in link above).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900