how to set maximum rows in create table for sqlite

In MySQL, I can use MAX_ROWS option in CREATE TABLE statement to limit rows number, how might I do this in sqlite? thanks

Answers


SQLite has no explicit mechanism for this, but you could implement it with a trigger:

CREATE TRIGGER MyTable_row_count
BEFORE INSERT ON MyTable
WHEN (SELECT COUNT(*) FROM MyTable) >= 10
BEGIN
    SELECT RAISE(FAIL, 'too many rows');
END;

SQLite has no such equivalent option.

Your best bet is to run SELECT COUNT(*) FROM tbl before inserting and checking if the returned count is greater than whatever you want your maximum to be.


Need Your Help

C - How to use an API library in linux

c linux api ubuntu

I'm really hopeless when it comes to Unix-like systems. I tried to download an open library to my Ubuntu system, so that I could use its functions in my own C code. However, now that I've downloade...

richtextbox binding

wpf binding richtextbox

I have 2 RichTextBoxes (rtb1, rtb2), I something wrote in rtb1 and click on enter key, on this event is added text from rtb1 to rtb2. I solved this in code behind, it is possible this same write in