SYNTAX CREATE VIEW SQL SERVER

两盒软妹~` 提交于 2019-12-13 08:31:09

问题


i make a view in sql server and throw an error:

USE BaseDeDatos;

CREATE VIEW TEMAS_USUARIO
AS 
SELECT TOP 5 t.id_userTopic, t.nameTopic, u.id_user, u.name
FROM Topic t, Users u
WHERE t.id_userTopic = u.id_group
ORDER BY t.id_topic DESC;

what is wrong whit the syntax? error ---> CREATE VIEW TEMAS_USUARIO can´t use LIMIT


回答1:


USE BaseDeDatos
GO
CREATE VIEW TEMAS_USUARIO
AS 
SELECT TOP 5 t.id_userTopic, t.nameTopic, u.id_user, u.name
FROM Topic t, Users u
WHERE t.id_userTopic = u.id_group
ORDER BY t.id_topic DESC;

The SQL SELECT TOP Clause:

SQL SERVER / MS ACCESS Syntax

SELECT TOP number|percent column_name(s)
FROM table_name;

MySQL Syntax

SELECT column_name(s)
FROM table_name
LIMIT number;

SQL SELECT TOP Clause explanation: Here




回答2:


The syntax command of CREATE VIEW you have this:

The SELECT clauses in a view definition cannot include the following:

  • An ORDER BY clause, unless there is also a TOP clause in the select list of the SELECT statement

Important note Important

The ORDER BY clause is used only to determine the rows that are returned by the TOP or OFFSET clause in the view definition. The ORDER BY clause does not guarantee ordered results when the view is queried, unless ORDER BY is also specified in the query itself.



来源:https://stackoverflow.com/questions/23878954/syntax-create-view-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!