Spanish Total.js
English
Documentation For AI agents
Contents

Change the structure of a table

See what a table is made of, and change its columns, indexes, relations and rules. Each change waits until you read its SQL and run it.

.md GitHub
On this page

Read the structure

Open a table and press Structure. It begins with the table in words: what names each row, which tables it points to, what a new row has to bring. Then come its columns, indexes, relations and rules, and the SQL that makes it.

Press the name of another table in Relations to open it.

Prepare your changes

ToPress
Add a columnColumn
Change the name, the type, the default or the NULL of a columnThe pencil of its row
Add an indexIndex. Its columns go in the order in which you mark them
Point to another tableRelation. Choose the columns, the other table, and what happens when the row pointed to goes away
Add a condition that every row must passRule. Write it as SQL: price >= 0
Drop any of themThe bin of its row

Each change goes to a list above the columns. The cross of a change takes it out.

Save them

  1. Press Review and save.
  2. Read the statements. They run in that order.
  3. Press Run.

In PostgreSQL, SQL Server and SQLite, if one fails, none is kept. MySQL and MariaDB keep each change of structure as soon as it runs, so those before the one that fails stay.

The list stays when you go to Data and back. If you close the tab before you run it, TotalSQL asks. When changes of rows wait too, it asks before you change the structure, because the rows are read again after it: save them first.

Dropping a column loses its values for good.

What happens when the row goes away

ChoiceWhat the database does
Refuse to drop it (the usual)The row cannot be dropped while others point to it
Drop these rows with itDrops the rows that point to it
Empty the column herePuts NULL in the rows that point to it
Refuse, at onceRefuses without waiting for the end of the transaction, in the databases that tell them apart
Put the default herePuts the default of the column

What needs a query

  • The key of the table, and its columns, cannot be dropped here.
  • The type of a column that the database fills.
  • The comments of columns, which are only shown.
  • The definition of a view.
  • In SQLite, the type, the default and the NULL of a column, and the relations and the rules. SQLite needs the table to be made again for that. A new column that cannot be NULL needs a default.
Made in Europe