SQL Server – Create Custom View in Microsoft SQL Server Management Studio

Speaking about SQL, I have noted something really interesting in MS SQL Server Management Studio, which would probably be of use in MS Access as well. This is the saved custom view. It is not present in MS Access, but it is pretty close to the saved query there, although I am not sure whether in MS Access the saved query is that optimized.

Anyway, I will show how to create a custom view. Thus, I will use the table from the previous article for the chess players.

topalov

Let’s imagine that for a reason, the king who was cheated wanted to have a view of the last 3 values of the chess board, that he had to pay with grain. As far as I had an overflow of the big int value, I have reached up to 63. Thus, the last 3 values are these:

top3

 

They are achieved with the following SQL command:

So, if we want to create a view about this sql, we simply have to add a line above like this:

And now in Views we get a view named “Top 3 DESC”. If we click “Design”, we may see even the SQL used for the creation of the view here:

view2

 

Thus, at the end, we may use the view as a separate table – thus, a request for the top value would look like this:

sql2

 

Pretty much that is it! 🙂

I hope you enjoyed it! 😀

Tagged with: , , ,