Junior — Middle
Can you explain what sequential data access in a database is and how it works?
sobes.tech AI
Answer from AI
Sequential access to data in a database means reading or processing records in order, one after another, starting from the first and ending with the last, without skipping.
Unlike random access, where you can directly jump to a specific record by index or key, sequential access is typically used when traversing all data, for example, when reading all rows of a table.
In databases, this is often implemented through cursors or iterators, which allow sequential retrieval of records from a query result.
Example in Python using SQLite:
import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM users')
for row in cursor:
print(row) # Process each record in order
conn.close()
Here, data is read sequentially, which is convenient for processing large datasets without loading the entire result into memory at once.