From the course: Program Databases with Transact-SQL

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Leverage view objects with indexes

Leverage view objects with indexes - SQL Server Tutorial

From the course: Program Databases with Transact-SQL

Start my 1-month free trial

Leverage view objects with indexes

- Earlier I mentioned that user don't generally store data, and that's true in most cases. But there is a way to have a view store its own copy of your data in addition to the copy that's in the original tables. You do this by adding an index to the view. Let's first explore why you would want to do this. I'm going to review the data that's currently stored in two different tables, Warehouse.StockItems and Purchasing.Suppliers. Let's go ahead and run these queries on line one through eight to see these two different tables. The WideworldImporters database is properly normalized. Meaning that information is split across multiple tables with key values that connect the rows of data together. So from the StockItems table that we have here at the top, we can find the ProductSupplier by matching the SupplierID in both tables. This pattern repeats itself over and over again in the database. We have the ColorID, the UnitPackageID, we also have the SupplierCategoryID and the…

Contents