sql - Deleting a user and the user profile -
i'm new sql , stored procedures, , need stored procedure below. have tables connected each other: "user" , "profile".
when deleting user user profile should deleted, , that's sp below does. however, when executing sp userids in table user shows (of course because of "select userid), , don't want.
so, guess question how write sp works without using select?
thanks in advance.
create procedure usp_deleteuser @userid int begin begin try begin transaction; select u.userid [user] u inner join profile p on u.userid = p.userid; delete profile userid = @userid; delete [user] userid = @userid; commit transaction; end try begin catch rollback transaction raiserror ('borttagningen gick inte att genomföra!',16,1) end catch end go
profile.userid
should foreign key indicating one-to-one relationship user
table, on delete cascade
specified. delete record user
table, , associated record in profile
table automatically removed.
Comments
Post a Comment