Using stored procedures

The previous section gave us an insight into how to create modules and show them on view. When compared to views that simply project data, stored procedures are very powerful modules that are also used for data projection. But the biggest strength of stored procedures arises when we either need to optimize difficult queries or when we want to manipulate data. Let's go straight into creating our first stored procedure now. We will still use the denormalization example from the previous sections, but we will encapsulate it into a stored procedure.

The following script demonstrates this:

CREATE OR ALTER PROC Staging.procLoadOrdersAS DELETE Analytics.OrdersINSERT Analytics.Orders  (OrderLineId, ProductKey, ProductName, ...

Get Hands-On Data Science with SQL Server 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.