04-stable.md 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
---
sidebar_label: STable
title: Super Table
---

:::note

Keyword `STable`, abbreviated for super table, is supported since version 2.0.15.

:::

12
## Create STable
13 14 15 16 17

```
CREATE STable [IF NOT EXISTS] stb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...]) TAGS (tag1_name tag_type1, tag2_name tag_type2 [, tag3_name tag_type3]);
```

S
Sean Ely 已提交
18
The SQL statement of creating a STable is similar to that of creating a table, but a special column set named `TAGS` must be specified with the names and types of the tags.
19 20 21

:::info

22
1. A tag can be of type timestamp, since version 2.1.3.0, but its value must be fixed and arithmetic operations cannot be performed on it. Prior to version 2.1.3.0, tag types specified in TAGS could not be of type timestamp.
S
Sean Ely 已提交
23 24 25
2. The tag names specified in TAGS should NOT be the same as other columns.
3. The tag names specified in TAGS should NOT be the same as any reserved keywords.(Please refer to [keywords](/taos-sql/keywords/)
4. The maximum number of tags specified in TAGS is 128, there must be at least one tag, and the total length of all tag columns should NOT exceed 16KB.
26 27 28 29 30 31 32 33 34

:::

## Drop STable

```
DROP STable [IF EXISTS] stb_name;
```

S
Sean Ely 已提交
35
All the subtables created using the deleted STable will be deleted automatically.
36 37 38 39 40 41 42

## Show All STables

```
SHOW STableS [LIKE tb_name_wildcard];
```

S
Sean Ely 已提交
43
This command can be used to display the information of all STables in the current database, including name, creation time, number of columns, number of tags, and number of tables created using this STable.
44 45 46 47 48 49 50

## Show The Create Statement of A STable

```
SHOW CREATE STable stb_name;
```

S
Sean Ely 已提交
51
This command is useful in migrating data from one TDengine cluster to another because it can be used to create the exact same STable in the target database.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

## Get STable Definition

```
DESCRIBE stb_name;
```

## Change Columns Of STable

### Add A Column

```
ALTER STable stb_name ADD COLUMN field_name data_type;
```

### Remove A Column

```
ALTER STable stb_name DROP COLUMN field_name;
```

### Change Column Length

```
ALTER STable stb_name MODIFY COLUMN field_name data_type(length);
```

79
This command can be used to change (or more specifically, increase) the length of a column of variable length types, like BINARY or NCHAR.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

## Change Tags of A STable

### Add A Tag

```
ALTER STable stb_name ADD TAG new_tag_name tag_type;
```

This command is used to add a new tag for a STable and specify the tag type.

### Remove A Tag

```
ALTER STable stb_name DROP TAG tag_name;
```

97
The tag will be removed automatically from all the subtables, created using the super table as template, once a tag is removed from a super table.
98 99 100 101 102 103 104

### Change A Tag

```
ALTER STable stb_name CHANGE TAG old_tag_name new_tag_name;
```

105
The tag name will be changed automatically for all the subtables, created using the super table as template, once a tag name is changed for a super table.
106 107 108 109 110 111 112

### Change Tag Length

```
ALTER STable stb_name MODIFY TAG tag_name data_type(length);
```

113
This command can be used to change (or more specifically, increase) the length of a tag of variable length types, like BINARY or NCHAR.
114 115

:::note
S
Sean Ely 已提交
116
Changing tag values can be applied to only subtables. All other tag operations, like add tag, remove tag, however, can be applied to only STable. If a new tag is added for a STable, the tag will be added with NULL value for all its subtables.
117 118

:::