title: Select the first 3 rows of each table in a database
body: <p>I have a database with 69 tables and I want to select only the first three records of each table.</p>
  
  <p>I can do it <em>per table</em> with:</p>
  
  <pre><code>SELECT TOP 3 * 
    FROM table_schema.table_name
  </code></pre>
  
  <p>However if I was to do this manually, it would take a lot of time. </p>
  
  <p>Could you please suggest a workaround?</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/2154087/mysql-select-first-4-records-for-each-category-in-a-table">this solution</a> but I can get it to work (I don't know how to modify it for MSSQL)</p>
  
  <p><strong>EDIT</strong> Thanks for your replies. I probably wasn't clear enough: I meant I wanted to parse each individual table and only get the top 3 records than move on to the next one. 
  Yaroslav's code below is what I needed</p>
  
  <pre><code>DECLARE @sql VARCHAR(MAX)='';
  SELECT @sql=@sql+'SELECT TOP 3 * FROM '+'['+SCHEMA_NAME(schema_id)+'].['+name+']'+';'
    FROM sys.tables
  EXEC(@sql)
  </code></pre>