<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5127798429426738073</id><updated>2024-12-18T19:31:40.295-08:00</updated><category term="Interview Questions"/><category term="Sql Server"/><category term="SQL Index"/><category term="Primary Keys"/><category term="Sql Optimization"/><category term="Sql Server Errors"/><category term="Unique Keys"/><category term="Collation"/><category term="Delete"/><category term="Functions"/><category term="Fuzzy Search"/><category term="Soundex Search"/><category term="Stored Procedures"/><category term="System Database"/><category term="Candidate Keys"/><category term="Error Actions"/><category term="Error Handling"/><category term="Find And Replace"/><category term="Identity"/><category term="Master Database"/><category term="Model Database"/><category term="New Features"/><category term="Normalization"/><category term="Null"/><category term="Resource Database"/><category term="SQL Cursors"/><category term="SQL Views"/><category term="SubQuery"/><category term="Truncate"/><category term=".net"/><category term="ACID"/><category term="Alternate keys"/><category term="Avoid Duplicate Entry"/><category term="CHARINDEX"/><category term="CTE"/><category term="Clustered Index"/><category term="CommaSeparated"/><category term="Composite keys"/><category term="DBCC Commands"/><category term="DDL"/><category term="DML"/><category term="DMV/DMF"/><category term="DataWareHousing"/><category term="Database Mirroring"/><category term="DateTime"/><category term="Do&#39;s and Don&#39;ts in Sys Databases"/><category term="Duplicate Records"/><category term="Foreign Keys"/><category term="Group By Clause"/><category term="Having Clause"/><category term="IndexOf"/><category term="Inline Table UDF"/><category term="Linked Server"/><category term="Locking"/><category term="MERGE Statement"/><category term="MSDB Database"/><category term="Multi Statement UDF"/><category term="MySQL"/><category term="New in 2008"/><category term="NonClustered Index"/><category term="OLEDB"/><category term="RDBMS"/><category term="RaiseError"/><category term="Ranking Functions"/><category term="Reading/Writing Files"/><category term="Recursive SP"/><category term="Remove HTMLtags"/><category term="Remove Spaces"/><category term="Remove the string"/><category term="Replication"/><category term="Roles"/><category term="SCOPE_IDENTITY"/><category term="SQL Agent"/><category term="SQL Alias"/><category term="SQL Governer"/><category term="SQL Joins"/><category term="SQL Profiler"/><category term="SQL pages"/><category term="Scaler UDF"/><category term="Security"/><category term="Sql Grant"/><category term="Stored Procedure return type"/><category term="TempDB DataBase"/><category term="Temporary Tables"/><category term="Transaction"/><category term="User Defined Datatypes"/><category term="VARCHAR vs TEXT"/><category term="WaitFor"/><category term="XML DataType"/><category term="XML to Sql"/><category term="columns"/><category term="database"/><category term="drop"/><category term="footprint"/><category term="memory"/><category term="parameters"/><category term="process"/><category term="rowcount"/><category term="shell script"/><category term="tables"/><category term="trancount"/><category term="triggers"/><title type='text'>Sql Code Masterz</title><subtitle type='html'>This blog is for developers, they can find answers to some very common and little problems but time consuming ones. If they are missing a logic or are just a step behind, this blog will surely help you achieve. Some very useful and time saving sql queries and much more....</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>103</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-32500799564178803</id><published>2013-10-23T03:55:00.001-07:00</published><updated>2013-10-23T03:55:17.351-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DDL"/><category scheme="http://www.blogger.com/atom/ns#" term="Delete"/><category scheme="http://www.blogger.com/atom/ns#" term="DML"/><category scheme="http://www.blogger.com/atom/ns#" term="Transaction"/><category scheme="http://www.blogger.com/atom/ns#" term="Truncate"/><title type='text'>What is difference between DELETE and TRUNCATE commands? </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Delete command removes the rows from a table based on the condition that we 
provide with a WHERE clause. Truncate will actually remove all the rows from a 
table and there will be no data in the table after we run the truncate command. 
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;TRUNCATE&lt;/b&gt;: &lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;TRUNCATE is faster and uses fewer system and transaction log resources than DELETE. TRUNCATE removes the data by deallocating the data pages used to store the table&#39;s data, and only the page deallocations are recorded in the transaction log. &lt;/li&gt;
&lt;li&gt;TRUNCATE removes all rows from a table, but the table structure, its columns, constraints, indexes and so on, remains. &lt;/li&gt;
&lt;li&gt;The counter used by an identity for new rows is reset to the seed for the column. &lt;/li&gt;
&lt;li&gt;You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint. Because TRUNCATE TABLE is not logged, it cannot activate a trigger. &lt;/li&gt;
&lt;li&gt;TRUNCATE cannot be rolled back. &lt;/li&gt;
&lt;li&gt;TRUNCATE is DDL Command. &lt;/li&gt;
&lt;li&gt;TRUNCATE Resets identity of the table &lt;/li&gt;
&lt;/ul&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;DELETE&lt;/b&gt;: &lt;/li&gt;
&lt;/ol&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;DELETE removes rows one at a time and records an entry in the transaction log for each deleted row. If you want to retain the identity counter, use DELETE instead. &lt;/li&gt;
&lt;li&gt;If you want to remove table definition and its data, use the DROP TABLE statement. &lt;/li&gt;
&lt;li&gt;DELETE Can be used with or without a WHERE clause &lt;/li&gt;
&lt;li&gt;DELETE Activates Triggers. &lt;/li&gt;
&lt;li&gt;DELETE can be rolled back.&lt;/li&gt;
&lt;li&gt;DELETE is DML Command.&lt;/li&gt;
&lt;li&gt;DELETE does not reset identity of the table. &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Note: DELETE and TRUNCATE both can be rolled back when surrounded by TRANSACTION if the current session is not closed. If TRUNCATE is written in Query Editor surrounded by TRANSACTION and if session is closed, it can not be rolled back but DELETE can be rolled back.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/32500799564178803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-is-difference-between-delete-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/32500799564178803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/32500799564178803'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-is-difference-between-delete-and.html' title='What is difference between DELETE and TRUNCATE commands? '/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-4999979325106011451</id><published>2013-10-23T03:45:00.000-07:00</published><updated>2013-10-23T03:45:19.395-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Primary Keys"/><category scheme="http://www.blogger.com/atom/ns#" term="Unique Keys"/><title type='text'>What&#39;s the difference between a primary key and a unique key?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Both primary key and unique key enforces uniqueness of the column on which 
they are defined. &lt;br /&gt;
&lt;br /&gt;
But by default &lt;strong&gt;primary key creates a clustered index&lt;/strong&gt; on the 
column, where are &lt;strong&gt;unique creates a nonclustered index&lt;/strong&gt; by default. &lt;br /&gt;
&lt;br /&gt;
Another major 
difference is that, &lt;strong&gt;primary key doesn&#39;t allow NULLs&lt;/strong&gt;, but &lt;strong&gt;unique key allows one 
NULL only&lt;/strong&gt;.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/4999979325106011451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/whats-difference-between-primary-key.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4999979325106011451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4999979325106011451'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/whats-difference-between-primary-key.html' title='What&#39;s the difference between a primary key and a unique key?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-1124391524684525383</id><published>2013-10-23T03:42:00.003-07:00</published><updated>2013-10-23T03:42:51.740-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Collation"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><title type='text'>What are different types of Collation Sensitivity? </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Case sensitivity&lt;/b&gt; - A and a, B and b, etc. &lt;/div&gt;
&lt;/li&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;li&gt;&lt;div class=&quot;tech-answer&quot; style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Accent sensitivity&lt;/b&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;div class=&quot;tech-answer&quot; style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;li&gt;&lt;div class=&quot;tech-answer&quot; style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Kana Sensitivity&lt;/b&gt; - When Japanese kana characters Hiragana and Katakana are treated differently, it is called Kana sensitive. &lt;/div&gt;
&lt;/li&gt;
&lt;div class=&quot;tech-answer&quot; style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;li&gt;&lt;div class=&quot;tech-answer&quot; style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Width sensitivity&lt;/b&gt; - A single-byte character (half-width) and the same character represented as a double-byte character (full-width) are treated differently than it is width sensitive. &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/1124391524684525383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-are-different-types-of-collation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1124391524684525383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1124391524684525383'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-are-different-types-of-collation.html' title='What are different types of Collation Sensitivity? '/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-7276963330787791037</id><published>2013-10-23T03:40:00.001-07:00</published><updated>2013-10-23T03:41:54.371-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clustered Index"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="NonClustered Index"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Index"/><title type='text'>What are the different index configurations a table can have? </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
A table can have one of the following index configurations: 
&lt;br /&gt;
&lt;div class=&quot;tech-answer&quot;&gt;
&lt;ol class=&quot;tech-ol-123&quot;&gt;
&lt;li&gt;No indexes&amp;nbsp;
&lt;li&gt;A clustered index
&lt;li&gt;A clustered index and many nonclustered indexes
&lt;li&gt;A nonclustered index
&lt;li&gt;Many nonclustered indexes &lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/7276963330787791037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-are-different-index-configurations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/7276963330787791037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/7276963330787791037'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2013/10/what-are-different-index-configurations.html' title='What are the different index configurations a table can have? '/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-3636869801268315485</id><published>2012-09-11T20:47:00.000-07:00</published><updated>2012-09-11T20:51:53.635-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DMV/DMF"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Schema Binding and Indexed Views in SQL Server </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;Problem&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Recently while creating an archival job I noticed that job was taking way too long to complete. To help troubleshoot I executed the stored procedure directly and it was also taking a long time to fetch the rows from the view that I was using. Based on the query plan it looked like creating an index on the view may help the issue, so I first looked to see if any indexes were in place for the views, but none were found. The next step was to create an index on the view, but I was presented with this error message &quot;Cannot create index on view, because the view is not schema bound&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Solution&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The error message &quot;Cannot create index on view &#39;*&#39; because the view is not schema bound. (Microsoft SQL Server, Error: 1939)&quot; clearly suggested that in order to create an index on this view I have to make it schema bound, but what is schema binding and how does this work? Schema binding ties an object to the base object that this new object depends upon. So without schema binding if a view is created and the underlying table is changed, the view may break, but the table change can still occur. With schema binding, if the base object is bound to another object, you will not be able to modify the based object unless you drop or alter the object to remove the schema binding. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In SQL Server, views are not bound to the schema of the base tables by default. In such case we may change the schema of the base table at any time, regardless of the fact that the associated view may or may not work with the new schema. We can even drop the underlying table while keeping the associated view without any warning. In this case when the view is used, we will get an invalid object name error for the base table. &lt;br /&gt;
So if you want to create an index on a view or you want to preserve the base table schema once a view has been defined, in both these cases you have to use the &quot;WITH SCHEMABINDING&quot; clause to bind the view to the schema of the base tables. &lt;br /&gt;
To use schema binding for views, first we will create a sample table in AdventureWorks database then a view &quot;vw_sampleView&quot; is created on this new table.&lt;br /&gt;
Create sample table and sample view &lt;br /&gt;
&lt;br /&gt;
USE AdventureWorks &lt;br /&gt;
&lt;br /&gt;
GO &lt;br /&gt;
&lt;br /&gt;
SELECT * INTO SampleTable &lt;br /&gt;
&lt;br /&gt;
FROM sales.SalesOrderDetail &lt;br /&gt;
&lt;br /&gt;
GO &lt;br /&gt;
&lt;br /&gt;
CREATE VIEW [dbo].[vw_sampleView] WITH SCHEMABINDING AS &lt;br /&gt;
&lt;br /&gt;
SELECT salesorderid, productid, unitprice, linetotal, rowguid,modifieddate &lt;br /&gt;
&lt;br /&gt;
FROM dbo.SAMPLETABLE &lt;br /&gt;
&lt;br /&gt;
GO &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--If the view already existed we could use this to add SCHEMABINDING &lt;br /&gt;
&lt;br /&gt;
ALTER VIEW [dbo].[vw_sampleView] WITH SCHEMABINDING AS &lt;br /&gt;
&lt;br /&gt;
SELECT salesorderid, productid, unitprice, linetotal, rowguid,modifieddate &lt;br /&gt;
&lt;br /&gt;
FROM dbo.SAMPLETABLE &lt;br /&gt;
&lt;br /&gt;
GO &lt;br /&gt;
Be aware that if you do not use the schema name, (dbo) in this case, then you will get the following error while creating the view. &quot;Cannot schema bind view &#39;dbo.vw_sampleView&#39; because name &#39;SAMPLETABLE&#39; is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.&quot; &lt;br /&gt;
This error is only generated in case of schema bound views. In the case of ordinary views you will not get this error. &lt;br /&gt;
So here we are with a SCHEMABOUND view &quot;sampleView&quot; on base table &quot;sampleTable&quot;. Now we will check that we are able to create an index on the view.&lt;br /&gt;
&lt;br /&gt;
An important point to note is that you must first create a unique clustered index on the view, before you can create any non-clustered indexes. The script below shows us how we can create this unique clustered index or you can do this via SQL Server Management Studio (SSMS).&lt;br /&gt;
Create Unique clustered index on view &lt;br /&gt;
&lt;br /&gt;
CREATE UNIQUE CLUSTERED INDEX [TestIndex] ON [dbo].[vw_sampleView] &lt;br /&gt;
&lt;br /&gt;
( &lt;br /&gt;
&lt;br /&gt;
[rowguid] ASC &lt;br /&gt;
&lt;br /&gt;
) &lt;br /&gt;
&lt;br /&gt;
GO &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When this is run the command successfully creates the unique clustered index &quot;TestIndex&quot; on &quot;vw_sampleview&quot;. At this point we can add any additional indexes as needed.&lt;br /&gt;
Here are some things to consider:&lt;br /&gt;
You can not create an index on a view with outer joins used in it, even if you use schema binding &lt;br /&gt;
&lt;br /&gt;
You can not use &#39;*&#39; in the select statement of a view when it is schema bound. In such case you will clearly get error message of level 15 as &quot;Syntax &#39;*&#39; is not allowed in schema-bound objects.&quot;. &lt;br /&gt;
&lt;br /&gt;
You will not be able to create clustered index on a view if the view references any nondeterministic functions. &lt;br /&gt;
&lt;br /&gt;
You can not use aggregate functions when using schema binding. &lt;br /&gt;
&lt;br /&gt;
You can not migrate the base table of a schema bound view.&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
Now we are left with our second part of the problem, how schema preservation is implemented for the base table. Again we have our &quot;sampleTable&quot; and &quot;vw_sampleView&quot; with schema binding. We know that without schema binding there was no issue to alter or drop the base table without any type of warning or error. Now if we try to alter the table structure or drop the table, we are going to get this error message.&lt;br /&gt;
&lt;br /&gt;
By using SSMS to alter the data type of a column in the base table&quot;sampleTable&quot;, I get a warning message notifying me that because of the schema bound view this will not work. &lt;br /&gt;
&lt;br /&gt;
To change the base table we need to remove the SCHEMABINDING option from our objects or drop and recreate these objects once the table has been altered.&lt;br /&gt;
&lt;br /&gt;
On the other hand schema binding does not implement any restriction on the alteration of the view. You may alter or drop the view the same way as you normally would. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ref :-&amp;nbsp; &lt;a href=&quot;http://www.mssqltips.com/sqlservertip/1610/sql-server-schema-binding-and-indexed-views/&quot;&gt;http://www.mssqltips.com/sqlservertip/1610/sql-server-schema-binding-and-indexed-views/&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/3636869801268315485/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/09/schema-binding-and-indexed-views-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3636869801268315485'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3636869801268315485'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/09/schema-binding-and-indexed-views-in-sql.html' title='Schema Binding and Indexed Views in SQL Server '/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-4898111735004832884</id><published>2012-09-05T23:02:00.001-07:00</published><updated>2012-09-05T23:02:31.621-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Ranking Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Which of the following ranking functions distribute the rows in an ordered partition into a specified number of groups</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Which of the following ranking functions distribute the rows in an ordered partition into a specified number of groups?&lt;/td&gt;&lt;/tr&gt;
&lt;tr valign=&quot;top&quot;&gt;&lt;td align=&quot;left&quot; gt=&quot;gt&quot; style=&quot;padding-right: 5px;&quot; tr=&quot;tr&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;5&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;A. ROW_NUMBER&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;B. RANK&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;C. DENSE_RANK&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;D. NTILE&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;E. None of the Above&lt;br /&gt;
&lt;br /&gt;
Ans :- D&lt;br /&gt;
&lt;br /&gt;
Explanation:- &lt;br /&gt;
&lt;span id=&quot;_ctl0_ContentPlaceHolder1_LabelExplanation&quot;&gt;The NTILE ranking function distributes the rows in an ordered partition into a specified number of groups.  The groups are numbered, starting at one.  For each row, NTILE returns the number of the group to which the row belongs.&lt;br /&gt;&lt;br /&gt;The ROW_NUMBER ranking function returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.&lt;br /&gt;&lt;br /&gt;The RANK ranking function returns the rank of each row within the partition of a result set.  The rank of a row is one plus the number of ranks that come before the row in question.  Just like the DENSE_RANK, in the RANK ranking function, if two or more rows tie for a rank, each tied rows receive the same rank.  Unlike the DENSE_RANK, the RANK ranking function does not always return consecutive integers.&lt;br /&gt;&lt;br /&gt;The DENSE_RANK ranking function returns the rank of rows within the partition of a result set, without any gaps in the ranking.  The rank of a row is one plus the number of distinct ranks that come before the row in question.  If two or more rows tie for a rank in the same partition, each tied rows receive the same rank.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/table&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/4898111735004832884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/09/which-of-following-ranking-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4898111735004832884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4898111735004832884'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/09/which-of-following-ranking-functions.html' title='Which of the following ranking functions distribute the rows in an ordered partition into a specified number of groups'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-6543257437149071772</id><published>2012-06-02T06:06:00.003-07:00</published><updated>2012-06-02T06:06:55.131-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Identity"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="SCOPE_IDENTITY"/><title type='text'>@@IDENTITY VS SCOPE_IDENTITY() VS IDENT_CURRENT</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;SELECT @@IDENTITY&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.&lt;br /&gt;
&lt;br /&gt;
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SELECT SCOPE_IDENTITY()&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.&lt;br /&gt;
&lt;br /&gt;
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SELECT IDENT_CURRENT(‘tablename’)&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.&lt;br /&gt;
&lt;br /&gt;
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;Reference : &lt;strong&gt;Pinal Dave (&lt;/strong&gt;&lt;/span&gt;&lt;a href=&quot;http://blog.sqlauthority.com/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;http://blog.SQLAuthority.com&lt;/span&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;)&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/6543257437149071772/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/06/identity-vs-scopeidentity-vs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/6543257437149071772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/6543257437149071772'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/06/identity-vs-scopeidentity-vs.html' title='@@IDENTITY VS SCOPE_IDENTITY() VS IDENT_CURRENT'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-1263100833181373902</id><published>2012-05-23T21:13:00.000-07:00</published><updated>2012-05-23T21:13:02.122-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Inline Table UDF"/><category scheme="http://www.blogger.com/atom/ns#" term="Multi Statement UDF"/><category scheme="http://www.blogger.com/atom/ns#" term="Scaler UDF"/><title type='text'>Types of User Defined Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h5&gt;
Types of User Defined Functions&lt;/h5&gt;
There are three different types of User Defined Functions. Each type 
refers to the data being returned by the function. Scalar functions 
return a single value. In Line Table functions return a single table 
variable that was created by a select statement. The final UDF is a 
Multi-statement Table Function. This function returns a table variable 
whose structure was created by hand, similar to a Create Table 
statement. It is useful when complex data manipulation inside the 
function is required.&lt;br /&gt;
&lt;br /&gt;
&lt;h5&gt;
Scalar UDFs&lt;/h5&gt;
Our first User Defined Function will accept a date time, and return 
only the date portion. Scalar functions return a value. From inside 
Query Analyzer, enter:
&lt;br /&gt;
&amp;nbsp;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE FUNCTION&lt;/span&gt; dbo.DateOnly(@InDateTime datetime)&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;RETURNS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;varchar(10)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;DECLARE&lt;/span&gt; @MyOutput &lt;span style=&quot;color: blue;&quot;&gt;varchar(10)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SET&lt;/span&gt; @MyOutput = &lt;span style=&quot;color: blue;&quot;&gt;CONVERT&lt;/span&gt;(&lt;span style=&quot;color: blue;&quot;&gt;varchar(10)&lt;/span&gt;,@InDateTime,101)&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;RETURN&lt;/span&gt; @MyOutput&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/pre&gt;
To call our function, execute: &lt;code&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; dbo.DateOnly(&lt;span style=&quot;color: blue;&quot;&gt;GETDATE()&lt;/span&gt;)&lt;/code&gt; &lt;br /&gt;

Notice the User Defined Function must be prefaced with the owner 
name, DBO in this case. In addition, GETDATE can be used as the input 
parameter, but could not be used inside the function itself. Other built
 in SQL functions that cannot be used inside a User Defined Function 
include: RAND, NEWID, @@CONNCECTIONS, @@TIMETICKS, and @@PACK_SENT. Any 
built in function that is non-deterministic. &lt;br /&gt;

The statement begins by supplying a function name and input parameter
 list. In this case, a date time value will be passed in. The next line 
defines the type of data the UDF will return. Between the BEGIN and END 
block is the statement code. Declaring the output variable was for 
clarity only. This function should be shortened to: &lt;br /&gt;

&amp;nbsp;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE FUNCTION&lt;/span&gt; testDateOnly(@InDateTime datetime)&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;RETURNS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;varchar(10)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;RETURN CONVERT(varchar(10)&lt;/span&gt;,@InDateTime,101)&amp;nbsp;&amp;nbsp; &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/pre&gt;
&lt;h5&gt;
Inline Table UDFs&lt;/h5&gt;
These User Defined Functions return a table variable that was created
 by a single select statement. Almost like a simply constructed 
non-updatable view, but having the benefit of accepting input 
parameters. &lt;br /&gt;

This next function looks all the employees in the pubs database that 
start with a letter that is passed in as a parameter. In Query Analyzer,
 enter and run: &lt;br /&gt;

&amp;nbsp;
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;USE&lt;/span&gt; pubs&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;FUNCTION&lt;/span&gt; dbo.LookByFName(@FirstLetter char(1))&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;RETURNS&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;RETURN&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; *&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; employee&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHERE LEFT&lt;/span&gt;(fname, 1) =&amp;nbsp; @FirstLetter&lt;/pre&gt;
To use the new function, enter:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; dbo.LookByFName(&#39;A&#39;)&lt;/pre&gt;
All the rows having a first name starting with A were returned. The 
return is a Table Variable, not to be confused with a temporary table. 
Table variables are new in SQL 2000. They are a special data type whose 
scope is limited to the process that declared it. Table variables are 
stated to have performance benefits over temporary tables. None of my 
personal testing has found this result though. &lt;br /&gt;

&lt;h5&gt;
Multi Statement UDFs&lt;/h5&gt;
Multi Statement User Defined Functions are very similar to Stored 
Procedures. They both allow complex logic to take place inside the 
function. There are a number of restrictions unique to functions though.
 The Multi Statement UDF will always return a table variable–and only 
one table variable. There is no way to return multiple result sets. In 
addition, a User Defined Function cannot call a Stored Procedure from 
inside itself. They also cannot execute dynamic SQL. Remember also, that
 UDFs cannot use non-deterministic built in functions. So GETDATE and 
RAND cannot be used. Error handling is restricted. RAISERROR and @@ERROR
 are invalid from inside User Defined Functions. Like other programming 
languages, the purpose of a User Defined Function is to create a 
stand-alone code module to be reused over and over by the global 
application. &lt;br /&gt;

For a Multi Statement test, we will create a modified version of the 
LookByFName function. This new function will accept the same input 
parameter. But rather than return a table from a simple select, a 
specific table will be created, and data in it will be manipulated prior
 to the return: &lt;br /&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE FUNCTION&lt;/span&gt; dbo.multi_test(@FirstLetter char(1))&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;RETURNS&lt;/span&gt; @Result &lt;span style=&quot;color: blue;&quot;&gt;TABLE&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fname &lt;span style=&quot;color: blue;&quot;&gt;varchar(20)&lt;/span&gt;,&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hire_date &lt;span style=&quot;color: blue;&quot;&gt;datetime&lt;/span&gt;,&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on_probation &lt;span style=&quot;color: blue;&quot;&gt;char(1)&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;INSERT INTO&lt;/span&gt; @Result&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (fname, hire_date)&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; fname, hire_date&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; employee&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;WHERE LEFT&lt;/span&gt;(fname, 1) =&amp;nbsp; @FirstLetter&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;UPDATE&lt;/span&gt; @Result&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SET&lt;/span&gt; on_probation = &#39;N&#39;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;UPDATE&lt;/span&gt; @Result&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SET&lt;/span&gt; on_probation = &#39;Y&#39;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;WHERE&lt;/span&gt; hire_date &amp;lt; &#39;01/01/1991&#39;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;RETURN&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/pre&gt;
To use the new function, execute:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; dbo.multi_test(&#39;A&#39;)&lt;/pre&gt;
&lt;/blockquote&gt;
With the new Multi Statement Function, we can manipulate data like a 
Stored Procedure, but use it in statement areas like a View. &lt;br /&gt;

For example, only specific columns can be returned.
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; fname &lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; dbo.multi_test(&#39;A&#39;)&lt;/pre&gt;
The function can also be joined like a view:
&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt; e.lname, f.fname&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt; employee e &lt;span style=&quot;color: blue;&quot;&gt;INNER JOIN&lt;/span&gt; dbo.multi_test(&#39;A&#39;) f &lt;span style=&quot;color: blue;&quot;&gt;ON &lt;/span&gt;e.fname = f.fname&lt;/pre&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/1263100833181373902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/types-of-user-defined-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1263100833181373902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1263100833181373902'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/types-of-user-defined-functions.html' title='Types of User Defined Functions'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-7098910216651213774</id><published>2012-05-23T21:07:00.003-07:00</published><updated>2012-05-23T21:07:41.197-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Advantages and Disadvantages of User Defined Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h5&gt;
Advantages of User Defined Functions&lt;/h5&gt;
Before SQL 2000, User Defined Functions (UDFs), were not available. 
Stored Procedures were often used in their place. When advantages or 
disadvantages of User Defined Functions are discussed, the comparison is
 usually to Stored Procedures.
&lt;br /&gt;
One of the advantages of User Defined Functions over Stored 
Procedures, is the fact that a UDF can be used in a Select, Where, or 
Case statement. They also can be used to create joins. In addition, User
 Defined Functions are simpler to invoke than Stored Procedures from 
inside another SQL statement.&lt;br /&gt;
&lt;br /&gt;
&lt;h5&gt;
Disadvantages of User Defined Functions&lt;/h5&gt;
User Defined Functions cannot be used to modify base table 
information. The DML statements INSERT, UPDATE, and DELETE cannot be 
used on base tables. Another disadvantage is that SQL functions that 
return non-deterministic values are not allowed to be called from inside
 User Defined Functions. GETDATE is an example of a non-deterministic 
function. Every time the function is called, a different value is 
returned. Therefore, GETDATE cannot be called from inside a UDF you 
create.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/7098910216651213774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/advantages-and-disadvantages-of-user.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/7098910216651213774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/7098910216651213774'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/advantages-and-disadvantages-of-user.html' title='Advantages and Disadvantages of User Defined Functions'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-3998255829185621373</id><published>2012-05-19T09:17:00.000-07:00</published><updated>2012-05-19T09:17:23.758-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Master Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Model Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Resource Database"/><category scheme="http://www.blogger.com/atom/ns#" term="System Database"/><title type='text'>What are the SQL Server system databases and can you outline the general functionality of each database?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;color: #0c343d;&quot;&gt;
What are the SQL Server system databases and can you outline the general functionality of each database? 
&lt;/div&gt;
&lt;ul style=&quot;color: #0c343d;&quot;&gt;
&lt;li&gt;Master - Database responsible for SQL Server 
instance related data.&amp;nbsp; You can also think of this database 
corresponding to the Windows SQL Server service account. 
&lt;/li&gt;
&lt;li&gt;Resource - Database responsible for SQL 
Server system objects.&amp;nbsp; This database was introduced in SQL Server 2005 
and is intended to ease the upgrade and rollback of SQL Server system 
objects. 
&lt;/li&gt;
&lt;li&gt;Model - Template database for the creation of new user defined databases. 
&lt;/li&gt;
&lt;li&gt;MSDB - Database responsible for SQL Server Agent related data such as Jobs, Alerts, Operators, etc. 
&lt;/li&gt;
&lt;li&gt;TempDB - Temporary database to store 
temporary tables (#temptable or ##temptale), table variables, cursors, 
work tables, row versioning, create or rebuild indexes sorted in TempDB,
 etc.&amp;nbsp; Each time the SQL Server instance is restarted all objects in 
this database are destroyed, so permanent objects cannot be created in 
this database. 
&lt;/li&gt;
&lt;li&gt;Distribution - Database responsible for managing replicated data.&amp;nbsp; This database could reside on the publisher or subscriber. 
&lt;ul&gt;
&lt;li&gt;&lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/3998255829185621373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-are-sql-server-system-databases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3998255829185621373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3998255829185621373'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-are-sql-server-system-databases.html' title='What are the SQL Server system databases and can you outline the general functionality of each database?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-1633794397751504757</id><published>2012-05-19T09:08:00.000-07:00</published><updated>2012-05-19T09:08:16.375-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Do&#39;s and Don&#39;ts in Sys Databases"/><category scheme="http://www.blogger.com/atom/ns#" term="System Database"/><title type='text'>System Databases Do&#39;s and Don&#39;ts</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;i&gt;&lt;b&gt;System Databases Do&#39;s and Don&#39;ts &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Data Access&lt;/b&gt; - Based on the version of SQL Server query only 
the recommended objects.&amp;nbsp; In general the system database objects are 
being deprecated to a set of views, so be sure all of your scripts are 
accessing the right objects.&amp;nbsp; If not, you are going to have a big 
project in the future to convert all of your scripts. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Changing Objects&lt;/b&gt; - Do not change system objects.&amp;nbsp; In SQL
 Server 2005 all of the database objects have been moved to the Resource
 database which stores the definition for the system objects and can be 
updated via new SQL Server releases independent of the data. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;New Objects&lt;/b&gt; - Creating objects in the system databases 
is not recommended.&amp;nbsp; If you have objects that are needed for the 
instance i.e. administrative items, just create a separate DBA database 
to store these objects. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Sneaking a Peak&lt;/b&gt; - Up to this point, all of the T-SQL 
code for the tables, views, stored procedures, functions, etc. has been 
clear text.&amp;nbsp; So you can review the objects and learn from the techniques
 used by Microsoft. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Dropping Objects&lt;/b&gt; - The most prominent reason to drop 
system objects are for specific types of lock downs and auditing in 
particular industries.&amp;nbsp; Although some of those practices are well 
documented, be sure you understand the ramifications related to 
administering and developing applications once those restrictions are in
 place. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Security&lt;/b&gt; - Do not forget about the Public role and Guest
 user, they are the conduit for users to access the system objects.&amp;nbsp; So 
that should answer the question of how people (logins\users) can access 
the objects based on the object owner or schema, depending on the SQL 
Server version. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Backups&lt;/b&gt; - Be sure to have a consistent backup process 
for your system databases.&amp;nbsp; Including the system databases with your 
user defined databases might be the best approach if a disaster occurs. 
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Scope&lt;/b&gt; - Each SQL Server instance (including the Express 
Edition) has its own set of SQL Server system databases.&amp;nbsp; As such, if a 
single Windows server has multiple SQL Server instances installed, a 
change to one system database only impacts the single instance, not all 
instances on the Windows server.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/1633794397751504757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/system-databases-dos-and-donts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1633794397751504757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1633794397751504757'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/system-databases-dos-and-donts.html' title='System Databases Do&#39;s and Don&#39;ts'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-439170127108834763</id><published>2012-05-19T09:05:00.001-07:00</published><updated>2012-05-19T09:05:20.380-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Master Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Model Database"/><category scheme="http://www.blogger.com/atom/ns#" term="MSDB Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Resource Database"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="System Database"/><category scheme="http://www.blogger.com/atom/ns#" term="TempDB DataBase"/><title type='text'>SQL Server System Databases</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;i&gt;&lt;b&gt;SQL Server System Databases&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;

&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Master Database&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Core system database to manage the SQL Server instance.&amp;nbsp; 
In SQL Server 2005, the Master database is the logical repository for 
the system objects residing in the sys schema.&amp;nbsp; In SQL Server 2000 and 
previous editions of SQL Server, the Master database physically stored 
all of the system objects. 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Per instance configurations 
&lt;/li&gt;
&lt;li&gt;Databases residing on the instance 
&lt;/li&gt;
&lt;li&gt;Files for each database 
&lt;/li&gt;
&lt;li&gt;Logins 
&lt;/li&gt;
&lt;li&gt;Linked\Remote servers 
&lt;/li&gt;
&lt;li&gt;Endpoints&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;The first database in the SQL Server startup process 
&lt;/li&gt;
&lt;li&gt;In SQL Server 2005, needs to reside in the same directory as the Resource database 
&lt;/li&gt;
&lt;li&gt;Sources for Database Information - SQL Server 2000 to 2005 Crosswalk 
&lt;/li&gt;
&lt;li&gt;SQL 2000 to 2005 Crosswalk - Startup Parameters&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Resource &lt;/b&gt;&lt;b&gt;Database&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - The Resource database is responsible for physically 
storing all of the SQL Server 2005 system objects. This database has 
been created to improve the upgrade and rollback of SQL Server system 
objects with the ability to overwrite only this database. 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;System object definition&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;Introduced in SQL Server 2005 to help manage the upgrade and rollback of system objects 
&lt;/li&gt;
&lt;li&gt;Prior to SQL Server 2005 the system related data was stored in the master database 
&lt;/li&gt;
&lt;li&gt;Read-only database that is not accessible via the SQL Server 2005 tool set 
&lt;/li&gt;
&lt;li&gt;The database ID for the Resource database is 32767 
&lt;/li&gt;
&lt;li&gt;The Resource database does not have an entry in master.sys.databases&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;TempDB &lt;/b&gt;&lt;b&gt;Database&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Temporary database to store temporary tables (#temptable 
or ##temptale), table variables, cursors, work tables, row versioning, 
create or rebuild indexes sorted in TempDB, etc. Each time the SQL 
Server instance is restarted all objects in this database are destroyed,
 so permanent objects cannot be created in this database. 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Manage temporary objects listed in the purpose above&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;Properly Sizing the TempDB Database 
&lt;/li&gt;
&lt;li&gt;Each time a SQL Server instance is rebooted, the TempDB database is reset to its original state&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Model &lt;/b&gt;&lt;b&gt;Database&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Template database for all user defined databases 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Objects 
&lt;/li&gt;
&lt;li&gt;Columns 
&lt;/li&gt;
&lt;li&gt;Users&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;User defined tables, stored procedures, user defined data types, etc
 can be created in the Model database and will exist in all future user 
defined databases 
&lt;/li&gt;
&lt;li&gt;The database configurations such as the recovery model for the Model database are applied to future user defined databases&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;MSDB&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Primary database to manage the SQL Server Agent configurations 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;SQL Server Agent Jobs, Operators and Alerts 
&lt;/li&gt;
&lt;li&gt;DTS Package storage in SQL Server 7.0 and 2000 
&lt;/li&gt;
&lt;li&gt;SSIS Package storage in SQL Server 2005&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;Provides some of the configurations for the SQL Server Agent service 
&lt;/li&gt;
&lt;li&gt;For the SQL Server 2005 Express edition installations, even 
though the SQL Server Agent service does not exist, the instance still 
has the MSDB database 
&lt;/li&gt;
&lt;li&gt;Missing SQL Server Agent History 
&lt;/li&gt;
&lt;li&gt;MSSQLTips Category - SQL Server Agent&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Distribution&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Primary data to support SQL Server replication 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Database responsible for the replication meta data 
&lt;/li&gt;
&lt;li&gt;Supports the data for transaction replication between the publisher and subscriber(s)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;MSSQLTips Category - Replication&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ReportServer&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Primary database for Reporting Services to store the meta data and object definitions 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Reports security 
&lt;/li&gt;
&lt;li&gt;Job schedules and running jobs 
&lt;/li&gt;
&lt;li&gt;Report notifications 
&lt;/li&gt;
&lt;li&gt;Report execution history&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;MSSQLTips Category - Reporting Services&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ReportServerTempDB &lt;/b&gt;&lt;b&gt;Database&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt;Purpose - Temporary storage for Reporting Services 
&lt;/li&gt;
&lt;li&gt;Prominent Functionality 
&lt;ul&gt;
&lt;li&gt;Session information 
&lt;/li&gt;
&lt;li&gt;Cache&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Additional Information 
&lt;ul&gt;
&lt;li&gt;MSSQLTips Category - Reporting Services&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/439170127108834763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-server-system-databases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/439170127108834763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/439170127108834763'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-server-system-databases.html' title='SQL Server System Databases'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-4509529458975020777</id><published>2012-05-16T04:02:00.002-07:00</published><updated>2012-05-16T04:02:30.613-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VARCHAR vs TEXT"/><title type='text'>SQL Text vs VARCHAR</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;code&gt;&lt;b&gt;When to use VARCHAR and When to use TEXT&lt;/b&gt;&lt;/code&gt;&lt;/h2&gt;
&lt;code&gt;TEXT&lt;/code&gt; is used for large pieces of string data. If the length of the field exceeed a certain threshold, the text is stored out of row.&lt;br /&gt;


&lt;code&gt;VARCHAR&lt;/code&gt; is always stored in row and has a limit of &lt;em&gt;8000&lt;/em&gt; characters. If you try to create a &lt;code&gt;VARCHAR(x)&lt;/code&gt;, where &lt;em&gt;x &amp;gt; 8000&lt;/em&gt;, you get an error:&lt;br /&gt;


&lt;blockquote&gt;

  Server: Msg 131, Level 15, State 3, Line 1&lt;br /&gt;

  
  The size () given to the type ‘varchar’ exceeds the maximum allowed for any data type (8000) &lt;br /&gt;

&lt;/blockquote&gt;
These length limitations do not concern &lt;code&gt;VARCHAR(MAX)&lt;/code&gt; in &lt;em&gt;SQL Server 2005&lt;/em&gt;, which may be stored out of row, just like &lt;code&gt;TEXT&lt;/code&gt;.&lt;br /&gt;


Note that &lt;code&gt;MAX&lt;/code&gt; is not a kind of constant here, &lt;code&gt;VARCHAR&lt;/code&gt; and &lt;code&gt;VARCHAR(MAX)&lt;/code&gt; are very different types, the latter being very close to &lt;code&gt;TEXT&lt;/code&gt;.&lt;br /&gt;


In prior versions of &lt;em&gt;SQL Server&lt;/em&gt; you could not access the &lt;code&gt;TEXT&lt;/code&gt; directly, you only could get a &lt;code&gt;TEXTPTR&lt;/code&gt; and use it in &lt;code&gt;READTEXT&lt;/code&gt; and &lt;code&gt;WRITETEXT&lt;/code&gt; functions.&lt;br /&gt;


In &lt;em&gt;SQL Server 2005&lt;/em&gt; you can directly access &lt;code&gt;TEXT&lt;/code&gt; columns (though you still need an explicit cast to &lt;code&gt;VARCHAR&lt;/code&gt; to assign a value for them).&lt;br /&gt;


&lt;code&gt;TEXT&lt;/code&gt; is good:&lt;br /&gt;


&lt;ul&gt;
&lt;li&gt;If you need to store large texts in your database&lt;/li&gt;
&lt;li&gt;If you do not search on the value of the column&lt;/li&gt;
&lt;li&gt;If you select this column rarely and do not join on it.&lt;/li&gt;
&lt;/ul&gt;
&lt;code&gt;VARCHAR&lt;/code&gt; is good:&lt;br /&gt;


&lt;ul&gt;
&lt;li&gt;If you store little strings&lt;/li&gt;
&lt;li&gt;If you search on the string value&lt;/li&gt;
&lt;li&gt;If you always select it or use it in joins.&lt;/li&gt;
&lt;/ul&gt;
By &lt;em&gt;selecting&lt;/em&gt; here I mean issuing any queries that return the value of the column.&lt;br /&gt;


By &lt;em&gt;searching&lt;/em&gt; here I mean issuing any queries whose result depends on the value of the &lt;code&gt;TEXT&lt;/code&gt; or &lt;code&gt;VARCHAR&lt;/code&gt; column. This includes using it in any &lt;code&gt;JOIN&lt;/code&gt; or &lt;code&gt;WHERE&lt;/code&gt; condition.&lt;br /&gt;


As the &lt;code&gt;TEXT&lt;/code&gt; is stored out of row, the queries not involving the &lt;code&gt;TEXT&lt;/code&gt; column are usually faster.&lt;br /&gt;


Some examples of what &lt;code&gt;TEXT&lt;/code&gt; is good for:&lt;br /&gt;


&lt;ul&gt;
&lt;li&gt;Blog comments&lt;/li&gt;
&lt;li&gt;Wiki pages&lt;/li&gt;
&lt;li&gt;Code source&lt;/li&gt;
&lt;/ul&gt;
Some examples of what &lt;code&gt;VARCHAR&lt;/code&gt; is good for:&lt;br /&gt;


&lt;ul&gt;
&lt;li&gt;Usernames&lt;/li&gt;
&lt;li&gt;Page titles&lt;/li&gt;
&lt;li&gt;Filenames&lt;/li&gt;
&lt;/ul&gt;
As a rule of thumb, if you ever need you text value to exceed &lt;em&gt;200&lt;/em&gt; characters &lt;strong&gt;AND&lt;/strong&gt; do not use join on this column, use &lt;code&gt;TEXT&lt;/code&gt;.&lt;br /&gt;


Otherwise use &lt;code&gt;VARCHAR&lt;/code&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/4509529458975020777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-text-vs-varchar.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4509529458975020777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4509529458975020777'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-text-vs-varchar.html' title='SQL Text vs VARCHAR'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-8482472111062838094</id><published>2012-05-15T21:35:00.003-07:00</published><updated>2012-05-15T21:35:51.154-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ACID"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>SQL SERVER – ACID (Atomicity, Consistency, Isolation, Durability)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt; ACID&lt;/strong&gt; (an acronymn for 
Atomicity Consistency Isolation Durability) is a concept  that Database 
Professionals generally look for when evaluating databases and 
application architectures. For a reliable database all this four 
attributes should be achieved.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Atomicity&lt;/strong&gt; is an all-or-none proposition.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Consistency&lt;/strong&gt; guarantees that a transaction never leaves your database in a half-finished state.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Isolation&lt;/strong&gt; keeps transactions separated from each other until they’re finished.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Durability&lt;/strong&gt; guarantees 
that the database will keep track of pending changes in such a way that 
the server can recover from an abnormal termination.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Above four rules are very important for any developers dealing with databases.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Reference : &lt;strong&gt;Pinal Dave (&lt;/strong&gt;&lt;a href=&quot;http://blog.sqlauthority.com/&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;http://blog.SQLAuthority.com&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/8482472111062838094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-server-acid-atomicity-consistency.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8482472111062838094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8482472111062838094'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/sql-server-acid-atomicity-consistency.html' title='SQL SERVER – ACID (Atomicity, Consistency, Isolation, Durability)'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-8124302416186133482</id><published>2012-05-14T23:09:00.001-07:00</published><updated>2012-05-14T23:09:52.404-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><category scheme="http://www.blogger.com/atom/ns#" term="XML DataType"/><title type='text'>What is XML Datatype?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is XML Datatype?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The &lt;strong&gt;xml&lt;/strong&gt; data type lets 
you store XML documents and fragments in a SQL Server database. An XML 
fragment is an XML instance that is missing a single top-level element. 
You can create columns and variables of the &lt;strong&gt;xml&lt;/strong&gt; type and store XML instances in them. The &lt;strong&gt;xml&lt;/strong&gt; data type and associated methods help integrate XML into the relational framework of SQL Server.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/8124302416186133482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-xml-datatype.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8124302416186133482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8124302416186133482'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-xml-datatype.html' title='What is XML Datatype?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-8599412046210831365</id><published>2012-05-14T23:07:00.001-07:00</published><updated>2012-05-14T23:07:18.275-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="New in 2008"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Which are new data types introduced in SQL SERVER 2008?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;Which are new data types introduced in SQL SERVER 2008?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;&lt;em&gt;The GEOMETRY Type: &lt;/em&gt;&lt;/strong&gt;The
 GEOMETRY data type is a system .NET common language runtime (CLR) data 
type in SQL Server. This type represents data in a two-dimensional 
Euclidean coordinate system.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;&lt;em&gt;The GEOGRAPHY Type:&lt;/em&gt;&lt;/strong&gt;
 The GEOGRAPHY datatype’s functions are the same as with GEOMETRY. The 
difference between the two is that when you specify GEOGRAPHY, you are 
usually specifying points in terms of latitude and longitude.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;&lt;em&gt;New Date and Time Datatypes:&lt;/em&gt;&lt;/strong&gt; SQL Server 2008 introduces four new datatypes related to date and time: DATE, TIME, DATETIMEOFFSET, and DATETIME2.&lt;/div&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;strong&gt;&lt;em&gt;DATE&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; The new DATE type just stores the date itself. It is based on the Gregorian calendar and handles years from 1 to 9999.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;&lt;em&gt;TIME&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;:&lt;/em&gt; The new TIME (&lt;em&gt;n&lt;/em&gt;) 
type stores time with a range of 00:00:00.0000000 through 
23:59:59.9999999. The precision is allowed with this type. TIME supports
 seconds down to 100 nanoseconds. The &lt;em&gt;n &lt;/em&gt;in TIME (&lt;em&gt;n&lt;/em&gt;) defines this level of fractional second precision, from 0 to 7 digits of precision.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;strong&gt;&lt;em&gt;The DATETIMEOFFSET Type&lt;/em&gt;&lt;/strong&gt;: DATETIMEOFFSET (&lt;em&gt;n&lt;/em&gt;)
 is the time-zone-aware version of a datetime datatype. The name will 
appear less odd when you consider what it really is: a date + a time + a
 time-zone offset. The offset is based on how far behind or ahead you 
are from Coordinated Universal Time (UTC) time.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;strong&gt;&lt;em&gt;The DATETIME2 Type&lt;/em&gt;&lt;/strong&gt;: It is an extension of
 the datetime type in earlier versions of SQL Server. This new datatype 
has a date range covering dates from January 1 of year 1 through 
December 31 of year 9999. This is a definite improvement over the 1753 
lower boundary of the datetime datatype. DATETIME2 not only includes the
 larger date range, but also has a timestamp and the same fractional 
precision that TIME type provides&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/8599412046210831365/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/which-are-new-data-types-introduced-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8599412046210831365'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8599412046210831365'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/which-are-new-data-types-introduced-in.html' title='Which are new data types introduced in SQL SERVER 2008?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-5050930515196836454</id><published>2012-05-14T23:05:00.002-07:00</published><updated>2012-05-14T23:05:55.352-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="MERGE Statement"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is MERGE Statement?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;What is MERGE Statement?&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;br /&gt;
&lt;/strong&gt;MERGE is a new feature that provides an efficient way to 
perform multiple DML operations. In previous versions of SQL Server, we 
had to write separate statements to INSERT, UPDATE, or DELETE data based
 on certain conditions, but now, using MERGE statement we can include 
the logic of such data modifications in one statement that even checks 
when the data is matched then just update it and when unmatched then 
insert it. One of the most important advantages of MERGE statement is 
all the data is read and processed only once.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/5050930515196836454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-merge-statement.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/5050930515196836454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/5050930515196836454'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-merge-statement.html' title='What is MERGE Statement?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-2357418879462201217</id><published>2012-05-14T23:05:00.000-07:00</published><updated>2012-05-14T23:05:00.922-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CTE"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is CTE(Common Table Expression )</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is CTE?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
CTE is an abbreviation Common Table 
Expression. A Common Table Expression (CTE) is an expression that can be
 thought of as a temporary result set which is defined within the 
execution of a single SQL statement&lt;strong&gt;. &lt;/strong&gt;A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/2357418879462201217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-ctecommon-table-expression.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/2357418879462201217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/2357418879462201217'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-ctecommon-table-expression.html' title='What is CTE(Common Table Expression )'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-3349998575200711677</id><published>2012-05-14T23:03:00.001-07:00</published><updated>2012-05-14T23:03:58.691-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database Mirroring"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Replication"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is Replication and Database Mirroring?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is Replication and Database Mirroring?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Database mirroring can be used with 
replication to provide availability for the publication database. 
Database mirroring involves two copies of a single database that 
typically reside on different computers. At any given time, only one 
copy of the database is currently available to clients which are known 
as the principal database. Updates made by clients to the principal 
database are applied on the other copy of the database, known as the 
mirror database. Mirroring involves applying the transaction log from 
every insertion, update, or deletion made on the principal database onto
 the mirror database.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/3349998575200711677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-replication-and-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3349998575200711677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/3349998575200711677'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-replication-and-database.html' title='What is Replication and Database Mirroring?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-1834796894558237894</id><published>2012-05-14T23:01:00.001-07:00</published><updated>2012-05-14T23:01:40.979-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is Service Broker?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is Service Broker?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Service Broker is a message-queuing 
technology in SQL Server that allows developers to integrate SQL Server 
fully into distributed applications. Service Broker is feature which 
provides facility to SQL Server to send an asynchronous, transactional 
message. it allows a database to send a message to another database 
without waiting for the response, so the application will continue to 
function if the remote database is temporarily unavailable&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/1834796894558237894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-service-broker.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1834796894558237894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/1834796894558237894'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-service-broker.html' title='What is Service Broker?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-4713377213467433825</id><published>2012-05-14T23:00:00.001-07:00</published><updated>2012-05-14T23:00:34.493-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is an execution plan in SQL server</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is an execution plan? When would you use it? How would you view the execution plan?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
An execution plan is basically a road map
 that graphically or textually shows the data retrieval methods chosen 
by the SQL Server query optimizer for a stored procedure or ad-hoc query
 and is a very useful tool for a developer to understand the performance
 characteristics of a query or stored procedure since the plan is the 
one that SQL Server will place in its cache and use to execute the 
stored procedure or query. From within Query Analyzer is an option 
called “Show Execution Plan” (located on the Query drop-down menu). If 
this option is turned on it will display query execution plan in 
separate window when query is ran again.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/4713377213467433825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-execution-plan-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4713377213467433825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4713377213467433825'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-execution-plan-in-sql-server.html' title='What is an execution plan in SQL server'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-8159556440795534807</id><published>2012-05-14T22:57:00.001-07:00</published><updated>2012-05-14T22:57:23.603-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DataWareHousing"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is DataWarehousing?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is DataWarehousing?&lt;/strong&gt;&lt;/div&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; Subject-oriented, meaning that the data in the database is 
organized so that all the data elements relating to the same real-world 
event or object are linked together;&lt;/li&gt;
&lt;li&gt; Time-variant, meaning that the changes to the data in the database 
are tracked and recorded so that reports can be produced showing changes
 over time;&lt;/li&gt;
&lt;li&gt; Non-volatile, meaning that data in the database is never 
over-written or deleted, once committed, the data is static, read-only, 
but retained for future reporting.&lt;/li&gt;
&lt;li&gt; Integrated, meaning that the database contains data from most or 
all of an organization’s operational applications, and that this data is
 made consistent.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/8159556440795534807/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-datawarehousing.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8159556440795534807'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8159556440795534807'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-datawarehousing.html' title='What is DataWarehousing?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-4561518610902725838</id><published>2012-05-14T22:56:00.000-07:00</published><updated>2012-05-14T22:56:16.006-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Identity"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What is Identity in SQL Server?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;strong&gt;What is Identity?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Identity (or AutoNumber) is a column that
 automatically generates numeric values. A start and increment value can
 be set, but most DBA leave these at 1. A GUID column also generates 
numbers; the value of this cannot be controlled. Identity/GUID columns 
do not need to be indexed.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/4561518610902725838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-identity-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4561518610902725838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/4561518610902725838'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-is-identity-in-sql-server.html' title='What is Identity in SQL Server?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-8003384972902871866</id><published>2012-05-14T22:54:00.002-07:00</published><updated>2012-05-14T22:55:24.547-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Joins"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>What are different Types of Join in SQL Server</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;What are different Types of Join?&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt;Cross Join&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A cross join that does not have a WHERE 
clause produces the Cartesian product of the tables involved in the 
join. The size of a Cartesian product result set is the number of rows 
in the first table multiplied by the number of rows in the second table.
 The common example is when company wants to combine each product with a
 pricing table to analyze each product at each price.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt;Inner Join&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A join that displays only the rows that 
have a match in both joined tables is known as inner Join.&amp;nbsp; This is the 
default type of join in the Query and View Designer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt;Outer Join&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A join that includes rows even if they do
 not have related rows in the joined table is an Outer Join. &amp;nbsp;You can 
create three different outer join to specify the unmatched rows to be 
included:&lt;/div&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;b&gt;Left Outer Join:&lt;/b&gt; In Left Outer Join all rows in 
the first-named table i.e. “left” table, which appears leftmost in the 
JOIN clause are included. Unmatched rows in the right table do not 
appear.&lt;b&gt; &lt;/b&gt;&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;b&gt;Right Outer Join:&lt;/b&gt; In Right Outer Join all rows in 
the second-named table i.e. “right” table, which appears rightmost in 
the JOIN clause are included. Unmatched rows in the left table are not 
included.&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;ul class=&quot;unIndentedList&quot; style=&quot;text-align: justify;&quot;&gt;
&lt;li&gt; &lt;b&gt;Full Outer Join:&lt;/b&gt; In Full Outer Join all rows in all joined tables are included, whether they are matched or not.&lt;b&gt;&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;i&gt;Self Join&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
This is a particular case when one table 
joins to itself, with one or two aliases to avoid confusion. A self join
 can be of any type, as long as the joined tables are the same. A self 
join is rather unique in that it involves a relationship with only one 
table. The common example is when company has a hierarchal reporting 
structure whereby one member of staff reports to another. Self Join can 
be Outer Join or Inner Join.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/8003384972902871866/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-are-different-types-of-join-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8003384972902871866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/8003384972902871866'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/what-are-different-types-of-join-in-sql.html' title='What are different Types of Join in SQL Server'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5127798429426738073.post-2048805893249298985</id><published>2012-05-13T22:00:00.002-07:00</published><updated>2012-05-13T22:00:59.526-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Recursive SP"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>Can a stored procedure call itself or recursive stored procedure? How many level SP nesting possible?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Can a stored procedure call itself or recursive stored procedure? How many level SP nesting&lt;br /&gt;possible?&lt;br /&gt;Yes. Because Transact-SQL supports recursion, you can write stored procedures that call themselves.&lt;br /&gt;Recursion can be defined as a method of problem solving wherein the solution is arrived at by&lt;br /&gt;repetitively applying it to subsets of the problem. A common application of recursive logic is to perform&lt;br /&gt;numeric computations that lend themselves to repetitive evaluation by the same processing steps.&lt;br /&gt;Stored procedures are nested when one stored procedure calls another or executes managed code by&lt;br /&gt;referencing a CLR routine, type, or aggregate. You can nest stored procedures and managed code&lt;br /&gt;references up to 32 levels.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sqlcodemaster.blogspot.com/feeds/2048805893249298985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/can-stored-procedure-call-itself-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/2048805893249298985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5127798429426738073/posts/default/2048805893249298985'/><link rel='alternate' type='text/html' href='http://sqlcodemaster.blogspot.com/2012/05/can-stored-procedure-call-itself-or.html' title='Can a stored procedure call itself or recursive stored procedure? How many level SP nesting possible?'/><author><name>Pratap Singh</name><uri>http://www.blogger.com/profile/00310023181491568166</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/-NqVwqaPsorw/Tz9AH2BoVPI/AAAAAAAAECI/TYyRYDepEQ4/s220/Untitled.jpg'/></author><thr:total>0</thr:total></entry></feed>