首页 > 开发 > 综合 > 正文

在视图中用order by

2024-07-21 02:08:31
字体:
来源:转载
供稿:网友

大家知道

1:如下查询语句没问题
  select * from sysobjects order by name
2:如果把该查询语句建成视图
  create view v_test
  as
  select * from sysobjects order by name
  会提示出错:
the order by clause is invalid in views, inline functions, derived tables, and subqueries, unless top is also specified.

3: 既然提示除非在语句中使用top 才能用order by,那就好说了
  create view v_test
  as
  select top 100 percent * from sysobjects order by name

一切正常
再用select * from v_test查一下,确实已经正确排序。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表