# Execute SQL and manage SQL metadata

Execute SQL, track execution status and results, and query or delete related database, table, and view metadata. This page does not manage saved SQL or data dashboards; see [Manage SQL workbooks and data dashboards](sql-workbooks-dashboards.md) for those objects.

## Prerequisites

Prepare credentials that can access the target workspace and database information for SQL to execute or objects to query. For service endpoints, authentication, and general request formats, see [Prepare to call an API](../../api-call-basics.md).

Before querying or deleting metadata, identify the target object through database and table queries.

## Call sequence

1. To understand existing objects, query databases, tables in a database, table information, table fields, or table-creation statements.
2. After submitting SQL execution, retain the execution ID and query execution status.
3. Query or download results after they become available. Cancel an execution when it no longer needs to continue.
4. Before deleting a database, table, or view, confirm the object and impact scope.

## API operations

### Execute SQL and obtain results

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| Execute SQL | [Execute SQL](../../../../reference/api/ai-studio/data-processing/sql-execution/execute-sql.md) | Submit SQL execution. |
| Query execution status | [Get execution status](../../../../reference/api/ai-studio/data-processing/sql-execution/get-execution-status.md) | Check current execution status after submission. |
| Query execution results | [Get execution result](../../../../reference/api/ai-studio/data-processing/sql-execution/get-execution-result.md) | Read results after they become available. |
| Download execution results | [Download execution result](../../../../reference/api/ai-studio/data-processing/sql-execution/download-execution-result.md) | Obtain an execution-result file. |
| Cancel an execution | [Cancel execution](../../../../reference/api/ai-studio/data-processing/sql-execution/cancel-execution.md) | The target execution no longer needs to continue. |

### Query SQL metadata

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| Query databases | [List databases](../../../../reference/api/ai-studio/data-processing/sql-metadata/list-databases.md) | Select a target database. |
| Query tables in a database | [List tables and views in a database](../../../../reference/api/ai-studio/data-processing/sql-metadata/list-database-tables.md) | Locate a table in a selected database. |
| Query table information | [Get table information](../../../../reference/api/ai-studio/data-processing/sql-metadata/get-table-info.md) | Inspect current information for one table. |
| View table fields | [List table columns](../../../../reference/api/ai-studio/data-processing/sql-metadata/list-table-columns.md) | View table fields. |
| Query a creation statement | [Get a table or view DDL](../../../../reference/api/ai-studio/data-processing/sql-metadata/get-table-ddl.md) | View a table-definition statement. |

### Delete metadata objects

| What you need to do | API operation | Use it when |
| --- | --- | --- |
| Delete a database | [Delete a database](../../../../reference/api/ai-studio/data-processing/sql-metadata/delete-database.md) | You confirmed that the database is no longer needed. |
| Delete a table | [Delete a table](../../../../reference/api/ai-studio/data-processing/sql-metadata/delete-table.md) | You confirmed that the table is no longer needed. |
| Delete a view | [Delete a view](../../../../reference/api/ai-studio/data-processing/sql-metadata/delete-view.md) | You confirmed that the view is no longer needed. |

## Confirm the result

After submitting SQL, first use [Get execution status](../../../../reference/api/ai-studio/data-processing/sql-execution/get-execution-status.md) to confirm progress, then query or download results. Before and after deleting metadata objects, use the relevant database, table, and table-information queries to confirm the target object.

## Limitations and notes

- Submitting SQL does not mean results are available. Use execution status and result queries to confirm.
- Before deleting a database, table, or view, confirm impact and conditions on the corresponding action page.

## Next steps

- [Manage SQL workbooks and data dashboards](sql-workbooks-dashboards.md)
