Back to home page

OSCL-LXR

 
 

    


0001 ---
0002 layout: global
0003 title: DROP TABLE
0004 displayTitle: DROP TABLE
0005 license: |
0006   Licensed to the Apache Software Foundation (ASF) under one or more
0007   contributor license agreements.  See the NOTICE file distributed with
0008   this work for additional information regarding copyright ownership.
0009   The ASF licenses this file to You under the Apache License, Version 2.0
0010   (the "License"); you may not use this file except in compliance with
0011   the License.  You may obtain a copy of the License at
0012  
0013      http://www.apache.org/licenses/LICENSE-2.0
0014  
0015   Unless required by applicable law or agreed to in writing, software
0016   distributed under the License is distributed on an "AS IS" BASIS,
0017   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0018   See the License for the specific language governing permissions and
0019   limitations under the License.
0020 ---
0021 
0022 ### Description
0023 
0024 `DROP TABLE` deletes the table and removes the directory associated with the table from the file system
0025 if the table is not `EXTERNAL` table. If the table is not present it throws an exception.
0026 
0027 In case of an external table, only the associated metadata information is removed from the metastore database.
0028 
0029 ### Syntax
0030 
0031 ```sql
0032 DROP TABLE [ IF EXISTS ] table_identifier
0033 ```
0034 
0035 ### Parameter
0036 
0037 * **IF EXISTS**
0038 
0039     If specified, no exception is thrown when the table does not exist.
0040 
0041 * **table_identifier**
0042 
0043     Specifies the table name to be dropped. The table name may be optionally qualified with a database name.
0044 
0045     **Syntax:** `[ database_name. ] table_name`
0046 
0047 ### Examples
0048 
0049 ```sql
0050 -- Assumes a table named `employeetable` exists.
0051 DROP TABLE employeetable;
0052 
0053 -- Assumes a table named `employeetable` exists in the `userdb` database
0054 DROP TABLE userdb.employeetable;
0055 
0056 -- Assumes a table named `employeetable` does not exist.
0057 -- Throws exception
0058 DROP TABLE employeetable;
0059 Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeetable;
0060 (state=,code=0)
0061 
0062 -- Assumes a table named `employeetable` does not exist,Try with IF EXISTS
0063 -- this time it will not throw exception
0064 DROP TABLE IF EXISTS employeetable;
0065 ```
0066 
0067 ### Related Statements
0068 
0069 * [CREATE TABLE](sql-ref-syntax-ddl-create-table.html)
0070 * [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html)
0071 * [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html)