SqlOtter
← All documentationManage objects

Manage objects

Manage indexes and constraints

Inspect keys and indexes, create an index on an existing table, and review staged foreign-key changes with the correct engine and cancellation boundaries.

What this feature does

Index lists ordinary and unique indexes, including some constraint-backed entries. Relations stages supported foreign-key changes. The relational Index buttons execute independently; primary/unique constraints and CHECK need their own definition and enforcement checks.

When to use it

Use this to inspect access paths, add a supported index, prepare a single-column foreign key, or check whether declared relationships are actually enforced.

Index editor for test.test_docs showing PRIMARY / BTREE / id / Yes and the complete Add Index form for idx_review_note, with review_note checked and Unique Index unchecked.
Owner capture of test.test_docs before Add Index / OK. The existing row reads PRIMARY, BTREE, id, Unique = Yes. The form prepares idx_review_note on review_note with BTREE and Unique Index unchecked; id is unchecked. Parent Save Changes is disabled. This is configuration before submission; index creation and fresh metadata are not shown.

Before you start

Use an existing disposable demo table, confirm connection/database/Schema and DDL permissions, and keep the original definitions and a recovery copy. A foreign-key example also needs a compatible referenced key and valid existing data. Read the action boundaries before pressing OK, Delete Index or Execute.

Default shortcuts

Main-window bindings are configurable. Dialog keys depend on focus; use explicit Index/Relations buttons for their actions.

Default shortcuts
ActionWindows / LinuxmacOSFocus and effect
Show Structure (read-only)F6F6Main workspace, current table context. Configurable; opens metadata rather than the Index/Relations editing dialog.
Edit table structureAlt+Enter⌥+EnterMain workspace; select the intended object-tree table first. Configurable default.
Edit from the focused object treeCtrl+Enter / Alt+Enter⌘+Enter / ⌥+EnterFixed tree handler. The tree-filter input has its own opening behavior.
Add IndexNo dedicated defaultNo dedicated defaultClick Index → Add Index, review the form, then OK immediately submits the relational index.
Refresh indexes and available fieldsNo dedicated defaultNo dedicated defaultClick Index → Refresh. Reloads server metadata; it does not undo changes.
Delete IndexNo dedicated defaultNo dedicated defaultSelect its row and click Delete Index. Direct drop attempt with no parent preview or separate confirmation.
Add a relationNo dedicated defaultNo dedicated defaultClick Relations → Add, fill Add Foreign Key, then Add stages the definition.
Delete a relationNo dedicated defaultNo dedicated defaultSelect the relation and click Delete. Stages an existing drop or removes a pending addition.
Refresh relationsNo dedicated defaultNo dedicated defaultUse Relations → Refresh or its row context menu. Pending additions/deletions are not cleared.
Focus structure searchCtrl+F⌘+FStructure dialog; searches controls/values within the current top-level and nested tab.
Start / next search matchEnterEnterFocused structure-search input; starts or advances search without executing DDL. Use the previous button to go back.
Review staged changesCtrl+Enter / Ctrl+Return⌘+Enter / ⌘+ReturnParent structure dialog, enabled Save Changes. Prepares review; does not defer already-applied relational Index actions.
Execute the previewCtrl+Enter / Ctrl+Return⌘+Enter / ⌘+ReturnSQL Preview text editor only. Invokes Execute; do not blindly repeat the parent review chord.
Activate a default buttonEnterEnterFocus-dependent. Parent Save Changes is the enabled default; Add Foreign Key defaults to Add; SQL Preview defaults to Cancel when its text editor does not consume Enter. Read the active button.
Cancel / close the current layerEscEscActive search or a cell/popup can consume it first. Parent Cancel may open Unsaved Changes; no rollback of executed actions.
Reset Auto IncrementNo dedicated defaultNo dedicated defaultIndex button opens a separate counter-value input. This changes a counter, not an index draft reset or undo.
  • Settings → Shortcuts shows configurable bindings; customized keys take precedence. Fixed dialog keys and mouse gestures may be managed by their own controls.
  • On macOS, ⌘ means Command and ⌥ means Option. Function keys may require Fn. Delete means forward delete (often Fn+⌫ on a compact Mac keyboard); use the menu when Insert is unavailable.
  • Ctrl+N, Ctrl++ / Ctrl+=, Delete and Ctrl+- in the relational parent are field actions, not universal index/relation add/delete shortcuts. Use labeled tab buttons; there is no Ctrl+S structure-save default established here.
  • Keyboard/focus behavior is source-reviewed; physical-keyboard acceptance is still pending.

