Posts

Showing posts with the label stored-procedures

SQL Server - update field in one table and updated related fields in multiple other tables, trigger, stored procedure or combination of both?

I'm working on a college problem and need to create a stored procedure to soft-delete a record in one table and the associated records in other tables. I'm trying to figure out how I might approach this and hence here I am. I have the following tables: As you can see, all of these tables have an IsDeleted column set with the data type bit and defaults to 0 (to allow for soft deletes). What I'm trying to achieve is that when dbo.Customers(IsDeleted) is updated to bit 1, the following records automatically update to bit 1 also: My initial thought is to set up a stored procedure to allow the end-user to easily update the dbo.Customers(IsDeleted) column and then a trigger to update the related records but I'm not clear if this is the best approach and if so where to start. My research into solving the problem so far has further confused me as it seems I need to be very careful that my code restricts the update of the IsDeleted columns ONLY as a standard stored procedu...

How to insert data if not exist else update it?

I want to update row if exists in table bag else insert new row these types of columns that I used it in table bag I make car_name and p_id as primary (composite key) I write this code in MySQL routine in xampp and it saves in xampp without errors but when I tries to execute it in xampp it makes error that says The following query has failed: "SET @p0='mohamed'; SET @p1='1'; SET @p2='1'; SET @p3='1'; CALL bag_insert (@p0, @p1, @p2, @p3); " MySQL said: Code: By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.