I want to store only last 200 data (if 201 data is coming means i need to delete 1 row and so on….)to table in database.Is there any logic?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think you can do this in a single statement. Suppose a table has a primary key column ‘id’, a data column ‘dataCol’, and a time stamp column ‘dataTime’. Here’s an approach (untested) that deletes the oldest row whenever the number of rows exceeds 200:
If you aren’t going to delete data for any reason other than that the table is full, then another approach is possible. (No idea if this is better.) Start by pre-populating the table with 200 entries. Then create a second table with bookkeeping information about what’s in the first table. The second table would have a single row that keeps the following information:
The idea is that you insert new data into the first table at the index specified by the second table, increment the second table’s slot column modulo 200, and set the full column to 1 the first time the slot pointer wraps back to 0.