How to get the effect of a sorted database view?

I would like to (efficiently) sort the database view - I know that the conceptual order in the db view is not valid, but I have the following scenario:

  • a third-party legacy application that reads data from database tables using select (*) from a tab statement
  • outdated application is very sensitive to record order
  • an application that I wrote so that users can more easily manage data in tables, but inserting and deleting from a table naturally upset records.

Changing the instructions in an outdated application to select (*) from the name field of the name table will fix my problem, but this is not an option.

So - I set up a staging table into which data can be exported in the correct order, but this is a resource-intensive option, meaning that the data is not "live" in an outdated application and additional work for users.

I would like to access an ordered version of a table with these restrictions. Any ideas how?


Update - I work with Sybase 12.5, but I would like to avoid a tightly coupled solution with a specific RDBMS - it may change.

I cannot add the "order by" clause to the view due to the SQL standards mentioned in this Wikipedia entry

+3
source share
6 answers

First of all, I had to work on this type of project before, and it really is a bitch. My condolences.

, , , , , UDTF. , - .

+2

. , TSQL (Sql Server):

CREATE FUNCTION orderedTable() 
RETURNS @returnTable TABLE 
    (val varchar(100)) AS
BEGIN
    insert @returnTable (val)
    select val from MyTable
    order by val desc
    RETURN 
END

GO

SELECT * FROM orderedTable
+1

,

CREATE VIEW OrderedTable
AS SELECT TOP (Select Count(*) from UnorderedTable) *
FROM UnorderedTable Order By field
0

, :
1)
2) , .
3) , , .

0

MS Sql Server , :

SELECT TOP 100 PERCENT * FROM TABLE ORDER BY 1

. Sybase Sql Server T-SQL, , .

, . , * " ".

  • , , . SQL ( - , AFAIK) ... , , , .
0

, , , , , , Sybase ASE 12.5.

MSSQL Server and Sybase ASE 15.x should do what is needed - I hope I can organize something. I’m not quite sure which one to accept if something works for me, but I will return and accept the answer.

0
source

Source: https://habr.com/ru/post/1697882/


All Articles