<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>SQLYoga</title><generator>teletype.in</generator><description><![CDATA[Join SQLYoga to boost your SQL and database skills with tutorials, articles, and expert tips. Be part of a growing community of learners.]]></description><image><url>https://img1.teletype.in/files/08/7c/087c024e-b1dd-4bee-9200-b1cfc222e4a5.png</url><title>SQLYoga</title><link>https://teletype.in/@sqlyoga</link></image><link>https://teletype.in/@sqlyoga?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/sqlyoga?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/sqlyoga?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Tue, 21 Apr 2026 13:45:02 GMT</pubDate><lastBuildDate>Tue, 21 Apr 2026 13:45:02 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@sqlyoga/table-size-in-sql-server--spmsforeachtable-sqlyoga</guid><link>https://teletype.in/@sqlyoga/table-size-in-sql-server--spmsforeachtable-sqlyoga?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga</link><comments>https://teletype.in/@sqlyoga/table-size-in-sql-server--spmsforeachtable-sqlyoga?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga#comments</comments><dc:creator>sqlyoga</dc:creator><title>Exploring Table Size Measurement in SQL Server with sp_MSforeachtable by SQLYoga Guide</title><pubDate>Fri, 14 Jun 2024 14:15:47 GMT</pubDate><media:content medium="image" url="https://img3.teletype.in/files/62/36/6236e721-5b95-44e5-b757-932af77b9063.png"></media:content><description><![CDATA[<img src="https://img1.teletype.in/files/c8/66/c8666b91-2cd3-4cde-acc9-8abca50e82ba.jpeg"></img>Are you looking to delve into the nitty-gritty details of your SQL Server database? Perhaps you’re seeking insights into how much space each table occupies? Look no further! In this guide, brought to you by SQLYoga, we’ll walk you through a handy tool for measuring table size in SQL Server using the sp_MSforeachtable procedure.]]></description><content:encoded><![CDATA[
  <figure id="mnth" class="m_original">
    <img src="https://img1.teletype.in/files/c8/66/c8666b91-2cd3-4cde-acc9-8abca50e82ba.jpeg" width="1280" />
  </figure>
  <p id="w0U7">Are you looking to delve into the nitty-gritty details of your SQL Server database? Perhaps you’re seeking insights into how much space each table occupies? Look no further! In this guide, brought to you by SQLYoga, we’ll walk you through a handy tool for measuring table size in SQL Server using the <a href="https://www.sqlyoga.com/2009/03/sql-server-how-much-space-occupied-by.html" target="_blank">sp_MSforeachtable</a> procedure.</p>
  <h1 id="c3ff">Understanding the Need</h1>
  <p id="c152">In the realm of database management, understanding the space utilization of tables is crucial for optimization, performance tuning, and resource management. Knowing how much space each table occupies can aid in identifying potential bottlenecks, optimizing storage, and planning for scalability.</p>
  <h1 id="ec10">Meet sp_MSforeachtable</h1>
  <p id="2bb3">One might wonder: “How can I efficiently gather information on table sizes across my entire database?” Enter sp_MSforeachtable, an undocumented stored procedure tucked away in the master database of SQL Server. Despite its hidden nature, this gem proves to be invaluable for database administrators and developers alike.</p>
  <h1 id="b3f3">The Script in Action</h1>
  <p id="3d9d">Let’s dive into a practical example. Suppose we’re working with the Adventure Works database and want to ascertain the space usage of each table. With sp_MSforeachtable, this task becomes a breeze:</p>
  <pre id="sIob">USE AdventureWorks;EXECUTE sp_MSforeachtable &#x27;sp_spaceused [?]&#x27;</pre>
  <p id="c5e7">Executing this script initiates a journey through each table in the AdventureWorks database, courtesy of sp_MSforeachtable. For every table encountered, the sp_spaceused stored procedure is invoked, providing insights into the space allocated and utilized.</p>
  <h1 id="50bd">Deconstructing the Script</h1>
  <p id="1769">The script comprises two essential components:</p>
  <ol id="6OOb">
    <li id="fbf4"><strong>USE AdventureWorks;</strong>: This statement selects the AdventureWorks database as the current context for executing subsequent commands. Replace ‘AdventureWorks’ with the name of your target database.</li>
    <li id="af73"><strong>EXECUTE sp_MSforeachtable ‘sp_spaceused [?]’;</strong>: This line is where the magic happens. The sp_MSforeachtable procedure iterates over each table in the database, replacing the ‘?’ placeholder with the respective table name. For every iteration, the sp_spaceused stored procedure is invoked with the current table name, yielding valuable space utilization metrics.</li>
  </ol>
  <h1 id="df36">Harnessing the Power</h1>
  <p id="a063">The versatility of sp_MSforeachtable extends beyond measuring table size. Whether you’re performing data validation, executing maintenance tasks, or conducting schema analysis, this hidden gem empowers you to traverse through tables with ease.</p>
  <h1 id="7a8e">Conclusion</h1>
  <p id="bfe5">In the realm of SQL Server database management, understanding table size is paramount. With the aid of sp_MSforeachtable, you can effortlessly navigate through your database, gathering insights into space utilization across tables. Armed with this knowledge, you’re better equipped to optimize performance, allocate resources judiciously, and embark on your journey to database mastery.</p>
  <p id="e2e2">Unearth the power of sp_MSforeachtable and embark on a voyage of discovery within your SQL Server database today!</p>
  <p id="8e68">Visit <a href="https://www.sqlyoga.com/" target="_blank">SQLYoga</a> today to explore our articles, tutorials, and community forums. Elevate your database skills with SQLYoga and unleash the full potential of SQL Server!</p>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@sqlyoga/sql-server-replicate-function-by-sqlyoga-guide</guid><link>https://teletype.in/@sqlyoga/sql-server-replicate-function-by-sqlyoga-guide?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga</link><comments>https://teletype.in/@sqlyoga/sql-server-replicate-function-by-sqlyoga-guide?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga#comments</comments><dc:creator>sqlyoga</dc:creator><title>REPLICATE() Function in SQL Server by SQLYoga Guide </title><pubDate>Wed, 12 Jun 2024 11:41:50 GMT</pubDate><media:content medium="image" url="https://img1.teletype.in/files/84/7f/847f69c2-35b3-41a1-a62b-08c26f17b3ba.png"></media:content><description><![CDATA[<img src="https://img3.teletype.in/files/ae/66/ae668006-9b6c-4400-bdc9-9bca5f3b8143.jpeg"></img>Are you struggling with ensuring uniformity in numeric data stored in your SQL Server database? Fear not! SQLYoga brings you an insightful guide on mastering the REPLICATE() function, your solution to standardizing numeric data effortlessly.]]></description><content:encoded><![CDATA[
  <section>
    <figure id="qNuF" class="m_original">
      <img src="https://img3.teletype.in/files/ae/66/ae668006-9b6c-4400-bdc9-9bca5f3b8143.jpeg" width="1280" />
    </figure>
    <p id="xnpm">Are you struggling with ensuring uniformity in numeric data stored in your SQL Server database? Fear not! <a href="https://www.sqlyoga.com/" target="_blank">SQLYoga</a> brings you an insightful guide on mastering the <a href="https://www.sqlyoga.com/2009/02/sql-server-replicate-function.html" target="_blank">REPLICATE()</a> function, your solution to standardizing numeric data effortlessly.</p>
    <p id="4a78">Recently, while perusing SQL Authority, I stumbled upon a common developer dilemma: how to standardize numeric data sizes. Let’s explore this issue and unveil the simplicity of its resolution.</p>
    <p id="497f"><strong>The Problem: Numeric Data Standardization</strong></p>
    <p id="1293">Imagine a scenario where you have a numeric column containing values like There is one numeric column. User needs to make sure that all data should be of same size. Like “<strong>17.00,12.00,8.17,4.44</strong>”, these all should be “<strong>17.00,12.00,08.17,04.44</strong>” like that. How can you achieve this uniformity efficiently within SQL Server?</p>
    <p id="2c09"><strong>The Solution: REPLICATE() to the Rescue</strong></p>
    <p id="20ee">Enter the REPLICATE() function, a versatile tool within SQL Server’s arsenal. This function empowers developers to append a specified character to a string a specified number of times. Let’s break down how to leverage this function effectively:</p>
    <p id="03a9"><strong>Syntax of REPLICATE():</strong></p>
    <pre id="qP9F" data-lang="sql">REPLICATE (&quot;string that you want TO append&quot; ,&quot;INTEGER VALUE&quot; )</pre>
    <ol id="yqr1">
      <li id="6662">The first parameter represents the character or string you wish to append before the number.</li>
      <li id="6e19">The second parameter denotes the number of times the specified character should be added to the number.</li>
    </ol>
    <p id="92dd"><strong>Example Implementation:</strong></p>
    <pre id="G3FP" data-lang="sql">DECLARE @t AS NUMERIC(8,2)
