A
A
Anton2016-09-10 02:00:37
MySQL
Anton, 2016-09-10 02:00:37

How to limit the number of records in a table with a specific field?

Hello. Is it possible to somehow limit the number of records with a certain field in the database without triggers and procedures?
For example, there is a table in which there is a user_id field, is it possible to make a user with a user_id, for example 5, be able to make only 10 entries.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2016-09-10
@DmitriyEntelis

start transaction
select count(*) from ... where user_id = ... for update

and then we look at the YaP - you can insert it or not.

D
DrunkMaster, 2016-09-10
@DrunkMaster

Do COUNT(*) before INSERT for example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question