ROOM64 / KNOWLEDGE / NOCODB

Table Operations

Demonstrates how to check for table existence, create a table, and list all tables in the base.

อ่านต้นฉบับที่ NocoDB Official Docs ↗
เอกสารอ้างอิงภาษาอังกฤษเนื้อหาจากเอกสาร NocoDB คงรายละเอียดและโค้ดตามต้นฉบับ · ต้นฉบับอัปเดต 2026-08-17 ชื่อเมนูและฟีเจอร์ที่ใช้ได้ขึ้นอยู่กับเวอร์ชันและรุ่นที่ทีมใช้งาน

Workflows · ระบบอัตโนมัติและ Scripts · Table Operations

← Generic Examples

สารบัญในหน้านี้

Demonstrates how to check for table existence, create a table, and list all tables in the base.

This script demonstrates how to check for the existence of a table, create a new table if it doesn't exist, and list all tables in the current base in NocoDB.

For detailed descriptions of each table operation and associated configuration options, refer to the NocoDB meta API documentation .

// NocoDB Script: Table Operations
// Demonstrates how to check for table existence, create a table, and list all tables in the base.

const tableName = 'Inventory';

// ------------------------------
// Check if table exists
// ------------------------------
let table = base.getTable(tableName);

if (!table) {
  output.text(`🔍 Table "${tableName}" not found. Creating it now...`);

  try {
    // ------------------------------
    // CREATE TABLE
    // ------------------------------
    table = await base.createTableAsync(tableName, [
      { name: 'Item ID', type: "SingleLineText" },
      { name: 'Item Name', type: "SingleLineText" },
      { name: 'Quantity', type: "Number" },
      {
        name: 'Category',
        type: "SingleSelect",
        options: {
          choices: [
            { title: 'Electronics', color: '#FFC107' },
            { title: 'Clothing', color: '#007BFF' },
            { title: 'Home & Garden', color: '#28A745' },
            { title: 'Books', color: '#6F42C1' },
            { title: 'Sports', color: '#DC3545' }
          ]
        }
      }
    ]);

    output.text(`✅ Table "${tableName}" created successfully!`);
  } catch (error) {
    output.text(`❌ Error creating table: ${error.message}`);
  }
} else {
  output.text(`ℹ️ Table "${tableName}" already exists.`);
}

// ------------------------------
// READ: List all tables in base
// ------------------------------
output.markdown('### 📋 Tables in this base');

const tableSummary = base.tables.map(t => ({
  'Table Name': t.name,
  'Table ID': t.id,
  'Fields': t.fields.length,
  'Views': t.views.length
}));

output.table(tableSummary);

เนื้อหาเอกสารอ้างอิงและภาพประกอบมาจาก NocoDB Official Docs · บทความแนะนำภาษาไทยเรียบเรียงโดย Room64 · เว็บไซต์นี้เป็นคู่มือประกอบการใช้งานโดย Room64 · เอกสารทางการ ↗

มีงานที่อยากให้ Software, AI หรือ Automation ช่วยอยู่ไหม?

เล่า workflow หรือปัญหาที่ทีมกำลังเจอ เราช่วยดูได้ว่าควรใช้ระบบสำเร็จรูป เชื่อมเครื่องมือเดิม หรือพัฒนาเพิ่มเฉพาะส่วนไหน

คุยกับเราทาง LINEhello@room64.net