0

Need to keep running count of Rows in very large database. Row Count is needed enough times in my program that running Count(*) is too slow, so I will just keep running count to get around this in SQLITE.

CREATE TRIGGER RowCountUpdate AFTER INSERT ON LastSample
        BEGIN
        UPDATE BufferControl SET NumberOfSamples = NumberOfSamples + 
        (SELECT Count(*) FROM Inserted);
        END;

So from here I want to take the current number of rows (NumberOfSamples) and increment it with how many rows were affected by the insert (do same with DELETE and decrementing). In the C API of Sqlite, this is done with Sqlite3_Changes(). However, I cannot use that function here in this script. I looked around and saw that some were using the SELECT Count(*) FROM Inserted, but I don't think Sqlite supports that.

Is there any statement that Sqlite recognizes that holds the amount of rows that were affected by the INSERT and DELETE queries?

4

1 回答 1

1

SQLite 有changes() SQL 函数,但和sqlite3_changes()API 函数一样,它报告最后完成语句的行数。在触发器执行期间,触发语句尚未完成。

只需使用FOR EACH ROW触发器,并为每一行添加 1。

于 2013-07-09T19:30:34.757 回答