In this topic, we described about the Create Database in detail.
Hive deals with tables to analyze the data which is a database technology. The technology allows storing the data in table and allows user to query to analyze the data.
Let’s discuss about creating and using database in detail.
Create Database -
Hive had a default database named default. User can create the database new database if user do not want to use default database. In general terms, the database is a collection of tables.
A logical construct for grouping related tables, views, and functions together within their own namespace. So to create a table on a new database, user needs to create the database as a first step and make it in use as a second step. The below is the syntax to create the database.
CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_name=property_value, ...)];
The database and schema are interchangeable. DATABASE or SCHEMA is same thing in behavior. CREATE DATABASE was added in Hive 0.6. The WITH DBPROPERTIES clause was added in Hive 0.7.
The keywords CREATE (DATABASE|SCHEMA) database_name is the only mandatory keywords and remaining keywords are optional. [IF NOT EXISTS] is used to notify the user if the new database is already existed in the system.
The below command used to create the new database std_db
Hive> CREATE DATABASE [IF NOT EXISTS] std_db Or Hive> CREATE SCHEMA [IF NOT EXISTS] newsch
Once the database is successfully created, below command is used to display the databases.
Hive> SHOW DATABASES; default std_db