<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>T-SQLpowered &#8211; SQLpowered.com</title>
	<atom:link href="https://sqlpowered.com/category/t-sqlpowered/feed/" rel="self" type="application/rss+xml" />
	<link>https://sqlpowered.com</link>
	<description>SQL Server + BI</description>
	<lastBuildDate>Thu, 24 Jul 2025 08:54:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://sqlpowered.com/wp-content/uploads/2020/07/FavIcon-e1594067873682-99x100.png</url>
	<title>T-SQLpowered &#8211; SQLpowered.com</title>
	<link>https://sqlpowered.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Constraints</title>
		<link>https://sqlpowered.com/t-sql-commands/constraints/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Thu, 24 Jul 2025 08:53:22 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5751</guid>

					<description><![CDATA[Add default constraint to column inline: ALTER TABLE [dbo].[SampleTable] ADD Is_Archived BIT NOT NULL CONSTRAINT DF_dbo_Sample_Table_Is_Archived DEFAULT 0 ALTER TABLE [dbo].[SampleTable] ADD Is_Cleaned_Up BIT CONSTRAINT DF_dbo_Sample_Table_Is_Archived DEFAULT 0 NOT NULL &#160;]]></description>
										<content:encoded><![CDATA[<p>Add default constraint to column inline:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">ALTER TABLE [dbo].[SampleTable] ADD Is_Archived BIT NOT NULL CONSTRAINT DF_dbo_Sample_Table_Is_Archived DEFAULT 0 

ALTER TABLE [dbo].[SampleTable] ADD Is_Cleaned_Up BIT CONSTRAINT DF_dbo_Sample_Table_Is_Archived DEFAULT 0 NOT NULL</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>VALUES</title>
		<link>https://sqlpowered.com/t-sql-commands/values/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 22 Jul 2025 11:23:26 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5749</guid>

					<description><![CDATA[SELECT from VALUES: SELECT * FROM (VALUES (1), (2)) a (Id) &#160;]]></description>
										<content:encoded><![CDATA[<p>SELECT from VALUES:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT * FROM (VALUES (1), (2)) a (Id)</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>WHILE</title>
		<link>https://sqlpowered.com/t-sql-commands/while/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 15 Jun 2024 08:11:23 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5699</guid>

					<description><![CDATA[Iterate with MIN/MAX Id. Doesn&#8217;t perform well for broken number sequences. DECLARE @Current_Id INT DECLARE @Max_Id INT DECLARE @Ids TABLE ( [Id] INT) INSERT INTO @Ids ([Id]) SELECT [Id] FROM (VALUES (1),(2),(3)) [v] ([Id]) SELECT @Current_Id = MIN([Id]) FROM @Ids SELECT @Max_Id = MAX([Id]) FROM @Ids WHILE @Current_Id &#60;= @Max_Id...]]></description>
										<content:encoded><![CDATA[<p>Iterate with MIN/MAX Id. Doesn&#8217;t perform well for broken number sequences.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">DECLARE @Current_Id INT
DECLARE @Max_Id INT
DECLARE @Ids TABLE ( [Id] INT)

INSERT INTO @Ids ([Id])
	SELECT [Id]
	FROM (VALUES (1),(2),(3)) [v] ([Id])

SELECT @Current_Id = MIN([Id]) FROM @Ids
SELECT @Max_Id = MAX([Id]) FROM @Ids

WHILE @Current_Id &lt;= @Max_Id
BEGIN

    SELECT 
		@Current_Id = [Id]
    FROM @Ids
    WHERE [Id] = @Current_Id

    PRINT @Current_Id

    SET @Current_Id = @Current_Id + 1

END
GO</pre>
<p>Iterate as long as there is a row to be processed. May have performance impact for large set of ids.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">DECLARE @Id INT
DECLARE @Ids TABLE ( [Id] INT)

INSERT INTO @Ids ([Id])
	SELECT 
        [Id]
	FROM (VALUES (1),(2),(3)) [v] ([Id])

WHILE EXISTS (SELECT * FROM @Ids)
BEGIN
    
    SELECT TOP(1)
		@Id = [Id]
    FROM @Ids
    ORDER BY Id

    RAISERROR('%i', 10, 1, @Id) WITH NOWAIT

    DELETE FROM @Ids WHERE Id = @Id

END
GO</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Basic operations</title>
		<link>https://sqlpowered.com/t-sql-commands/strings/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sat, 15 Apr 2023 22:34:59 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5638</guid>

					<description><![CDATA[Split long string to multiple lines (\ separator): SELECT 'abc\ def' AS [Result]; SELECT 0xabc\ def AS [Result]; &#160;]]></description>
										<content:encoded><![CDATA[<p>Split long string to multiple lines (\ separator):</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">SELECT 'abc\
def' AS [Result];

SELECT 0xabc\
def AS [Result];</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>CREATE TABLE</title>
		<link>https://sqlpowered.com/t-sql-commands/create-table/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 09:03:40 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5524</guid>

					<description><![CDATA[Create Table with clustered Primary Key on Identity column: CREATE TABLE [dbo].[SampleTable] ( [Id] INT IDENTITY (1,1) NOT NULL, CONSTRAINT [PK_SampleTable] PRIMARY KEY CLUSTERED ([Id]) ) &#160;]]></description>
										<content:encoded><![CDATA[<p>Create Table with clustered Primary Key on Identity column:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">CREATE TABLE [dbo].[SampleTable] (
	[Id] INT IDENTITY (1,1) NOT NULL,
	CONSTRAINT [PK_SampleTable] PRIMARY KEY CLUSTERED ([Id])
)</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Table Type</title>
		<link>https://sqlpowered.com/t-sql-commands/table-type/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Thu, 17 Feb 2022 07:44:30 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5451</guid>

					<description><![CDATA[Declare with PK constraint, insert and retrieve data: CREATE TYPE [dbo].[utt_Generic_Int] AS TABLE ( [Id] [INT] NOT NULL PRIMARY KEY CLUSTERED ) GO DECLARE @Ids utt_Generic_Int INSERT INTO @Ids ( [Id] ) VALUES (1), (2), (3) SELECT * FROM @Ids GO &#160;]]></description>
										<content:encoded><![CDATA[<p>Declare with PK constraint, insert and retrieve data:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">CREATE TYPE [dbo].[utt_Generic_Int] AS TABLE
(
	[Id] [INT] NOT NULL PRIMARY KEY CLUSTERED 
)
GO

DECLARE @Ids utt_Generic_Int

INSERT INTO @Ids
	( [Id] )
VALUES
	(1), (2), (3) 
	
SELECT *
FROM @Ids
GO</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Configuration (sp_configure)</title>
		<link>https://sqlpowered.com/t-sql-commands/configuration-sp_configure/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Mon, 17 Jan 2022 11:34:08 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5352</guid>

					<description><![CDATA[Show advanced options: USE [master] GO EXEC [sys].[sp_configure] 'Show advanced options',1 GO RECONFIGURE WITH OVERRIDE GO]]></description>
										<content:encoded><![CDATA[<p>Show advanced options:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">USE [master]
GO
EXEC [sys].[sp_configure] 'Show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Jobs</title>
		<link>https://sqlpowered.com/t-sql-commands/jobs/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Tue, 04 Jan 2022 10:00:54 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5313</guid>

					<description><![CDATA[Enable/Disable job: -- enable EXEC msdb.dbo.sp_update_job @job_name='SampleJobName', @enabled = 1 -- disable EXEC msdb.dbo.sp_update_job @job_name='SampleJobName', @enabled = 0 &#160; &#160;]]></description>
										<content:encoded><![CDATA[<p>Enable/Disable job:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">-- enable
EXEC msdb.dbo.sp_update_job @job_name='SampleJobName', @enabled = 1
-- disable
EXEC msdb.dbo.sp_update_job @job_name='SampleJobName', @enabled = 0</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MERGE</title>
		<link>https://sqlpowered.com/t-sql-commands/merge/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 31 Dec 2021 20:20:41 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5298</guid>

					<description><![CDATA[Using OUTPUT clause: MERGE INTO [dbo].[TargetTable] [trg] USING ( SELECT [ID], [Value], [OtherValue] FROM [dbo].[SourceTable] ) AS [src] ON 1 = 0 WHEN NOT MATCHED THEN INSERT ( [ID],[Value] ) VALUES ([src].[ID], [src].[Value]) OUTPUT [Inserted].[ID], [Inserted].[Value], [src].[OtherValue] &#160;]]></description>
										<content:encoded><![CDATA[<p>Using OUTPUT clause:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">MERGE INTO [dbo].[TargetTable] [trg]
USING ( SELECT [ID], [Value], [OtherValue]
		FROM [dbo].[SourceTable]
	  ) AS [src] ON 1 = 0
WHEN NOT MATCHED THEN
	INSERT ( [ID],[Value] )
	VALUES ([src].[ID], [src].[Value])
		OUTPUT [Inserted].[ID], [Inserted].[Value], [src].[OtherValue]</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>UPDATE</title>
		<link>https://sqlpowered.com/t-sql-commands/update/</link>
		
		<dc:creator><![CDATA[Jan Dvořák]]></dc:creator>
		<pubDate>Fri, 31 Dec 2021 20:09:38 +0000</pubDate>
				<category><![CDATA[T-SQLpowered]]></category>
		<guid isPermaLink="false">https://sqlpowered.com/?post_type=t-sql-commands&#038;p=5293</guid>

					<description><![CDATA[Update with the expression: UPDATE [dbo].[SampleTable] SET [Col1] = @a + @b + @c Update using the .WRITE() clause: UPDATE [dbo].[SampleTable] SET [Col1].WRITE('New Value, 0, NULL) UPDATE [dbo].[SampleTable] SET [Col1].WRITE(@a + @b + @c, 0, NULL) UPDATE [dbo].[SampleTable] SET [Col1].WRITE(@x, 500, 1000) &#160;]]></description>
										<content:encoded><![CDATA[<p>Update with the expression:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">UPDATE [dbo].[SampleTable] SET [Col1] = @a + @b + @c
</pre>
<p>Update using the .WRITE() clause:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="sql">UPDATE [dbo].[SampleTable] SET [Col1].WRITE('New Value, 0, NULL)
UPDATE [dbo].[SampleTable] SET [Col1].WRITE(@a + @b + @c, 0, NULL)
UPDATE [dbo].[SampleTable] SET [Col1].WRITE(@x, 500, 1000)</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
