Create the database table
After you create the TimeSeries subtype, use the CREATE TABLE statement to create a table with a column of that subtype.
You have the following options and restrictions when you create a table with at TimeSeries column:
- You can create the table in a dbspace that uses non-default page size.
- You cannot use delimited identifiers for table or column names.
- If you plan to replicate time series data with Enterprise Replication, the primary key column must not be an opaque data type.
- If you plan to write a loader program, the name of the table and the name of the TimeSeries column must not contain uppercase letters.
- You
can fragment the table. When you fragment the table and enable PDQ,
certain queries can run faster:
- TimeSeries routines that select time series data can run in parallel. The table can be fragmented by any method.
- Queries on a fragmented virtual table that is based on the table can run in parallel. The table must be fragmented by expression.
- You can include other options of the CREATE TABLE statement.
The basic syntax for creating a table with a TimeSeries subtype
column is:
CREATE TABLE table_name(
col1 any_data_type,
col2 any_data_type,
...
coln TimeSeries(subtype_name)
);
List the data type of the TimeSeries column as TimeSeries(subtype_name),
where subtype_name is the name of the subtype that
you created.Examples
The following example creates a
table that is called daily_stocks that contains a time series
column of type TimeSeries(stock_bar):
create table daily_stocks (
stock_id int,
stock_name lvarchar,
stock_data TimeSeries(stock_bar)
);
Each row in the daily_stocks table can hold a stock_bar time series for a particular stock.
The
following example creates a table that is called activity_stocks that
contains a time series column of type TimeSeries(stock_trade):
create table activity_stocks(
stock_id int,
activity_data TimeSeries(stock_trade)
);
Each row in the activity_stocks table can hold a stock trade time series for a particular stock.