CREATE PROCEDURE SP_Zhanr_InsEdit
@ID_ZHANR INT,
@NAME_ZHANR VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_ZHANR)
        FROM Zhanr
        WHERE ID_ZHANR = @ID_ZHANR
         if (@COUNTREC = 0)
		begin
			INSERT INTO Zhanr(NAME_ZHANR)
                        VALUES (@NAME_ZHANR)
		end
	 else
		begin
			UPDATE Zhanr SET
			NAME_ZHANR = @NAME_ZHANR
			WHERE ID_ZHANR = @ID_ZHANR 
		end	
END
GO

..................................................
CREATE PROCEDURE SP_Proizvoditel_InsEdit
@ID_PROIZV INT,
@NAME_PROIZV VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_PROIZV)
        FROM Proizvoditel
        WHERE ID_PROIZV = @ID_PROIZV
         if (@COUNTREC = 0)
		begin
			INSERT INTO Proizvoditel(NAME_PROIZV)
                        VALUES (@NAME_PROIZV)
		end
	 else
		begin
			UPDATE Proizvoditel SET
			NAME_PROIZV = @NAME_PROIZV
			WHERE ID_PROIZV = @ID_PROIZV 
		end	
END
GO

.................................................. 	
CREATE PROCEDURE SP_Vozrast_InsEdit
@ID_VOZR  INT,
@VOZR_OGR VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_VOZR)
        FROM Vozrast
        WHERE ID_VOZR  = @ID_VOZR 
         if (@COUNTREC = 0)
		begin
			INSERT INTO Vozrast(VOZR_OGR)
                        VALUES (@VOZR_OGR)
		end
	 else
		begin
			UPDATE Vozrast SET
			NAME_PROIZV = @NAME_PROIZV
			WHERE ID_VOZR  = @ID_VOZR  
		end	
END
GO

.................................................. 
CREATE PROCEDURE SP_Zal_InsEdit
@ID_ZAL INT,
@NAME_ZAL VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_ZAL)
        FROM Zal
        WHERE ID_ZAL = @ID_ZAL
         if (@COUNTREC = 0)
		begin
			INSERT INTO Zal(NAME_PROIZV)
                        VALUES (@NAME_PROIZV)
		end
	 else
		begin
			UPDATE Zal SET
			NAME_ZAL = @NAME_ZAL
			WHERE ID_ZAL = @ID_ZAL
		end	
END
GO

.................................................. 		
CREATE PROCEDURE SP_Regisser_InsEdit
@ID_REG INT,
@NAME_REG VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_REG)
        FROM Regisser
        WHERE ID_REG = @ID_REG
         if (@COUNTREC = 0)
		begin
			INSERT INTO Regisser(NAME_REG)
                        VALUES (@NAME_REG)
		end
	 else
		begin
			UPDATE Regisser SET
			NAME_REG = @NAME_REG
			WHERE ID_REG = @ID_REG
		end	
END
GO

.................................................. 	
CREATE PROCEDURE SP_Producer_InsEdit
@ID_PRODUC INT,
@NAME_PRODUC VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_PRODUC)
        FROM Producer
        WHERE ID_PRODUC = @ID_PRODUC
         if (@COUNTREC = 0)
		begin
			INSERT INTO Producer(NAME_PRODUC)
                        VALUES (@NAME_PRODUC)
		end
	 else
		begin
			UPDATE Producer SET
			NAME_PRODUC = @NAME_PRODUC
			WHERE ID_PRODUC = @ID_PRODUC
		end	
END
GO

..................................................	
CREATE PROCEDURE SP_Kinokompania_InsEdit
@ID_ KK INT,
@NAME_ KK VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_ KK)
        FROM Kinokompania
        WHERE ID_ KK = @ID_ KK
         if (@COUNTREC = 0)
		begin
			INSERT INTO Kinokompania(NAME_ KK)
                        VALUES (@NAME_ KK)
		end
	 else
		begin
			UPDATE Kinokompania SET
			NAME_ KK = @NAME_ KK
			WHERE ID_ KK = @ID_ KK
		end	
END
GO

..................................................	
CREATE PROCEDURE SP_GLR_InsEdit
@ID_ GLR INT,
@NAME_ GLR VARCHAR(20)
AS
	DECLARE @COUNTREC integer;
BEGIN
        SELECT @COUNTREC = COUNT(@ID_ GLR)
        FROM GLR
        WHERE ID_ GLR = @ID_ GLR
         if (@COUNTREC = 0)
		begin
			INSERT INTO GLR(NAME_ GLR)
                        VALUES (@NAME_ GLR)
		end
	 else
		begin
			UPDATE GLR SET
			NAME_ GLR = @NAME_ GLR
			WHERE ID_ GLR = @ID_ GLR
		end	
END
GO

..................................................
CREATE PROCEDURE SP_Film_InsEdit 
	@ID_FILM VARCHAR(36),
	@NAME_FILM VARCHAR(20),
	@FK_ZHANR INT
	@FK_PRODUC INT
	@FK_PROIZV INT
	@FK_VOZR INT
	@FK_REG INT
	@FK_GLR INT
	@FK_KK INT
AS
	DECLARE @COUNTREC integer;
BEGIN
	SELECT @COUNTREC = COUNT(@ID_FILM)
	FROM Film
	WHERE ID_FILM = @ID_FILM
	 if (@COUNTREC = 0)
		begin

			INSERT INTO Film(ID_FILM,NAME_FILM,FK_ZHANR,FK_PRODUC,FK_PROIZV,FK_VOZR,FK_REG,FK_GLR,FK_KK)
			VALUES (NEWID(),@NAME_FILM,@FK_ZHANR,@FK_PRODUC,@FK_PROIZV,@FK_REG,@FK_REG,@FK_GLR,@FK_KK);
		end
	 else
		begin
			UPDATE Film SET
	                NAME_FILM = @NAME_FILM
	                FK_ZHANR = @FK_ZHANR
	                FK_PRODUC = @FK_PRODUC
	                FK_PROIZV = @FK_PROIZV
	                FK_VOZR = @FK_VOZR
	                FK_REG = @FK_REG
	                FK_GLR = @FK_GLR
	                FK_KK = @FK_KK
                        WHERE ID_FILM = @ID_FILM 
		end	
END
GO

..................................................
CREATE PROCEDURE SP_Afisha_InsEdit 
	@ID_AFISHA VARCHAR(36)
	@FK_FILM INT
	@DATA_POKAZ DATATIME
	@TIME_POKAZ VARCHAR(5)
	@FK_ZAL INT
	@PRICE INT
AS
	DECLARE @COUNTREC integer;
BEGIN
	SELECT @COUNTREC = COUNT(@ID_AFISHA)
	FROM Afisha
	WHERE ID_AFISHA = @ID_AFISHA
	 if (@COUNTREC = 0)
		begin

			INSERT INTO Afisha(ID_AFISHA,FK_FILM,DATA_POKAZ,FK_ZAL,PRICE)
			VALUES (NEWID(),@ID_AFISHA,@FK_FILM,@DATA_POKAZ,@FK_ZAL,@PRICE);
		end
	 else
		begin
			UPDATE Afisha SET
	                FK_FILM = @FK_FILM
	                DATA_POKAZ = @DATA_POKAZ
	                TIME_POKAZ = @TIME_POKAZ
	                FK_ZAL =  @FK_ZAL
	                PRICE = @PRICE
                        WHERE ID_AFISHA = @ID_AFISHA
		end	
END
GO

................................................