Reputation:
I am making a project in C# and I have connected to my SQL Server 2008 database. I created a procedure but I keep getting error that it couldn't be found. Funny thing is that I created 2 more procedures in same script and everything works fine.
First I read script and execute all code, and that passes very well, then one table is created and 2 procedures and finally I come to my last procedure but it keep's giving me error. I'll put some code so you guys can see what have I done wrong.
IF object_id('Uporabniki') IS NULL
CREATE TABLE Uporabniki
(
id_uporabnika int,
ime_uporabnika nvarchar(200) not NULL,
skupina_uporabnika nvarchar(200) not NULL,
PRIMARY KEY (id_uporabnika)
)
GO
IF object_id('Dodaj_uporabnika') IS NULL
EXEC sp_executesql N'
CREATE PROCEDURE Dodaj_uporabnika
-- Add the parameters for the stored procedure here
@ime_uporabnika nvarchar(200),
@skupina_uporabnika nvarchar(200)
AS
BEGIN
DECLARE @id_konec INT
SET @id_konec=(SELECT MAX(id_uporabnika) FROM Uporabniki);
IF(@id_konec IS NULL)
BEGIN
SET @id_konec= 1
insert into Uporabniki (id_uporabnika,ime_uporabnika, skupina_uporabnika) values (@id_konec, @ime_uporabnika,@skupina_uporabnika);
END
ELSE
BEGIN
insert into Uporabniki (id_uporabnika,ime_uporabnika, skupina_uporabnika) values (@id_konec + 1, @ime_uporabnika,@skupina_uporabnika);
END
END'
GO
IF object_id('Spremeni_uporabnika') IS NULL
EXEC sp_executesql N'
CREATE PROCEDURE Spremeni_uporabnika
-- Add the parameters for the stored procedure here
@stari_id int,
@novo_ime_uporabnika nvarchar(200),
@nova_skupina_uporabnika nvarchar(200)
AS
BEGIN
BEGIN
UPDATE Uporabniki SET ime_uporabnika=@novo_ime_uporabnika,skupina_uporabnika=@nova_skupina_uporabnika WHERE @stari_id=id_uporabnika;
END
END'
GO
IF object_id('Brisanje_uporabnika') IS NULL
EXEC sp_executesql N'
CREATE PROCEDURE Brisanje_uporabnika
-- Add the parameters for the stored procedure here
@id_uporabnika int
AS
BEGIN
BEGIN
DELETE * FROM Uporabniki WHERE @id_uporabnika = id_uporabnika;
END
END'
GO
Upvotes: 1
Views: 169
Reputation: 453067
DELETE * FROM Uporabniki
is invalid syntax so Brisanje_uporabnika
will never be created.
use
DELETE FROM Uporabniki
instead. Not sure how you are submitting this script but you should see the following error when you run it.
Msg 102, Level 15, State 1, Procedure Brisanje_uporabnika, Line 9
Incorrect syntax near '*'.
Upvotes: 5