ProjetThe/ProjetTheAlone/Model - Copie/P_T_plat.sql

54 lines
1.2 KiB
Transact-SQL

CREATE PROCEDURE AjouterT_plat
@ID_plat int OUTPUT,
@P_nom int,
@P_img int,
@ID_typePlat int
AS
INSERT INTO T_plat(P_nom,P_img,ID_typePlat)
VALUES(@P_nom,@P_img,@ID_typePlat)
SET @ID_plat=@@IDENTITY
RETURN
GO
CREATE PROCEDURE ModifierT_plat
@ID_plat int,
@P_nom int,
@P_img int,
@ID_typePlat int
AS
IF(@ID_plat IS NULL OR @ID_plat=0)
RAISERROR('Identifiant requis !',16,1)
ELSE UPDATE T_plat
SET P_nom=@P_nom,P_img=@P_img,ID_typePlat=@ID_typePlat
WHERE ID_plat=@ID_plat
RETURN
GO
CREATE PROCEDURE SelectionnerT_plat
@Index VARCHAR(10)
AS
IF(@Index='P_nom') SELECT * FROM T_plat ORDER BY P_nom
ELSE IF(@Index='P_img') SELECT * FROM T_plat ORDER BY P_img
ELSE IF(@Index='ID_typePlat') SELECT * FROM T_plat ORDER BY ID_typePlat
ELSE SELECT * FROM T_plat ORDER BY ID_plat
RETURN
GO
CREATE PROCEDURE SelectionnerT_plat_ID
@ID_plat int
AS
IF(@ID_plat IS NULL)
RAISERROR('Identifiant requis !',16,1)
ELSE
SELECT ID_plat,P_nom,P_img,ID_typePlat
FROM T_plat
WHERE @ID_plat=ID_plat
RETURN
GO
CREATE PROCEDURE SupprimerT_plat
@ID_plat int
AS
IF(@ID_plat IS NULL)
RAISERROR('Identifiant requis !',16,1)
ELSE
DELETE FROM T_plat WHERE @ID_plat=ID_plat
RETURN
GO