Hive Tutorial 9 : Hive DDL
Data definition language parts of HiveQL, whichare used for creating, altering, and dropping
databases, tables, views, functions, and indexes.
Databases in Hive
How to create
database?
The Command used for creation of database in hive is
CREATE DATABASE
databasename;
Eg: hive >
CREATE DATABASE Test;
** Hive will convert uppercase letter into lower case . So even
though we gave name in uppercase, it is save in lower case letters in hive.
What if database already exists?
Hive will throw an error if databasealready exists. We can suppress this
error by modifying create query.
Eg: hive >CREATE DATABASE IF NOT EXISTS Test;
IF NOT EXISTS clause is useful
for scripts that should create a database on the-fly, if necessary, before
proceeding.
** We can use SCHEMA keyword instead of DATABASE key word.
How to View created databases??
hive> SHOWDATABASES;
This command is
used to view all the existed databases in hive. “default “ table will be
created in default in hive.
How to use database?
hive> Use databasename;
By default the operations will be performed under “default” database of
hive. If we want to use other database for performing operations we can use
this command.
How to Alter Database?
By using
ALTER command we can do modifications on database.
hive>ALTER
(DATABASE|SCHEMA) databasename SET DBPROPERTIES (property_name=property_value,
...);
How to Drop Database?
By using
DROP command we can delete the database that is created.
hive>DROP (DATABASE|SCHEMA) [IF EXISTS] databasename;
**In order to delete a database, it should be empty.
Comments
Post a Comment