SELECT @t = 08.2
SELECT Cast(Replicate(0,6-Len(@t)) AS VARCHAR(5)) + 
Cast(@t AS VARCHAR(5))</pre>
    <p id="6648">In this example, we specify that the resulting string should have a length of 5. Since “8.2” has only four digits, we add one “0” to the beginning of the number to meet the desired length.</p>
    <p id="5c01"><strong>Crafting Your Solutions with REPLICATE()</strong></p>
    <p id="b3ee">The beauty of the REPLICATE() function lies in its flexibility. You can append any character or string simply by changing the first parameter. Whether you need to pad numeric data with zeros, spaces, or any other character, REPLICATE() has got you covered.</p>
    <p id="f747"><strong>Unlock the Power of REPLICATE() with SQLYoga</strong></p>
    <p id="5165">Ready to streamline your data formatting processes and ensure consistency in your SQL Server database? Dive into the depths of the REPLICATE() function with SQLYoga comprehensive guide. Master the art of standardizing numeric data effortlessly and elevate your database skills to new heights.</p>
    <p id="394d">With REPLICATE() in your toolkit, achieving uniformity in numeric data has never been easier. Start mastering this indispensable function today with SQLYoga expert guidance.</p>
    <p id="a684"><a href="https://www.sqlyoga.com/" target="_blank"><strong>Visit SQLYoga</strong></a> for more articles and tutorials on SQL Server. Join our community of SQL enthusiasts and take your database skills to the next level with SQLYoga.</p>
  </section>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@sqlyoga/comma-separated-list-with-select-in-sql-server</guid><link>https://teletype.in/@sqlyoga/comma-separated-list-with-select-in-sql-server?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga</link><comments>https://teletype.in/@sqlyoga/comma-separated-list-with-select-in-sql-server?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga#comments</comments><dc:creator>sqlyoga</dc:creator><title>Create a Comma Separated List with SELECT in SQL Server by SQLYoga Guide</title><pubDate>Thu, 06 Jun 2024 13:54:31 GMT</pubDate><description><![CDATA[<img src="https://miro.medium.com/v2/resize:fit:160/1*twyhqMiQvVyYwBwOfgHkZA.jpeg"></img>Today, I encountered a situation where I needed to display all related data in a comma-separated list using a SELECT statement. Up until now, I have been using a scalar function that utilizes COALESCE() to achieve this. However, I discovered a fantastic solution that allows us to generate a comma-separated list without needing a scalar function. Let’s dive into it with SQLYoga guide.]]></description><content:encoded><![CDATA[
  <p id="c49e">Today, I encountered a situation where I needed to display all related data in a comma-separated list using a <a href="https://www.sqlyoga.com/2009/02/sql-server-get-comma-separated-list.html" target="_blank"><strong>SELECT</strong></a> statement. Up until now, I have been using a scalar function that utilizes <code>COALESCE()</code> to achieve this. However, I discovered a fantastic solution that allows us to generate a comma-separated list without needing a scalar function. Let’s dive into it with <a href="https://www.sqlyoga.com/" target="_blank"><strong>SQLYoga</strong></a> guide.</p>
  <h1 id="29b0">Example Scenario</h1>
  <p id="d30d">Consider the following table:</p>
  <pre id="DQwW">CREATE TABLE #test(    