How to use it

  1. Select the intended existing table in the object tree and open Edit table structure; check the title and wait for metadata.
  2. Inspect Index → Name / Type / Fields / Unique and Relations → local/reference endpoints and actions. Check full server DDL for properties missing from the lists.
  3. For a relational index, review Add Index before OK or the selected row before Delete Index: both immediately attempt database operations without the parent SQL Preview.
  4. For a supported single-column foreign key, use Relations → Add, choose endpoints/name/actions, then return to the pending list. Delete stages removal; directly editing list text is not a saved-definition workflow.
  5. Use Save Changes directly for staged changes, review the full editable SQL Preview and choose Cancel or deliberate Execute. Stop if required DDL is absent or only comments are generated.
  6. Read the outcome, reopen the same target and compare actual metadata/DDL. Verify enforcement separately, and reload actual state before retrying a failed batch.

Choose an existing table and the right editing surface

Use an existing disposable table for these examples. Show Structure is a read-only view; Edit table structure opens the Index and Relations tabs where offered.

  1. Check the workspace connection, database and Schema selector, then select the intended table in the object tree. The editing action uses this selected tree item, which can differ from an already open data tab.
  2. Use Table → Show Structure (F6) for read-only field metadata. To change definitions, choose Table → Edit table structure or the matching tree context-menu action; its configurable default is Alt+Enter / ⌥+Enter.
  3. Check the editor title and wait for metadata loading to finish. Open Index for the index list or Relations for foreign-key definitions. Availability depends on the engine and current table.
  4. Create and save a new table before following the existing-table index/relationship examples. These selectors read existing server columns; an unsaved Fields row is not automatically available to them.
  • With the object tree itself focused, Ctrl+Enter / ⌘+Enter also opens structure editing. The tree-filter input, structure dialog and SQL Preview use that chord for different actions.

Distinguish indexes, primary keys, unique constraints and checks

An ordinary index, a unique index and a constraint are different objects even when the database uses an index to implement a constraint.

  1. Use an ordinary index to support access paths. It does not forbid duplicate values, and its existence does not guarantee that the optimizer will use it or that every query will be faster.
  2. Unique Index requests a unique index over the selected fields. It is not a general-purpose UNIQUE CONSTRAINT editor. NULL handling, collation, filtered/expression definitions and eligible referenced keys follow the engine rules.
  3. A primary key identifies rows and can contain several ordered columns. Fields uses PRI, UNI and MUL key markers; review the resulting SQL rather than treating a marker as a completed constraint change. For a new relational table, check the actual PRIMARY KEY clause before Execute.
  4. For an existing table, changing its Fields Key marker is not a reliable general add/drop-constraint workflow. If SQL Preview lacks the required PRIMARY KEY or UNIQUE change, cancel and prepare the correct engine-specific DDL separately.
  5. A foreign key links local columns to a referenced key and may enforce referential integrity. Relations handles these links. CHECK validates a condition on a row; this editor has no dedicated CHECK tab or Add Check action. Inspect CHECK definitions in server DDL/metadata and use a separately reviewed SQL workflow where supported.
  • An index-backed constraint may appear in the index list. Unique = Yes alone does not identify whether it is a primary key, a standalone unique index, or the backing object of a constraint.
  • ER diagram lines, foreign-key record previews and migration metadata describe relationships; none independently proves that the current server enforces a definition.

Read the Index list and its limits

Index shows the server metadata as Name, Type, Fields and Unique. Its cells are read-only.

  1. Open Index and read Name, Type, the ordered Fields list and Unique together. A multi-column index is displayed as one row with comma-separated fields.
  2. Use Refresh to reload both existing table fields and indexes. After another session changes the table, reload before selecting fields or planning a new index.
  3. Inspect the server definition when the object has predicates, included columns, expressions, sort directions, prefix lengths, constraint ownership or enabled/validated state. The four displayed columns do not expose all those properties.
  4. Use the explicit Add Index or Delete Index button for the supported action. This list has no inline index rename/change workflow; replacing an index requires a deliberate engine-specific plan and dependency checks.
  • An empty list can also follow a metadata-loading failure or a permissions problem. It is not proof that the table has no indexes or constraints.
  • In the supplied overview, PRIMARY has Type BTREE, Fields id and Unique Yes. This describes the visible existing entry; it is separate from the pending idx_review_note form.

Add an index: OK submits it immediately

The relational Add Index dialog executes independently of the parent Save Changes flow. Use a disposable existing table and review the form before OK.

