Return to site

Writing sql scripts

broken image
broken image

This solution is wrapped as a PowerShell function, and as such, I can easily embed it into lots of my DBA automation work. So I will use PowerShell, with SMO to come up with a more robust and generic solution.ĭatabase.ExecuteWithResuts method to execute one or multipleĭataColumn, and based on the column data type, process the column value accordingly Time-consuming to do with a T-SQL solution since the sp_who2 result has two identical columns. It becomes very difficult to do when you do not know what data set you will getįrom a stored procedure (assuming depending on parameter values the stored procedure may returnĮven for a simple example, say I want to script out the results of 'sp_who2 active', it will be This is easy when you have a simple query, but the problem with this pure

broken image

Using the query to dump the data into a temporary table, something similar.In theory, given a query we can create a pure T-SQL solution with the following design:

broken image