field1 VARCHAR(5),     
field2 VARCHAR(5)
);</pre>
  <p id="74a5">Let’s insert some data into this table:</p>
  <pre id="OQL9">INSERT INTO #test
SELECT &#x27;001&#x27;,&#x27;AAA&#x27;
UNION ALL
SELECT &#x27;001&#x27;,&#x27;BBB&#x27;
UNION ALL
SELECT &#x27;002&#x27;,&#x27;CCC&#x27;
UNION ALL
SELECT &#x27;003&#x27;,&#x27;DDD&#x27;
UNION ALL
SELECT &#x27;004&#x27;,&#x27;EEE&#x27;
UNION ALL
SELECT &#x27;004&#x27;,&#x27;FFF&#x27;
UNION ALL
SELECT &#x27;004&#x27;,&#x27;GGG&#x27;;</pre>
  <h1 id="1d9b">Current Data in the Table</h1>
  <p id="9adf">After inserting the data, our table looks like this:</p>
  <figure id="rBCd" class="m_custom">
    <img src="https://miro.medium.com/v2/resize:fit:160/1*twyhqMiQvVyYwBwOfgHkZA.jpeg" width="160" />
  </figure>
  <h1 id="63ea">Expected Output</h1>
  <p id="17b8">We want to generate a comma-separated list of <code>field2</code> for each unique <code>field1</code>. The expected output is:</p>
  <figure id="F4MS" class="m_custom">
    <img src="https://miro.medium.com/v2/resize:fit:195/1*okl2pe3WkKdWys0y09hgLg.jpeg" width="195" />
  </figure>
  <h1 id="3974">Proposed Solution</h1>
  <p id="9e08">Here’s the SQL query to achieve the desired output:</p>
  <pre id="XkxA">SELECT field1,    
