Welcome to Day 17 of my “A Month of PowerShell” series. This series will use the series landing page on this blog at http://blog.waynesheffield.com/wayne/a-month-of-powershell/. Please refer to this page to see all of the posts in this series, and to quickly go to them.

We’ve spent several days working with tables, but that’s not all that is in a database. Continuing the mini-series of objects compiled with T-SQL code, today we will work with views.

Creating a view

[crayon-53f5aa4c3da83211494955/]

That was pretty simple. Does anybody out there have any questions? Okay, let’s move on.

Altering a view

Perhaps you noticed that the view’s definition is performing a select *. Seeing this gets the fangs coming out, fingernails in the clawing position, and the hair rising on the back of my neck. Okay, not really, but it is a practice generally considered to be bad. Let’s change this view to specify the columns.

[crayon-53f5aa4c3da9b399130882/]

Dropping a view

If you want to drop the view, after verifying that the view does exist, simply call its drop method. So from the above script for the alter, change this section:

[crayon-53f5aa4c3daa8116619477/]

To:

[crayon-53f5aa4c3dab3654785475/]