Complete Add Index dialog: idx_review_note, BTREE, Unique Index unchecked, review_note checked, id unchecked, Cancel and OK.
Exact dialog crop from the test.test_docs original: select review_note first, then check the final name idx_review_note, BTREE and the unchecked Unique Index option. Cancel abandons the form. Relational OK attempts creation immediately; no parent SQL Preview or creation result is shown here. Historical screenshot; UI icons have been updated.
  1. In Index, choose Add Index. The owner capture uses the existing test.test_docs table: check review_note, leave id unchecked and prepare the name idx_review_note. Use your own disposable target and a name that is not already in use.
  2. Check the fields first, then finish Index Name. Changing a field checkbox regenerates the suggested name and can overwrite a custom name. At least one field and a nonempty name are required.
  3. Read the selected field order carefully. This dialog collects checked fields in the displayed list order, not the order in which you ticked them; it has no separate reorder, expression, prefix or included-column controls.
  4. For the captured ordinary-index configuration, leave Unique Index unchecked and check BTREE. Confirm that the actual engine/table supports your choice; the standalone Index original does not independently identify its engine. A visible HASH or FULLTEXT option is not proof of support.
  5. Choose Cancel to leave the form without submitting. Choose OK only when ready to issue CREATE INDEX immediately; this path does not open the parent SQL Preview or wait for Save Changes.
  6. Read the success/error feedback, then use Refresh and reopen the same target to inspect the actual index. If Unique Index is checked, a duplicate-data precheck is attempted; it does not fully validate engine NULL/collation rules or concurrent changes.
  • Parent Cancel or Discard cannot undo an index already created through this dialog. A disabled parent Save Changes button does not mean that no database action occurred.
  • SQL Server, Oracle and SQLite index builders do not apply this generic type selection as an access-method instruction. Use a separately reviewed SQL workflow for definitions the form cannot express.
  • The overview shows the pre-existing PRIMARY / BTREE / id / Yes row, while the form is still before OK. Neither that row nor disabled parent Save Changes proves that idx_review_note was created.

Remove an index and check dependent constraints

Delete Index directly attempts a database operation. The relational index handler has no separate SQL Preview or confirmation step.

  1. Before deletion, record the full server definition and identify any primary/unique constraint or foreign key that depends on it. Select the exact index row and check the target table again.
  2. Click Delete Index only when ready to submit the drop. It is not a staged deletion for a later Save Changes; do not expect another review dialog.
  3. A recognized primary-key entry can generate DROP PRIMARY KEY or DROP CONSTRAINT, rather than an ordinary DROP INDEX. Deleting a constraint-owned unique index can be refused by the server; it is not a universal constraint-removal command.
  4. Read feedback and refresh/reopen the actual target. If the drop fails because of dependencies or permissions, inspect the server state and plan the required change explicitly. Parent Cancel does not restore an applied deletion.
  • SQLite primary keys cannot be dropped as standalone indexes, and engine-owned autoindexes can have additional restrictions.
  • Reset Auto Increment is a separate counter-changing operation with its own input. It does not reset the index list, clear a draft or undo index changes.

Stage a single-column foreign key in Relations

Relations → Add opens Add Foreign Key. Its Add button returns a pending definition to the parent editor; it does not execute the constraint.

Add Foreign Key with Local Column id, reference Database test2, Table admin_menus, Foreign column parent_id, name test_docs_id_fk_admin_menus_parent_id, both actions RESTRICT and Cancel / Add.
The full original identifies the child as test.test_docs. This exact form crop selects id → test2.admin_menus.parent_id, name test_docs_id_fk_admin_menus_parent_id, and RESTRICT for both On Update and On Delete. It stops before Add. The selections do not establish a suitable referenced key, compatible types, valid data or successful enforcement. Historical screenshot; UI icons have been updated.
  1. Use existing disposable tables and check key eligibility first. The supplied MySQL-context form selects test.test_docs.id → test2.admin_menus.parent_id. Before applying such a definition, verify compatible types, a suitable referenced key, valid existing child values and both storage engines; the images do not establish those prerequisites.
  2. Open Relations → Add. Choose Local Column, then the reference Database/Schema, Table and Foreign column. Check the reference namespace carefully: labels such as Database or Ref DB can represent a schema in a schema-based engine; verify the generated qualified names.
  3. After selecting both endpoints, check Name. The capture shows test_docs_id_fk_admin_menus_parent_id. Endpoint changes regenerate the suggested name, so enter a custom name last. Type mismatch feedback is advisory; it is not a complete server-side eligibility or data check.
  4. Choose On Update and On Delete explicitly; both are RESTRICT in the capture. The ordinary form also offers CASCADE, SET NULL and NO ACTION. A visible option is not accepted by every engine. SET NULL needs nullable local columns; CASCADE can affect dependent rows.
  5. Choose Cancel to abandon this form, or Add to return the definition to Relations. Inspect the pending Name, Column, Ref DB/Ref Schema, Ref Table, Ref Column and Action values before saving the parent dialog.
  • This form selects one local column and one referenced column. It is not a composite-foreign-key editor. A composite relation may be displayed through per-column metadata; do not recreate it as unrelated single-column keys.
  • The form and companion preview show the same cross-database endpoints and constraint name. This illustrates configuration and review, not a verified database design or an executed relationship. Confirm the actual qualified names and eligible keys for your own target.