SUBSTRING(        
(            
SELECT &#x27;, &#x27; + field2            
FROM #test t2            
WHERE t1.field1 = t2.field1            
ORDER BY t2.field2            
FOR XML PATH(&#x27;&#x27;)        
), 3, 1000) AS field2_list
FROM #test t1
GROUP BY field1;</pre>
  <h1 id="42fa">Explanation</h1>
  <ol id="o6vd">
    <li id="0479"><strong>Subquery with <code>FOR XML PATH</code></strong>: The subquery concatenates <code>field2</code> values into a single string separated by commas for each <code>field1</code>. The <code>FOR XML PATH(&#x27;&#x27;)</code> clause converts the result into XML format, which we then transform into a plain string.</li>
    <li id="1ad2"><strong>Substring Function</strong>: The <code>SUBSTRING</code> function removes the leading comma and space from the concatenated string. The <code>3</code> indicates starting from the third character, effectively skipping the first two characters (<code>, </code>).</li>
    <li id="999f"><strong>Group By</strong>: The <code>GROUP BY</code> clause ensures we get one row per <code>field1</code>.</li>
  </ol>
  <h1 id="b5d0">Output</h1>
  <p id="1c4d">Running the above query will yield the following output:</p>
  <figure id="yiy4" class="m_custom">
    <img src="https://miro.medium.com/v2/resize:fit:195/1*okl2pe3WkKdWys0y09hgLg.jpeg" width="195" />
  </figure>
  <p id="07b2">With this approach, you can generate a comma-separated list without relying on scalar functions. This method is efficient and leverages SQL Server’s XML capabilities to concatenate strings.</p>
  <p id="97d7"><a href="https://www.sqlyoga.com/" target="_blank"><strong>Read More on SQLYoga</strong></a> about advanced SQL techniques and optimizing your queries.</p>
  <p id="72f1">At SQLYoga, we are committed to bringing you the latest and most efficient SQL Server solutions. This method of generating a comma-separated list is a prime example of how you can streamline your SQL queries and achieve better performance. Stay tuned for more tips and tricks to enhance your SQL skills and streamline your database management tasks.</p>
  <p id="8d31"><a href="https://www.sqlyoga.com/" target="_blank"><strong>Visit SQLYoga</strong></a> for more articles and tutorials on SQL Server. Join our community of SQL enthusiasts and take your database skills to the next level with SQLYoga.</p>

]]></content:encoded></item><item><guid isPermaLink="true">https://teletype.in/@sqlyoga/WSxHhJWvuh0</guid><link>https://teletype.in/@sqlyoga/WSxHhJWvuh0?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga</link><comments>https://teletype.in/@sqlyoga/WSxHhJWvuh0?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=sqlyoga#comments</comments><dc:creator>sqlyoga</dc:creator><title>SQLYoga: Adding Computed Columns in SQL Server</title><pubDate>Mon, 27 May 2024 07:24:28 GMT</pubDate><description><![CDATA[<img src="https://img4.teletype.in/files/39/52/395254ac-fac3-44a1-8eb0-c79af6d63ff1.jpeg"></img>A scenario that required me to add one calculated column came up today. When a column is computed, it can be used in queries just like any other column and allows us to change one or more columns from the same table.]]></description><content:encoded><![CDATA[
  <p id="d0b4">A scenario that required me to add one calculated column came up today. When a column is computed, it can be used in queries just like any other column and allows us to change one or more columns from the same table.</p>
  <ul id="zgNK">
    <li id="c81c">Lets try it:</li>
  </ul>
  <pre id="nJZJ">Create One Table: tblTestComputed
