title: Execute T-SQL Alter Statements created from SELECT statement?
body: <p>End Goal: Change specific options of specific indexes in T-SQL.</p>
  <p>Setup: SQL Server Express Install / SQL Server Management Studio 19 / Database = AdventureWorks2019</p>
  <p>I have the following SELECT statement that queries for the indexes I want to change the row_locking/page_locking options of</p>
  <pre><code>select 'alter index '+ I.name +' on ' + s.name +'.'+ t.name + ' set (allow_row_locks = off, allow_page_locks = off);' 
  FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS DDIPS
  INNER JOIN sys.tables T on T.object_id = DDIPS.object_id
  INNER JOIN sys.schemas S on T.schema_id = S.schema_id
  INNER JOIN sys.indexes I ON I.object_id = DDIPS.object_id
  AND DDIPS.index_id = I.index_id
  WHERE DDIPS.database_id = DB_ID()
  and I.name is not null
  AND DDIPS.avg_fragmentation_in_percent &gt; 0;
  </code></pre>
  <p>This creates a series of results that I would want to execute.</p>
  <p>Example row:</p>
  <pre><code>alter index PK_EmployeePayHistory_BusinessEntityID_RateChangeDate on HumanResources.EmployeePayHistory set (allow_row_locks = off, allow_page_locks = off);
  </code></pre>
  <p>As far as I know right now is that I would have to manually copy the result set from the select statement then execute it as its own query, I was looking for a way to automate this process into one or more scripts.</p>
  <p>Is this possible to do?</p>