Skip to main content

Posts

Showing posts from December, 2006

Don't start the user defined stored procedure with "SP_"

As you might be knowing the system stored procs would be prefixed with "SP_". If we prefix "sp_" in our user-defined stored procedure it would bring down the performance because SQL Server always looks for a stored procedure beginning with "sp_" in the following order: 1) Master DB, 2) The stored procedure based on the fully qualified name provided, 3) The stored procedure using dbo as the owner, if one is not specified. So, when you have the SP with the prefix "sp_" in the DB other than master, the Master DB is always checked first, and if the user-created SP has the same name as a system stored proc, the user-created stored procedure will never be executed. For example, Let's say that by mistake you have named one of your user defined stored procedure as "sp_help" within the database! Create proc sp_help as Select * from dbo.empdetails Now when you try executing the stored procedure using the below script you would re

sp_executesql( ) vs Execute() -- Dynamic Queries

There were few questions regarding "Passing table names as parameters to stored procedures" in Dotnetspider forums. I don't feel this to be a write way of coding. Still many persons are asking similar questions in the forums thought would write a post on "SP_EXECUTESQL()" Vs "EXECUTE()". Sample SP to pass table name as parameter: Create proc SampleSp_UsingDynamicQueries @table sysname As Declare @strQuery nvarchar(4000) Select @strQuery = 'select * from dbo.' + quotename(@table) exec sp_executesql @strQuery -------- (A) --exec (@strQuery) ---------------------- (B) go Test: Execute dbo.samplesp_usingdynamicqueries 'EmpDetails' In the above stored procedure irrespective of whether we use the line which is marked as (A) or (B) it would give us the same result. So what's the difference between them? One basic difference is while using (A) we need to declare the @strQuery as nvarchar or nchar. (i) It would throw the below error if we

I am now a Microsoft Certified Technology Specialist!

Let me start by saying, I have never taken a Microsoft exam previously. I was having a "Microsoft Exams 100% Discount Coupon" which was valid till 31-Dec-2006 so thought of utilizing it. I prepared well for 70-431 Microsoft SQL Server 2005 - Implementation and Maintenance paper and today morning at 10.45 AM I took up the online test @ NIIT Adyar. I am glad that I have cleared it with a good score of 982 (out of 1000). Now I am a " Microsoft Certified Technology Specialist " :) There were 52 questions and out of which approximately 15 where simulation questions (that was where I spent most of my time). Though the score might look big, I need to accept that I answered 20 to 30% 0f questions without much of confidence. Hope the choices I made where accidently correct :) I was bit tensed in the morning till the time I answered the first question. Reason being, couple of my friends know that I am going to take up the test today. I was afraid what would they think if I f

Banks : Do Not Disturb Me

As per RBI regulation I guess all banks should have a "Do Not Distrub Me" or "Do not call me" :) web page inorder to value customers privacy. I get atleast couple of telemarketing calls a day from one bank or other. Its really irritating and i was looking for a way to avoid them totally. Only then i came to know about these "Don't call registeration pages" for various banks. Looooong Live RBI :) :) 1. ICICI Bank - As per the site itseems it would take 15 days for the number to be removed from the telemarketing list! 2. Citibank -- I didn't find the time frame in this site. 3. Deutsche bank -- As per the site itseems it would take 30 days for the number to be removed from the telemarketing list! 4. Standard Chartered Bank -- As per the site itseems it would take 30 days for the number to be removed from the telemarketing list! 5. HDFC Bank -- As per the site itseems it would take 45 days for the number to be removed from the telemarketing list!

Rolling back a truncate operation!

First I suggest you to go through my earlier article on subject "Delete VS Truncate" here . Truncate is also a logged operation, but in a different way. It logs the deallocation of the data pages in which the data exists. Let us create a dummy table for understanding this example: Create Table dbo.TruncateTblDemo (Sno int) Go Insert few records into it: Insert into dbo.TruncateTblDemo values (1) Insert into dbo.TruncateTblDemo values (2) Insert into dbo.TruncateTblDemo values (3) Go You could see that the table has 3 records in it: Select * from dbo.TruncateTblDemo Execute a truncate statement: Truncate Table dbo.TruncateTblDemo After the above statement you can't retrieve the data back because it is an explicit transaction . Unless or until you have set Implicit_Transactions to off . That is, Internally sql would have taken our above truncate statement as follow: Begin Tran Truncate Table dbo.TruncateTblDemo Commit Tran Select * from dbo.truncatetbldemo Getting back data

Fun with SQL Server ...

Read this first: 1. This has no real time usage. So try this out only when you are free :) 2. This script was just done for fun and nothing more. 3. Before executing this script change your result display mode to 'Text' (Ctrl + T) 4. There are easier way of doing the same thing. Just to make it look complex I have done this way :) Code snippet Starts here: Set nocount on Declare @TblLayout table([ID] int Identity, Canvas Char(75)) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Insert into @TblLayout Select Replicate (Convert(Varchar, 0x7E), 75) Inser