CREATE TABLE tblTestComputed(
FirstName VARCHAR(50),
LastName VARCHAR(50)
)</pre>
  <ul id="smze">
    <li id="91ef">Lets insert some data into it:</li>
  </ul>
  <pre id="qdsm">INSERT INTO tblTestComputed(FirstName, LastName)
SELECT &#x27;Tejas&#x27;, &#x27;Shah&#x27;
UNION
SELECT &#x27;Hiral&#x27;, &#x27;Shah&#x27;</pre>
  <ul id="zzlx">
    <li id="5acd">So now I run:</li>
  </ul>
  <pre id="JD7P">SELECT * FROM tblTestComputed</pre>
  <ul id="WLt9">
    <li id="e536">I will get output like:</li>
  </ul>
  <h2 id="6a20"><a href="https://www.sqlyoga.com/2008/12/sql-server-how-to-add-computed-column.html" target="_blank"><strong>Output</strong></a></h2>
  <ul id="ZUey">
    <li id="d206">I now require the display name to be something like “Shah Tejas” or “Shah Hiral”. I therefore created a new column and named it:</li>
  </ul>
  <pre id="VkcJ" data-lang="sql">ALTER TABLE tblTestComputed
ADD FullName AS (ISNULL(LastName,&#x27;&#x27;) + &#x27; &#x27; + ISNULL(FirstName,&#x27;&#x27;))</pre>
  <ul id="6QYi">
    <li id="fdf1">So, now if I run:</li>
  </ul>
  <pre id="ZGAi">SELECT * FROM tblTestComputed</pre>
  <ul id="Nlah">
    <li id="8bf1">So, Output like:</li>
  </ul>
  <h2 id="9d33"><a href="https://www.sqlyoga.com/2008/12/sql-server-how-to-add-computed-column.html" target="_blank"><strong>Output</strong></a></h2>
  <ul id="HAts">
    <li id="91fd">Add a computed column called FullName to your table to combine first and last names, updating automatically.</li>
    <li id="fd7d">However, it’s essential to note that computed columns cannot be updated directly since they are derived from other columns.</li>
    <li id="1be4">For a deeper dive into computed columns and their applications, <a href="https://www.sqlyoga.com/" target="_blank">click here</a> to learn more. Join <a href="https://www.sqlyoga.com/" target="_blank">SQLYoga</a> to boost your SQL and database skills with tutorials, articles, and expert tips. Be part of a growing community of learners.</li>
  </ul>

]]></content:encoded></item></channel></rss>