D
D
Drottarutarnum2020-08-31 02:19:43
SQLite
Drottarutarnum, 2020-08-31 02:19:43

How to limit the number of entries?

There is a table for logging records, how to make sure that records older than one month are deleted relative to the last record?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Vodakov, 2020-08-31
@Drottarutarnum

For sampling:

SELECT 
*
FROM logTable
WHERE logTable.date > DATEADD(month, -1, (SELECT MAX(logTable.date) FROM logTable))

For removing:
DELETE
FROM logTable
WHERE logTable.date <= DATEADD(month, -1, (SELECT MAX(logTable.date) FROM logTable))

R
Roman Mirilaczvili, 2020-08-31
@2ord

Create a task that will run a query with the removal of old entries and add it to the task scheduler for daily execution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question