sql - How to truncate and add new rows to the table with a select query never getting empty results -
i have requirement table holds state of things. table truncated , new status data in inserted in every second. problem if select query executed between delete , following insert, user empty table in return. sql transactions not here think not sure. also, if select query executed between delete , insert query, shouldn't return error because blocked database lock. should wait till delete + insert operation finished.
what best way implement such system? how should form "delete + insert" query , "select" query?
thank in advance.
--------additional information table result of multiple heavy queries , updated every second applications not run heavy queries , instead, required information table. truncate , insert every second , multiple selects @ random.
don't truncate table. instead, insert new status using identity primary key or date primary key. do:
select top 1 date table order date desc
or
select max(date) table
(these should have same execution plan.)
then, insert new date. when insert done, data available.
you can delete older rows @ leisure.
Comments
Post a Comment