[SOL-166] How to create tables and views Created: 04.09.2014  Updated: 02.01.2020  Resolved: 02.01.2020

Status: Obsolete
Project: Solution Center
Component/s: EXASolution
Affects Version/s: None
Fix Version/s: None

Type: How To
Reporter: Captain EXASOL Assignee: Captain EXASOL
Labels: EXASolo

Solution:

Note: This solution is no longer maintained. Please see the most up-to-date information in our documentation portal: 

https://docs.exasol.com/sql/create_table.htm

https://docs.exasol.com/sql/create_view.htm

-------------------------------------------------------------------------------------------------------------------------------------------

Prerequisites

You can create tables and views within a schema if you have the privilege CREATE TABLE/CREATE VIEW and you are the owner of the schema or contain the role that is owner. Otherwise you need the privilege CREATE ANY TABLE/VIEW.

CREATE TABLE

1) Specify the table name CREATE TABLE <table-name>
2) Add a comma-separated list of columns
(<column1> <datatype>,
<column2> <datatype>,...)

Optionally you can define primary and foreign keys, auto-increment columns (see identity) and a distribution key (see data distribution).

Example

CREATE TABLE customer(
	c_customer_id int IDENTITY PRIMARY KEY,
	c_customer_name varchar(50),
	c_region_id int REFERENCES region(r_region_id)
)

CREATE VIEW

1) Specify the view name: CREATE VIEW <view-name>
2) Define the query: AS SELECT ... FROM ... WHERE ...

Example

CREATE VIEW customer_of_europe AS
SELECT
	customer.*
FROM
	customer JOIN region
	ON
	customer.c_region_id = region.r_region_id
WHERE
	r_region_name = 'Europe'

Please have a look to the EXASolution manual for a complete description of the CREATE TABLE/VIEW commands.

Category 1: SQL
Generated at Sun Jul 12 13:51:13 CEST 2020 using Jira 7.13.13#713013-sha1:4c0f5f5e3383570393fbbf3d2fd5de1eb4057c36.