---
title: "Adding or Removing objects from SQLite in iOS."  
description: "Adding or Removing objects from SQLite in iOS."  
author: "Anonymous User"  
published: 2015-12-28  
updated: 2015-12-28  
canonical: https://www.mindstick.com/forum/33795/adding-or-removing-objects-from-sqlite-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Adding or Removing objects from SQLite in iOS.

In my [SQLite database](https://www.mindstick.com/articles/1554/crud-operation-in-asp-dot-net-using-sqlite-database) table I have [unique id](https://www.mindstick.com/forum/33873/how-to-get-unique-id-of-alasset-for-identification-in-ios) for each row and have rows name sequentially, like 5 rows in table and having id 0 to 4 for each row.\
now, when I [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) any row from table like row number 3, this occurs a 'hole' and afterwards I add more data on table but the 'hole' is still exists.\
[Please tell me](https://www.mindstick.com/forum/33900/please-tell-me-what-are-the-technique-to-content-optimization) that is this important for me to know exact number of row and to have at every row data in [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) to [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) my table arbitrarily.\
Is there any way in SQLite to do that, and can manage manually to remove and [add data](https://www.mindstick.com/forum/34130/how-to-add-data-into-the-post-method-of-a-form-in-extjs).

## Replies

### Reply by Tarun Kumar

In my knowledge primary keys of [database table](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table) usually should not change through the lifetime of the row. So, we can find the total number of rows by running:

```
SELECT COUNT(*) FROM table_name;
```

Now, create a TRIGGER for that table, whenever a delete creates a hole it will 'roll down' according to ID number:

```
CREATE TRIGGER table_trigger_name AFTER DELETE ON table_name FOR EACH ROWBEGINUPDATE table_name SET id=id-1 WHERE id > OLD.id;END;
```

I hope above example will solve your problem.


---

Original Source: https://www.mindstick.com/forum/33795/adding-or-removing-objects-from-sqlite-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
