Skip to content

Commit 488a894

Browse files
committed
CTAS table
1 parent fc31a44 commit 488a894

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docs/t-sql/statements/create-table-as-select-azure-sql-data-warehouse.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ CREATE TABLE { database_name.schema_name.table_name | schema_name.table_name | t
4040
<distribution_option> -- required
4141
[ , <table_option> [ ,...n ] ]
4242
)
43-
AS <select_statement>
43+
AS <select_statement>
44+
OPTION <query_hint>
4445
[;]
4546
4647
<distribution_option> ::=
@@ -53,16 +54,21 @@ CREATE TABLE { database_name.schema_name.table_name | schema_name.table_name | t
5354
<table_option> ::=
5455
{
5556
CLUSTERED COLUMNSTORE INDEX --default for SQL Data Warehouse
57+
| CLUSTERED COLUMNSTORE INDEX ORDER (column[,...n])
5658
| HEAP --default for Parallel Data Warehouse
5759
| CLUSTERED INDEX ( { index_column_name [ ASC | DESC ] } [ ,...n ] ) --default is ASC
5860
}
59-
| PARTITION ( partition_column_name RANGE [ LEFT | RIGHT ] --default is LEFT
61+
| PARTITION ( partition_column_name RANGE [ LEFT | RIGHT ] --default is LEFT
6062
FOR VALUES ( [ boundary_value [,...n] ] ) )
6163
6264
<select_statement> ::=
6365
[ WITH <common_table_expression> [ ,...n ] ]
6466
SELECT select_criteria
6567
68+
<query_hint> ::=
69+
{
70+
MAXDOP
71+
}
6672
```
6773

6874
<a name="arguments-bk"></a>
@@ -96,15 +102,19 @@ For details, see the [Table partition options](https://msdn.microsoft.com/librar
96102

97103
<a name="select-options-bk"></a>
98104

99-
### Select options
105+
### Select statement
100106
The select statement is the fundamental difference between CTAS and CREATE TABLE.
101107

102108
`WITH` *common_table_expression*
103109
Specifies a temporary named result set, known as a common table expression (CTE). For more information, see [WITH common_table_expression &#40;Transact-SQL&#41;](../../t-sql/queries/with-common-table-expression-transact-sql.md).
104110

105111
`SELECT` *select_criteria*
106112
Populates the new table with the results from a SELECT statement. *select_criteria* is the body of the SELECT statement that determines which data to copy to the new table. For information about SELECT statements, see [SELECT &#40;Transact-SQL&#41;](../../t-sql/queries/select-transact-sql.md).
107-
113+
114+
### Query hint
115+
Users can set MAXDOP to an integer value to control the maximum degree of parallelism. When MAXDOP is set to 1, the query is executed by a single thread.
116+
117+
108118
<a name="permissions-bk"></a>
109119

110120
## Permissions
@@ -814,6 +824,14 @@ OPTION (LABEL = 'CTAS : Partition IN table : Create');
814824
```
815825

816826
You can see therefore that type consistency and maintaining nullability properties on a CTAS is a good engineering best practice. It helps to maintain integrity in your calculations and also ensures that partition switching is possible.
827+
828+
### N. Create an ordered clustered columnstore index with MAXDOP 1
829+
```sql
830+
CREATE TABLE Table1 WITH (DISTRIBUTION = HASH(c1), CLUSTERED COLUMNSTORE INDEX ORDER(c1) )
831+
AS SELECT * FROM ExampleTable
832+
OPTION (MAXDOP 1);
833+
```
834+
817835

818836
## See Also
819837
[CREATE EXTERNAL DATA SOURCE &#40;Transact-SQL&#41;](../../t-sql/statements/create-external-data-source-transact-sql.md)

0 commit comments

Comments
 (0)