O
O
Optimus2016-05-24 07:00:12
MySQL
Optimus, 2016-05-24 07:00:12

How to create a statement in MySQL?

There are 4 fields in the table: id, workday, dayoff, sumdays
I want to add a check that the sum of workday + dayoff recorded in sumdays is no more than 365. I wrote:

CREATE ASSERTION Limitdays CHECK (
    NOT EXISTS (
        SELECT `workday`, `dayoff`, `sumdays`
        FROM `worker`
        WHERE id=id
        AND `sumdays` < 367
    )
);

Swears at the error
right syntax to use near 'ASSERTION Limitdays CHECK (
NOT EXISTS (
SELECT `workday`, `dayoff' at line 1
) Google almost nothing sensible at all. There are inter-table statements, but I have everything inside one table .. .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-05-24
Pyan @marrk2

MySQL does not support ASSERT.
Use BEFORE INSERT and BEFORE UPDATE triggers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question