IF OBJECT_ID('Sales.RankedProducts', 'V') IS NOT NULL DROP VIEW Sales.RankedProducts; GO CREATE VIEW Sales.RankedProducts AS SELECT ROW_NUMBER() OVER(PARTITION BY categoryid ORDER BY unitprice, productid) AS rownum, categoryid, productid, productname, unitprice FROM Production.Products; GO
Note that it’s not the result set of the view that is stored in the database; rather, only its definition is stored.
- 4. Combining Sets
- from Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012
- Publisher: Microsoft Press
- Released: December 2012
OBJECT_ID defines a database object by (object name, type) based on the list of defined types in T-SQL. V = view and U = user defined table for example. In this case, the programmer is dropping the view if it exists to create a new view. Note the CREATE VIEW command is being used to create the database object directly from the query window.
Share this highlighthttp://www.safaribooksonline.com/a/training-kit-exam/60132/