SYNTAX CREATE VIEW SQL SERVER

2019-09-19 16:18发布

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

2条回答
太酷不给撩
2楼-- · 2019-09-19 16:36
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

查看更多
再贱就再见
3楼-- · 2019-09-19 16:47

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.

查看更多
登录 后发表回答