Table cleaning

Sometimes, we may need to clean up the table, either by deleting only the records or the table along with the records. There are two statements in HQL to do such cleaning. One is the DROP TABLE statement, and the other is TRUNCATE TABLE. The drop-table statement on an internal table removes the table completely and moves data to .trash in the current user directory, if the trash setting is configured. The drop-table statement on an external table will only remove the table definition, but keeps data:

> DROP TABLE IF EXISTS empty_ctas_employee;
No rows affected (0.283 seconds)

On the other hand, the truncate table statement only removes data from the table. The table still exists, but is empty. Note, truncate table can only apply to an internal table:

> TRUNCATE TABLE cte_employee;-- Only apply to internal tables
No rows affected (0.093 seconds)


> SELECT name FROM cte_employee;--Other hand, the truncate t
-- Not data left, but empty table exists
+--------------------+
| cte_employee.name |
+--------------------+
+--------------------+
No rows selected (0.059 seconds)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.227.82