Interview Question in Microsoft Transact-SQL


 

Interview Question :: How to make a general stored procedure in T-SQL for the INSERT,UPDATE and DELETE operations


I have an entity named Country with fields: CountryID, CountryName where CountryID is a primary key. And i like to create a general stored procedure that does INSERT, UPDATE and DELETE operations. How can i do that?
Answers to "How to make a general stored procedure in T-SQL for the INSERT,UPDATE and DELETE operations"
RE: How to make a general stored procedure in T-SQL for the INSERT,UPDATE and DELETE operations?

Need a bit more info here. On each function, where are the value(s) and/or key coming from that you want to insert/update/delete. Do you want the procedures to be fairly generic with values/keys passed as parameters?



Edit: For updates



IF @operation = 'update'

BEGIN

UPDATE COUNTRY

SET somecol = @somevariable,

SET comecol2 = @somevar2,

...

WHERE COUNTRYNAME=@CountryName

END
 
Vote for this answer ::  
Update Alert Setting