我有以下语句在我省略ORDER BY
子句时有效,或者如果我将其作为选择运行并省略创建表部分,但我需要两者来确保我生成的密钥的顺序正确
有任何想法吗?
消息 104381,级别 16,状态 1,第 18 行
ORDER BY 子句在视图、CREATE TABLE AS SELECT、INSERT SELECT、SELECT INTO、内联函数、派生表、子查询和公用表表达式中无效,除非 TOP 或 FOR XML 是也指定。
CREATE TABLE #demo
WITH (DISTRIBUTION = ROUND_ROBIN)
AS
SELECT
ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS ID,
schemas.name as [schema],
tables.name as [table],
columns.column_id as [ordinal],
columns.name as [column],
types.name as [type]
FROM SYS.COLUMNS
inner join sys.types
on types.system_type_id = columns.system_type_id
inner join sys.tables
on tables.object_id = columns.object_id
inner join sys.schemas
on schemas.schema_id = tables.schema_id
order by schemas.name,
tables.name,
columns.column_id