I'm trying to create a procedure to update my table
create proc UPDATE_PRODUCT
@ID_CAT INT,
@ID_PRODUCT VARCHAR(30),
@LABEL NVARCHAR(30),
@QTE INT,
@PRICE VARCHAR(50),
@IMG IMAGE
AS
UPDATE [Product_DB].[dbo].[PRODUCTS]
SET [ID_CAT] = @ID_CAT
,[LABEL_PRODUCT] = @LABEL
,[QTE_IN_STOCK] = @QTE
,[PRICE] = @PRICE
,[IMAGE_PRODUCT] = @IMG
WHERE ID_PRODUCT = @ID_PRODUCT
When I run this code the first time, it says "completed successfully"
However, I can't find it in Stored Procedure folder. I tried to do multiple refreshes and restarts but still the same.
When I try to create a procedure for other purpose like selecting or deleting, it works with no problems.
What's the solution?
Best Answer
The problem here is typically because you were in the wrong database context (in this sense, "wrong" means really "unexpected".
In other words, you were expecting to create the stored procedure in
Database1
, but you were really in the context ofDatabase2
.This is the exactly reason why I'm always explicit, especially with DDL. At the top of your script/query window/etc., always put:
This will ensure you don't run into this snag again. I tend to not rely on GUI drop-down lists and my memory to double-check which database is selected before running management SQL queries.