Review, remove or replace pending relationships

Relations tracks additions and deletions for the parent save. Editing visible table text does not provide a supported relation-definition update.

  1. Read all six relation columns and inspect the server definition for composite keys, validation/enforcement state or other properties not shown in the list.
  2. To abandon a newly added relation, select its pending row and click Delete. This removes the pending addition without issuing a DROP for an existing constraint.
  3. To remove an existing relation, select its exact name and click Delete. The removal is staged; SQL Preview must later contain the intended constraint drop before you Execute.
  4. To change a relation, plan deletion of the old definition and addition of its replacement. Review both commands together, including endpoints and actions. Do not depend on typing directly into list cells to update the saved definition.
  5. Refresh, including the row context-menu Refresh, rereads existing server relations but does not clear the pending addition/deletion lists. A removed server row can reappear while its deletion is still pending. To discard the draft reliably, close with Discard and reopen the same table.
  • There is no dedicated Edit relation action or universal relation Delete-key default in this reviewed surface. Use its labeled buttons and inspect SQL Preview rather than inferring an action from a selected cell.

Review staged changes, then execute deliberately

Use Save Changes directly for staged Relations or field/key changes. This review path is separate from the immediate relational Index buttons.

Complete SQL Preview for ALTER TABLE test.test_docs ADD CONSTRAINT test_docs_id_fk_admin_menus_parent_id FOREIGN KEY (id) REFERENCES test2.admin_menus (parent_id), both actions RESTRICT, with Document formatted and Cancel / Execute.
The displayed preview matches the form: ALTER TABLE targets test.test_docs, adds test_docs_id_fk_admin_menus_parent_id and references test2.admin_menus.parent_id from id, with ON UPDATE RESTRICT and ON DELETE RESTRICT. The complete dialog retains Document formatted and Cancel / Execute. Formatting is not execution feedback; server acceptance, fresh metadata and enforcement remain unconfirmed. Historical screenshot; UI icons have been updated.
  1. Finish active cell edits, check pending additions/deletions and the target, then click Save Changes in the open editor. Resolve field validation or type-exchange prompts if other field changes are also present.
  2. Read any Database Limitation warning and the complete SQL Preview. In the supplied preview, verify ALTER TABLE test.test_docs, ADD CONSTRAINT test_docs_id_fk_admin_menus_parent_id, FOREIGN KEY (id), REFERENCES test2.admin_menus (parent_id), ON UPDATE RESTRICT and ON DELETE RESTRICT. Preserve the distinct test / test2 databases; reject unrelated field changes, drops or a wrong namespace.
  3. Check the actual generated actions: MySQL and PostgreSQL builders can translate NO ACTION to RESTRICT. For SQLite, the current Relations add/drop path only produces comments saying the table must be rebuilt; those comments do not implement a foreign-key change. Cancel that preview and plan a proper rebuild separately.
  4. The SQL text is editable. Cancel from this directly opened preview returns without submitting it; Execute accepts the displayed text, including any edits. Ctrl+Enter / ⌘+Enter in the preview text editor invokes Execute, whereas the same chord in the parent invokes Save Changes.
  5. After Execute, wait for completion and read success or per-statement error results. Reopen the same target and compare actual index/constraint metadata and the complete DDL. Check existing data and enforcement separately; a visible relation row is insufficient.
  6. If a batch fails, reload the actual state before retrying. Earlier commands can have taken effect, and Cancel, a closed editor or a failed batch is not a rollback guarantee.
  • A save with no executable change can close without a meaningful preview. Formatting feedback such as Document formatted is not execution success.
  • Three authentic originals now illustrate the Index form, relation form and matching pre-Execute preview. They do not establish index creation, constraint execution, a fresh metadata read, enforcement, physical-keyboard acceptance or a verified release build.

Cancel the right layer and preserve a draft when needed

