UNDROP TABLE

Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime 12.2 LTS e versioni successive

Il UNDROP comando risolve il problema delle tabelle gestite o esterne che si trovano nel catalogo Unity che vengono accidentalmente eliminate o eliminate. Per impostazione predefinita, questo comando rimuove (recupera) la tabella eliminata più di recente di proprietà dell'utente del nome di tabella specificato. Lo schema padre e il catalogo devono esistere. Questa funzionalità supporta il ripristino delle tabelle eliminate entro un periodo di conservazione di 7 giorni.

Se sono presenti più tabelle eliminate con lo stesso nome, è possibile usare SHOW TABLES DROPPED per identificare l'ID tabella e usare UNDROP TABLE WITH ID per recuperare una tabella specifica.

Se è presente una tabella con lo stesso nome della tabella da ripristinare, usare il comando ALTER TABLE RENAME TO per modificare il nome della tabella esistente.

I metadati della tabella, ad esempio privilegi di tabella, specifiche di colonna e proprietà, verranno recuperati. I vincoli di chiave primaria ed esterna non vengono recuperati dal UNDROP comando . Ricrearli manualmente usando ALTER TABLE ADD CONSTRAINT dopo il ripristino della tabella.

Sintassi

UNDROP TABLE { table_name | WITH ID table_id }

Parametro

  • table_name

    Nome della tabella da ripristinare. Il nome non deve includere una specifica temporale. Se la tabella non è stata trovata, Azure Databricks genera un errore.

  • table_id

    Valore STRING letterale sotto forma di UUID della tabella come visualizzato da SHOW TABLES DROPPED.

Autorizzazioni

UNDROP TABLE richiede una delle autorizzazioni di base seguenti:

  • Un utente è il proprietario della tabella, ha CREATE TABLE e USE SCHEMA sullo schema e USE CATALOG nel catalogo.
  • Un utente è il proprietario dello schema e ha USE CATALOG nel catalogo.
  • Un utente è il proprietario del catalogo.
  • Un utente è il proprietario del metastore.

Se un utente sta ripristinando un tipo diverso di tabella, si applicano autorizzazioni aggiuntive. Ad esempio, per rimuovere una tabella esterna, è necessario disporre CREATE EXTERNAL TABLE anche della credenziale di archiviazione o del percorso esterno, che deve esistere.

Dopo aver eseguito questo comando, per impostazione predefinita la proprietà è il proprietario della tabella precedente. Se necessario, la proprietà può essere modificata usando il ALTER TABLE comando .

Esempi

-- UNDROP using the table name
> CREATE TABLE my_catalog.my_schema.my_table (id INT, name STRING);
> DROP TABLE my_catalog.my_schema.my_table;
> UNDROP TABLE my_catalog.my_schema.my_table;
  OK

-- UNDROP WITH ID
– Use SHOW TABLES DROPPED to find dropped tables
> SHOW TABLES DROPPED IN my_schema;
  catalogname schemaname tablename  tableid                              tabletype deletedat                     createdat                     updatedat                     createdby     owner         comment
  ----------- ---------- ---------- ------------------------------------ --------- ----------------------------- ----------------------------- ----------------------------- ------------- ------------- -------
  my_catalog  my_schema  my_table   6ca7be55-8f58-47a7-85ee-7a59082fd17a managed   2023-05-03 AD at 18:17:56 UTC 2023-05-03 AD at 18:17:00 UTC 2023-05-03 AD at 18:17:00 UTC alf@melmak.et alf@melmak.et
  my_catalog  my_schema  my_table   b819f397-c51f-4e60-8acc-05d4d4a7e084 managed   2023-05-04 AD at 10:20:00 UTC 2023-05-04 AD at 08:20:00 UTC 2023-05-04 AD at 08:20:00 UTC alf@melmak.et alf@melmak.et

–- Undrop a specific dropped table.
–- Here, we undrop my_table with table id '6ca7be55-8f58-47a7-85ee-7a59082fd17a'.
-- Note that the table id will be a string surrounded by single quotation marks.
> UNDROP TABLE WITH ID '6ca7be55-8f58-47a7-85ee-7a59082fd17a';
  OK

– Continuing from the example above, Now we want to undrop table with ID 'b819f397-c51f-4e60-8acc-05d4d4a7e084'.
- First, we rename the existing table
> ALTER TABLE my_table RENAME TO my_other_table
  OK
- Then we can undrop table with the name my_table
> UNDROP TABLE WITH ID 'b819f397-c51f-4e60-8acc-05d4d4a7e084'
  OK