sql - Stored Procedure for multiple inserts with exiting if one fails -
i have eav table, each separate attribute have new row, this:
personid atributename atributevalue ----------------------------------- 1 name john 1 gender male 1 height 170
the problem if want insert new person (with id 2, name jack, male, height 180) need 3 more inserts, , there changes 1 ore more fail. thinking of including inserts in stored procedures parameters (id, name, gender, height, etc..).
my question is, doing this:
create procedure dbo.insersubject @id int, @name varchar(50), @gender varchar(50), @height int insert subjects values (1, 'name', 'john'), (1, 'gender', 'male'), (1, 'height', 170);
will fail if 1 of inserts fail? kind of implementation kind of database/table?
create procedure dbo.insersubject @id int, @name varchar(50), @gender varchar(50), @ height int begin try insert subjects values (1,'name','john'),(1,'gender','male'), (1,'height',170); end try begin catch error_message() end catch
Comments
Post a Comment