Google Sheets as a Simple Database with Apps Script
Google Sheets isn't a real database, but for small to medium datasets it works remarkably well as a lightweight data store — especially when combined with Apps Script for CRUD operations.
Sheet structure
Treat row 1 as your header row (column names). Each subsequent row is a record. Add an ID column (column A) to uniquely identify rows.
functionupdateRecord(id, updates){const sheet =getDb();const data = sheet.getDataRange().getValues();const headers = data[0];const idCol = headers.indexOf('ID');for(let i =1; i < data.length; i++){if(data[i][idCol]=== id){Object.entries(updates).forEach(([key, value])=>{const col = headers.indexOf(key);if(col !==-1){ sheet.getRange(i +1, col +1).setValue(value);}});Logger.log('Updated record: '+ id);returntrue;}}Logger.log('Record not found: '+ id);returnfalse;}// Usage:// updateRecord('some-uuid', { Status: 'Inactive' });
DELETE — remove a record by ID
functiondeleteRecord(id){const sheet =getDb();const data = sheet.getDataRange().getValues();const headers = data[0];const idCol = headers.indexOf('ID');for(let i =1; i < data.length; i++){if(data[i][idCol]=== id){ sheet.deleteRow(i +1);Logger.log('Deleted record: '+ id);returntrue;}}Logger.log('Record not found: '+ id);returnfalse;}
QUERY — filter records
functionqueryRecords(filterFn){returngetAllRecords().filter(filterFn);}// Usage: find all active users// const active = queryRecords(r => r.Status === 'Active');
Expose as a Web App API
functiondoGet(e){const action = e.parameter.action;if(action ==='getAll'){const records =getAllRecords();returnContentService.createTextOutput(JSON.stringify(records)).setMimeType(ContentService.MimeType.JSON);}returnContentService.createTextOutput(JSON.stringify({error:'Unknown action'})).setMimeType(ContentService.MimeType.JSON);}
Tips
sheet.appendRow() is simple but slow for bulk inserts. Use sheet.getRange(...).setValues() for batch writes.
Google Sheets has a limit of 10 million cells. For high-volume data, consider Firestore or a real database.
Avoid frequent reads/writes in loops — cache the full sheet data in a variable and operate on that array instead.
Use LockService if multiple users might write simultaneously to prevent race conditions.