1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] How to fix Errors when adding Check function: 3815 or 3814. An expression of a check...

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 4, 2024 às 05:23.

  1. Stack

    Stack Membro Participativo

    I have a problem with MYSQL. I have one table "screening" that consist of scrreningID(PK), movieID (FK) and roomID (FK). I want to make a check that if the movie is3d and room canplay3d, insert function can be executed. Otherwise, if movie is not3d and the room canplay3d then the insert cannot be done.

    I try to alter my tabla and add a Check constraint. I created a Function for the Check constraint. However, It is always getting Error

    Here is my function Code :

    CREATE DEFINER=`root`@`localhost` FUNCTION `is3d`(mov int, roo int) RETURNS int(11)
    READS SQL DATA
    DETERMINISTIC
    BEGIN
    declare movie_3d integer;
    declare room_3d integer;

    select is3d into movie_3d from movie where movieID = mov;
    select canplay3d into room_3d from room_auditorium where roomID = roo;

    if (movie_3d = 1 && room_3d =1) then
    RETURN 1;
    else
    return 0;
    end if;

    END


    The function is successful and it works well. But when I add it to the Check constraint

    alterter table screening_show add constraint
    checkisthreedy check (is3d(movieID, roomID) = 1)


    it always shows an error:

    Error Code: 3814. An expression of a check constraint xonstrainname contains disallowed function: CustomerLevel.

    I also tried to make basic functions, but the result is still the same when I use it for Check constraint.

    Continue reading...

Compartilhe esta Página