A nested form, SQL Preview and the parent editor have different cancellation boundaries.

  1. Cancel in Add Index abandons the form before its immediate OK submission. Cancel in Add Foreign Key abandons that form before a pending relation is added.
  2. Cancel in SQL Preview opened directly from Save Changes does not submit that preview. Review the retained parent draft before continuing or discarding it.
  3. Closing the parent with staged changes opens Unsaved Changes. Cancel keeps editing; Discard abandons unapplied changes. Already-applied relational index actions remain in the database.
  4. Use direct Save Changes when you want a cancelable review. The close prompt also offers Save, but that close path can finish closing after preview cancellation or while execution is pending; do not rely on it to retain the draft or prove completion.
  5. Esc is focus-dependent: an active search first clears, a field/completion editor may handle it locally, and a later parent Cancel can open Unsaved Changes. Use labeled Cancel/Discard choices when the intended layer is unclear.
  • Closing is not undo. If any index, constraint or other tab operation has already executed, restore the prior definition only through a separately reviewed database change.

Check action support and actual enforcement for the engine

A capability label or visible control describes an available surface, not acceptance of every definition or proof of enforcement.

  1. MySQL: the Relations support check requires InnoDB for the current table and warns about an incompatible referenced table engine. Check the referenced key, column definitions, current data and foreign-key checking state separately. Related MySQL-compatible products still need their own server/version acceptance.
  2. PostgreSQL, SQL Server and Oracle: verify the actual schema-qualified target, constraint ownership and supported actions. Generic type choices and referential actions are not a complete engine-specific contract; SQL Server and Oracle ignore the generic index-type input, and constraint-backed indexes can require a different drop path.
  3. SQLite: structure editing and foreign keys are partial. The reader attempts to enable PRAGMA foreign_keys on its connection; that does not establish the setting for every other connection. The current Relations add/drop generates comments only and does not implement the required table rebuild. Primary keys cannot be dropped as standalone indexes.
  4. Snowflake: table-structure editing is marked unsupported in the capability matrix. The implementation hides Index, rejects ordinary index DDL and describes foreign keys on standard tables as informational, not enforced. Internal relation metadata or an old indexes support label does not establish a supported edit flow; do not extend this standard-table statement to unreviewed table types.
  5. MongoDB: use its separate Schema / Index / Options editor. Index additions and confirmed deletions are staged here, unlike the immediate relational Index path. Review generated createIndex/dropIndex collection commands through the parent save. Unique, Sparse, key directions/types and TTL have document-engine semantics; TTL can expire documents. Relational foreign keys and CHECK are not this workflow.
  6. Redis: relational structure, indexes and foreign keys are not applicable to this documented editor. Native key operations are separate. For any engine, check current metadata and relevant server enforcement/validation state before relying on integrity; archived declarations alone do not establish target enforcement.
  • The reviewed support matrix, current source and named-release/database workflow evidence are separate. F14 remains a current-development draft. Its initial three-image configuration/review set is integrated; execution, enforcement, complete workflows and release acceptance remain pending.

What to expect

A supported command can change the target only when accepted by the server. Confirm the resulting object, ordered columns, reference actions and enforcement/validation state through fresh metadata and the relevant server checks.

Limits and safety

  • Relational Index Add/OK and Delete Index execute independently; parent Cancel/Discard cannot undo them. Relations additions/deletions are staged for the parent save. MongoDB indexes follow a separate staged path.
  • The index form does not express every index property, and the relation form is single-column. There is no dedicated CHECK editor or universal primary/unique-constraint manager here.
  • SQLite Relations add/drop currently produces rebuild guidance comments, not an implemented foreign-key change. Snowflake structure editing is unsupported and standard-table foreign keys are informational; Redis relational concepts are not applicable.
  • Visible choices, a metadata row, diagram link, archived declaration, formatting message or closed dialog do not prove execution success, enforcement, atomic rollback or release acceptance.

If something goes wrong

  • No fields or indexes? Wait for loading, use Index Refresh and check the target, metadata permissions and load errors. Newly staged Fields rows are not existing server columns.
  • Unique index refused? Check duplicate values, NULL/collation semantics and supported type/definition. A precheck is not a substitute for the server rule.
  • Foreign-key creation refused? Check both endpoints and namespace, referenced key eligibility, compatible types, local nullability, existing values, storage engine, supported referential actions and privileges.
  • A relationship still appears after Refresh? Refresh reloads server rows but does not clear pending additions/deletions. Use parent Discard and reopen to abandon the staged draft.
  • The preview is comments only or lacks the intended constraint clause? Cancel. A success/close signal cannot turn missing DDL into a created constraint; prepare the required engine-specific operation separately.
  • An index drop fails or a batch partly applies? Check constraint ownership/dependencies and fresh server state before retrying. Do not use parent Cancel as rollback.