Forum

This topic contains 0 replies, has 1 voice, and was last updated by  Avikumar 2 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1269 Reply

    Avikumar
    Participant

    Create Table Statement:

    Create Table is a statement used to create a table in Hive. The syntax and example are as follows:
    Syntax
    CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.] table_name

    [(col_name data_type [COMMENT col_comment], …)]
    [COMMENT table_comment]
    [ROW FORMAT row_format]
    [STORED AS file_format]

    The following query creates a table named employee using the above data.

    hive> CREATE TABLE IF NOT EXISTS employee ( eid int, name String,
    salary String, destination String)
    COMMENT ‘Employee details’
    ROW FORMAT DELIMITED
    FIELDS TERMINATED BY ‘\t’
    LINES TERMINATED BY ‘\n’
    STORED AS TEXTFILE;
    If you add the option IF NOT EXISTS, Hive ignores the statement in case the table already exists.

    On successful creation of table, you get to see the following response:

    OK
    Time taken: 5.905 seconds
    hive>

    Alter Table Statement:

    It is used to alter a table in Hive.

    Syntax
    The statement takes any of the following syntaxes based on what attributes we wish to modify in a table.

    ALTER TABLE name RENAME TO new_name
    ALTER TABLE name ADD COLUMNS (col_spec[, col_spec …])
    ALTER TABLE name DROP [COLUMN] column_name
    ALTER TABLE name CHANGE column_name new_name new_type
    ALTER TABLE name REPLACE COLUMNS (col_spec[, col_spec …])

    Rename To… Statement
    The following query renames the table from employee to emp.

    hive> ALTER TABLE employee RENAME TO emp;

    Drop Table Statement:

    The syntax is as follows:

    DROP TABLE [IF EXISTS] table_name;
    The following query drops a table named employee:

    hive> DROP TABLE IF EXISTS employee;
    On successful execution of the query, you get to see the following response:

    OK
    Time taken: 5.3 seconds
    hive>

Viewing 1 post (of 1 total)
Reply To: Hive – Create Table
Your information:




cf22

Your Name (required)

Your Email (required)

Subject

Phone No

Your Message

Cart

  • No products in the cart.