Search code examples
databasesurrealdb

SurrealDB - How to change table name in SurrealQL?


I have a table called "Computers".

I want to change it to "computer".

There must be no data loss while changing the name.

How can I change it? How to change table name in SurrealQL?


Solution

  • There isn't a direct method to change the table name without data loss in SurrealQL. However, you can accomplish your objective (change the table name from "Computers" to "computer") using the following technique:

    1. Create a new table named "computer" with the same structure.
    2. Migrate data using INSERT INTO computer SELECT * FROM Computers;.
    3. Verify data consistency.
    4. Update any references to the old table name.
    5. Drop the old "Computers" table.

    Remember to back up your data before making changes.