# Records: CRUD Operations

> Part of the NocoDB documentation (Workflows > Scripts > Examples > Generic). Index of all pages: https://nocodb.com/llms.txt. Any docs page is available as Markdown by adding `.md` to its URL.

URL: https://nocodb.com/docs/workflows/scripts/examples/demo/records-CRUD
Last updated: 2026-08-17

This script demonstrates how to create, read, update, and delete records in a NocoDB table.

This script demonstrates how to perform basic CRUD (Create, Read, Update, Delete) operations on records in a NocoDB table. It includes creating a table if it doesn't exist, adding fields, creating demo records, updating those records, and finally deleting them.

More information about the NocoDB API can be found in the [NocoDB data API documentation](https://nocodb.com/apis/v3/data).

```javascript
const tableName = 'Contacts';
const fields = [
  { name: 'Name', type: 'SingleLineText' },
  { name: 'Email', type: 'Email' },
  {
    name: 'Status',
    type: 'SingleSelect',
    options: {
      choices: [
        { title: 'Active' },
        { title: 'Pending' },
        { title: 'Inactive' }
      ]
    }
  }
];

// Step 1: Create table if it doesn’t exist
let table = base.getTable(tableName);
if (!table) {
  table = await base.createTableAsync(tableName, []);
}

// Step 2: Create any missing fields
const existingFieldNames = table.fields.map(f => f.name);
for (let field of fields) {
  if (!existingFieldNames.includes(field.name)) {
    await table.createFieldAsync({ name: field.name, type: field.type, options: field.options });
  }
}

// Step 3: Create demo records
const recordsToCreate = [
  { fields: {
    'Name': 'John Doe',
    'Email': 'john.doe@example.com',
    'Status': 'Active'
  }},
  { fields: {
    'Name': 'Jane Smith',
    'Email': 'jane.smith@example.com',
    'Status': 'Pending'
  }},
  { fields: {
    'Name': 'Bob Johnson',
    'Email': 'bob.johnson@example.com',
    'Status': 'Active'
  }}
];

const createdRecords = await table.createRecordsAsync(recordsToCreate);
output.text(`✅ Created ${createdRecords.length} new records.`);

// Step 4: Read the created records
const records = await table.selectRecordsAsync();
const created = records.records.filter(r => createdRecords.includes(r.id));

const displayBeforeUpdate = created.map(r => ({
  Name: r.getCellValue('Name'),
  Email: r.getCellValue('Email'),
  Status: r.getCellValue('Status')
}));

output.text('📖 Records after creation:');
output.table(displayBeforeUpdate);

// Step 5: Update status of each record to "Inactive"
const updates = created.map(r => ({
  id: r.id,
  fields: {
    Status: 'Inactive'
  }
}));

await table.updateRecordsAsync(updates);

const updated = await table.selectRecordsAsync();
const updatedDisplay = updated.records.filter(r => createdRecords.includes(r.id)).map(r => ({
  Name: r.getCellValue('Name'),
  Email: r.getCellValue('Email'),
  Status: r.getCellValue('Status')
}));

output.text('🔁 Records after status update:');
output.table(updatedDisplay);

// Step 6: Delete the created records
await table.deleteRecordsAsync(createdRecords);
output.text(`🗑️ Deleted ${createdRecords.length} records.`);

```

---

## Related pages

- [Table Operations](https://nocodb.com/docs/workflows/scripts/examples/demo/table-operations.md): Demonstrates how to check for table existence, create a table, and list all tables in the base.
- [Fields: Text-Based](https://nocodb.com/docs/workflows/scripts/examples/demo/field-text-based.md): Learn how to create and manage text-based fields in NocoDB.
- [Fields: Numerical](https://nocodb.com/docs/workflows/scripts/examples/demo/field-number-based.md): Learn how to create numerical fields for storing quantities, percentages, currency, and more.
- [Fields: Date & Time](https://nocodb.com/docs/workflows/scripts/examples/demo/field-date-time.md): Create fields to capture dates, times, and durations.
- [Fields: Select](https://nocodb.com/docs/workflows/scripts/examples/demo/field-select-based.md): Create single select and multi select fields for categorizing data.
- [Fields: System](https://nocodb.com/docs/workflows/scripts/examples/demo/field-system.md): Capture automatic audit information with system fields in NocoDB.
- [Fields: User & Collaborator](https://nocodb.com/docs/workflows/scripts/examples/demo/field-user.md): Assign or reference users directly within records.
- [Fields: Virtual & Formula](https://nocodb.com/docs/workflows/scripts/examples/demo/field-virtual.md): Add calculated or derivative data with virtual fields in NocoDB.
