<?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>SQL Tricks &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/sql-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 10:27:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>SQL Tricks &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Keyboard Query Shortcuts In SQL Server Management Studio</title>
		<link>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/</link>
					<comments>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 12 May 2016 00:00:53 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSMS]]></category>
		<category><![CDATA[Keyboard Shortcuts]]></category>
		<category><![CDATA[Query Shortcuts]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=11543</guid>

					<description><![CDATA[In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this. Background If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see some shortcuts that may be useful to you when you work with SQL Server Management Studio. You can always uses some custom queries too as query shortcuts in SSMS. Here I am going to show some most used the queries shortcuts. I hope you will like this.</p>
<p><strong>Background</strong></p>
<p>If you are a dot net developer or if you are working with any Microsoft technologies, you must have some experience in working with SQL and SQL Server Management Studio. But as a developer we always try to achieve the things in a simple manner. Isn&#8217;t it? This is where we are going for keyboard shortcuts. We do have an option to set and use the keyboard shortcuts in SSMS too. I will explain those. </p>
<p><strong>Keyboard Query Shortcuts In SSMS</strong></p>
<p>First of all let me tell you an example of where we can use the keyboard shortcuts. We know how to create stored procedures right? There procedures are created in a folder called &#8216;Stored Procedures&#8217; under Programmability. Now let us assume that I have a stored procedure with name as <em>usp_Get_SalesOrderDetail</em>. Now if you need to see the queries we have written in that stored procedure, what will you do? You have two options,</p>
<li>Right click on the stored procedure and click on modify</li>
<li>Use the sp_helptext as <em>sp_helptext usp_Get_SalesOrderDetail</em></li>
<p>Now my question is, in this scenario, whenever you need to see the stored procedure you need to type sp_helptext right? How can we overcome this situation? Here we can set the keyboard shortcuts. </p>
<p><strong>Setting the keyboard shortcuts</strong></p>
<p>Go to Tools -> Options.</p>
<div id="attachment_11544" style="width: 359px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-11544" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Tools_Options_.png" alt="Tools_Options" width="349" height="208" class="size-full wp-image-11544" srcset="/wp-content/uploads/2016/04/Tools_Options_.png 349w, /wp-content/uploads/2016/04/Tools_Options_-300x179.png 300w" sizes="(max-width: 349px) 100vw, 349px" /></a><p id="caption-attachment-11544" class="wp-caption-text">Tools_Options</p></div>
<p>Go to Environment -> Keyboard -> Query Shortcuts </p>
<div id="attachment_11545" style="width: 252px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png"><img decoding="async" aria-describedby="caption-attachment-11545" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png" alt="Environment_Keyboard_Query_Shortcuts_" width="242" height="341" class="size-full wp-image-11545" srcset="/wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_.png 242w, /wp-content/uploads/2016/04/Enviornment_Keyboard_Query_Shortcuts_-213x300.png 213w" sizes="(max-width: 242px) 100vw, 242px" /></a><p id="caption-attachment-11545" class="wp-caption-text">Environment_Keyboard_Query_Shortcuts_</p></div>
<p>On the right side you can see some shortcuts which are by default in SSMS. Now if you need to add a new one, just click on any column under Stored Procedure column.  </p>
<div id="attachment_11546" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png"><img decoding="async" aria-describedby="caption-attachment-11546" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png" alt="Adding_a_new_keyboard_shortcut" width="650" height="378" class="size-full wp-image-11546" srcset="/wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975.png 650w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-300x174.png 300w, /wp-content/uploads/2016/04/Adding_a_new_keyboard_shortcut-e1461588711975-400x233.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-11546" class="wp-caption-text">Adding_a_new_keyboard_shortcut</p></div>
<p>Click OK. Now please go to a query window and select the stored procedure then press CTRL+3, it will show the stored procedure. </p>
<div id="attachment_11547" style="width: 352px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png"><img decoding="async" aria-describedby="caption-attachment-11547" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/sp_helptext_Results_.png" alt="sp_helptext_Results_" width="342" height="441" class="size-full wp-image-11547" srcset="/wp-content/uploads/2016/04/sp_helptext_Results_.png 342w, /wp-content/uploads/2016/04/sp_helptext_Results_-233x300.png 233w" sizes="(max-width: 342px) 100vw, 342px" /></a><p id="caption-attachment-11547" class="wp-caption-text">sp_helptext_Results_</p></div>
<p>No if you need to select all the records from a table when you select the table and press CTRL+5(You can select any key). You can make the shortcut as follows. </p>
<div id="attachment_11548" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-e1461589819987.png"><img decoding="async" aria-describedby="caption-attachment-11548" src="http://sibeeshpassion.com/wp-content/uploads/2016/04/Selct_Query_As_Keyboard_Shortcut-1024x438.png" alt="Selct_Query_As_Keyboard_Shortcut" width="634" height="271" class="size-large wp-image-11548" /></a><p id="caption-attachment-11548" class="wp-caption-text">Selct_Query_As_Keyboard_Shortcut</p></div>
<p>Now please go ahead and select the table name from the query window and press CTRL+4(The key we selected). I hope you got the result as expected. Have a happy coding!.</p>
<p><strong>Conclusion</strong></p>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/keyboard-query-shortcuts-in-sql-server-management-studio/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solution for saving changes not permitted error in SQL</title>
		<link>https://sibeeshpassion.com/solution-for-saving-changes-not-permitted-error-in-sql/</link>
					<comments>https://sibeeshpassion.com/solution-for-saving-changes-not-permitted-error-in-sql/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 29 Jun 2015 08:07:06 +0000</pubDate>
				<category><![CDATA[Q&A]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Errors]]></category>
		<category><![CDATA[sql table design error]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<category><![CDATA[table design]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=5461</guid>

					<description><![CDATA[Introduction Hi All, How are you today? In this article we will see a solution for a fix that we usually encounter when you work in Microsoft SQL server. The error message will be &#8220;Saving changes is not permitted,The changes you have made require the following table to be dropped and re-created. You have either made changes to the table that can&#8217;t be re-created or enabled the option Prevent saving changes that require the table to be re-created.&#8221;. Let us see how we can solve this issue. I hope you will like it. Background As the error message says, it [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>Hi All, How are you today? In this article we will see a solution for a fix that we usually encounter when you work in Microsoft SQL server. The error message will be <em>&#8220;Saving changes is not permitted,The changes you have made require the following table to be dropped and re-created. You have either made changes to the table that can&#8217;t be re-created or enabled the option Prevent saving changes that require the table to be re-created.&#8221;</em>. Let us see how we can solve this issue. I hope you will like it.</p>
<p><strong>Background</strong></p>
<p>As the error message says, it is because of you have enabled the option Prevent saving changes. Now we will see how we can disable that option in SQL Server Management Studio. Before going through the fix, we will see teh screenshot of the error.</p>
<p><img decoding="async" src="http://www.sibeeshpassion.com/content/images/tab1.png" alt="www.sibeeshpassion.com" /></p>
<p><strong>Steps to follow</strong></p>
<p>To fix this issue, you need to follow some certain steps. We will explain that here.</p>
<p><em><strong>Step 1</strong></em></p>
<p>Go to Tools menu and click on options.</p>
<p><img decoding="async" src="http://www.sibeeshpassion.com/content/images/tab2.png" alt="www.sibeeshpassion.com" /></p>
<p><em><strong>Step 2</strong></em></p>
<p>Now you can see a window is opened as follows. You can see some settings there. No need to change anything in that.</p>
<p><img decoding="async" src="http://www.sibeeshpassion.com/content/images/tab3.png" alt="www.sibeeshpassion.com" /></p>
<p><em><strong>Step 3</strong></em></p>
<p>Now go to Designers menu and click on &#8220;Table and Database designers&#8221; </p>
<p><img decoding="async" src="http://www.sibeeshpassion.com/content/images/tab4.png" alt="www.sibeeshpassion.com" /></p>
<p><em><strong>Step 4</strong></em></p>
<p>It is time for changing the settings. As you can see there is a check box which is captioned as <em>&#8220;Prevent saving changes that requires table re-creation&#8221;</em> . Just uncheck that and click OK.</p>
<p><img decoding="async" src="http://www.sibeeshpassion.com/content/images/tab5.png" alt="www.sibeeshpassion.com" /></p>
<p>That is all. Now if you try to save that table, you won&#8217;t be facing above mentioned issue. Have a happy table designing.</p>
<p><strong>Conclusion</strong></p>
<p>I hope you will like this article. Please share me your valuable thoughts and comments. Your feedback is always welcomed.</p>
<p>Thanks in advance. Happy coding!</p>
<p>Kindest Regards<br />
<a href="https://plus.google.com/+sibeeshkv" target="_blank">Sibeesh Venu</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/solution-for-saving-changes-not-permitted-error-in-sql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Tips and Tricks</title>
		<link>https://sibeeshpassion.com/sql-server-tips-and-tricks/</link>
					<comments>https://sibeeshpassion.com/sql-server-tips-and-tricks/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 29 Dec 2014 19:23:14 +0000</pubDate>
				<category><![CDATA[Microsoft Technologies]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Performance Hints]]></category>
		<category><![CDATA[SQL Queries]]></category>
		<category><![CDATA[SQL Tips]]></category>
		<category><![CDATA[SQL Tricks]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=651</guid>

					<description><![CDATA[Introduction This article provides some tricks we may use in our day-to-day programming life in SQL. Background Right now, I am handling a software product in my office. The back end used in that project is SQL Server 2008, that have more than 250 tables and consists around cores of data. :). So I used to spend a lot of time in the queries to do some backend fixes. So I thought to share those with you all. Performance check hints in SQL A. To check for a missing Index, duplicate Index and unused index in the live db and [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>This article provides some tricks we may use in our day-to-day programming life in SQL.</p>
<p><strong>Background</strong></p>
<p>Right now, I am handling a software product in my office. The back end used in that project is SQL Server 2008, that have more than 250 tables and consists around cores of data. :). So I used to spend a lot of time in the queries to do some backend fixes. So I thought to share those with you all.</p>
<p><strong>Performance check hints in SQL</strong></p>
<p>A. To check for a missing Index, duplicate Index and unused index in the live db and appropriately drop and create the index, when doing this, check the execution plan, the SQL cost based optimizer will provide information about the missing index.</p>
<p>B. Review whether the index is required based on the predicator that is used in the query and appropriately creates or drops.</p>
<p>C. Try to use join conditions instead of a sub query.</p>
<p>Try this in one place and check the execution plan. If an improvement is found, do the same thing everwhere else.</p>
<p>D. The problem in the query would be:</p>
<p>Too many connections are made using a sub-query and indexing issue.<br />
E. Check whether the predicator column (Condition Column) is a clustered index, if not, see the feasibility for creating it.</p>
<p>F. If the where condition is based on multiple columns, analyze the multiple condition and create a non-clustered index for it, check the execution plan when doing it, there should not be any table scan, clustered scan, non-clustered scan.</p>
<p>G. In the execution plan, every predicator should be done using a seek operation.</p>
<p>Note: You can get the query from the internet for checking for a missing index, duplicate index and unused index.</p>
<p>Here I am posting some other techniques also. Enjoy programming!!!</p>
<p><strong>1.To Get the primary key</strong><br />
[sql]<br />
Select column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), ‘IsPrimaryKey’) = 1 AND table_name =yourtablename<br />
[/sql]</p>
<p><strong>2. To find what all the tables are that have a specific column</strong><br />
[sql]<br />
select * from sysobjects where id in(select id from syscolumns where name like ‘%your perticular column name%’) and xtype=‘u’<br />
[/sql]</p>
<p><strong>3. How to remove a constraint in a table in SQL Server</strong></p>
<p>Assume we want to drop the UNIQUE constraint on the “Address” column and the name of the constraint is “Con_First”. To do this, we type in the following:</p>
<p><strong>MySQL</strong>:<br />
[sql]<br />
ALTER TABLE Customer DROP INDEX Con_First;<br />
Note that MySQL uses DROP INDEX for index-type constraints such as UNIQUE.<br />
[/sql]</p>
<p><strong>Oracle</strong>:<br />
[sql]<br />
ALTER TABLE Customer DROP CONSTRAINT Con_First;<br />
[/sql]</p>
<p><strong>SQL Server</strong>:<br />
[sql]<br />
ALTER TABLE Customer DROP CONSTRAINT Con_First;<br />
[/sql]</p>
<p><strong>4. Kill transaction in SQL</strong><br />
[sql]<br />
SELECT * FROM master..sysprocesses where open_tran&gt;0<br />
kill Transavtion Id<br />
[/sql]</p>
<p><strong>5. Insert from one db to other in SQL</strong><br />
[sql]<br />
INSERT INTO TOTable<br />
SELECT * FROM [FromDB].[dbo].[FromTable]<br />
[/sql]</p>
<p><strong>6. Get the table count in a DB</strong><br />
[sql]<br />
select * from sys.tables where is_ms_shipped=‘0’<br />
[/sql]</p>
<p><strong>7. Get the count of entries in each table in a db</strong><br />
[sql]<br />
SELECT<br />
    sysobjects.Name<br />
    , sysindexes.Rows<br />
FROM<br />
    sysobjects<br />
    INNER JOIN sysindexes<br />
    ON sysobjects.id = sysindexes.id<br />
WHERE<br />
    type = ‘U’<br />
    AND sysindexes.IndId &lt; 2<br />
ORDER BY<br />
    sysobjects.Name<br />
[/sql]</p>
<p><strong>8. Find all the tables with a set identity</strong><br />
[sql]<br />
select COLUMN_NAME, TABLE_NAME<br />
from INFORMATION_SCHEMA.COLUMNS<br />
where TABLE_SCHEMA = ‘dbo’<br />
and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, ‘IsIdentity’) = 1<br />
order by TABLE_NAME<br />
[/sql]</p>
<p><strong>9. Find the relationships between tables</strong><br />
[sql]<br />
SELECT f.name AS ForeignKey,<br />
SCHEMA_NAME(f.SCHEMA_ID) SchemaName,<br />
OBJECT_NAME(f.parent_object_id) AS TableName,<br />
COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,<br />
SCHEMA_NAME(o.SCHEMA_ID) ReferenceSchemaName,<br />
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,<br />
COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName<br />
FROM sys.foreign_keys AS f<br />
INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id<br />
INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id<br />
[/sql]</p>
<p><strong>10. Find the relationship difference between two dbs</strong></p>
<p>Run the following in your first DB.<br />
[sql]<br />
SELECT f.name AS ForeignKey<br />
FROM sys.foreign_keys AS f where f.name not in<br />
(SELECT f.name AS ForeignKey<br />
FROM your second DB name.sys.foreign_keys AS f)order by f.name asc<br />
[/sql]</p>
<p><strong>11. Determine the Missing Indexes</strong><br />
[sql]<br />
SELECT<br />
  d.[object_id],<br />
  s = OBJECT_SCHEMA_NAME(d.[object_id]),<br />
  o = OBJECT_NAME(d.[object_id]),<br />
  d.equality_columns,<br />
  d.inequality_columns,<br />
  d.included_columns,<br />
  s.unique_compiles,<br />
  s.user_seeks, s.last_user_seek,<br />
  s.user_scans, s.last_user_scan<br />
INTO #missingindexes<br />
FROM sys.dm_db_missing_index_details AS d<br />
INNER JOIN sys.dm_db_missing_index_groups AS g<br />
ON d.index_handle = g.index_handle<br />
INNER JOIN sys.dm_db_missing_index_group_stats AS s<br />
ON g.index_group_handle = s.group_handle<br />
WHERE d.database_id = DB_ID()<br />
AND OBJECTPROPERTY(d.[object_id], ‘IsMsShipped’) = 0;<br />
select * from #missingindexes<br />
[/sql]</p>
<p><strong>12. Get the column name of each table in a DB in SQL</strong><br />
[sql]<br />
SELECT T.NAME AS [TABLE NAME], C.NAME AS [COLUMN NAME],<br />
P.NAME AS [DATA TYPE], P.MAX_LENGTH AS[SIZE],<br />
CAST(P.PRECISION AS VARCHAR) +‘/’+ CAST(P.SCALE AS VARCHAR) AS<br />
[PRECISION/SCALE]<br />
FROM SYS.OBJECTS AS T JOIN SYS.COLUMNS AS C ON<br />
T.OBJECT_ID=C.OBJECT_ID JOIN<br />
SYS.TYPES AS P ON C.SYSTEM_TYPE_ID=P.SYSTEM_TYPE_ID WHERE<br />
T.TYPE_DESC=‘USER_TABLE’;<br />
                                                    OR<br />
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME,<br />
ORDINAL_POSITION, COLUMN_DEFAULT, DATA_TYPE,<br />
CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION,<br />
NUMERIC_PRECISION_RADIX, NUMERIC_SCALE, DATETIME_PRECISION<br />
FROM  INFORMATION_SCHEMA.COLUMNS<br />
[/sql]</p>
<p>Let’s code now.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/sql-server-tips-and-tricks/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
