<?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: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-4287412049591913125</id><updated>2011-11-27T17:16:06.137-08:00</updated><category term='Execution Time'/><category term='Views in SQL Server'/><category term='Store procedure'/><category term='Running Total'/><category term='What is SQL Injection'/><category term='Temporary Stored Procedures'/><title type='text'>Microsoft SQL Server 2005/2008</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-5671407097128133358</id><published>2011-03-15T21:57:00.000-07:00</published><updated>2011-03-15T22:01:16.613-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Execution Time'/><title type='text'>Calculate Execution Time of the Query</title><content type='html'>&lt;b&gt;Method 1:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DECLARE @StartTime datetime&lt;br /&gt;,@EndTime datetime&lt;br /&gt;&lt;br /&gt;SELECT @StartTime=GETDATE()&lt;br /&gt;&lt;br /&gt;SELECT * FROM tblmastertable ORDER BY Insertion_time DESC&lt;br /&gt;&lt;br /&gt;SELECT @EndTime=GETDATE()&lt;br /&gt;&lt;br /&gt;SELECT DATEDIFF(ms,@StartTime,@EndTime) AS [Duration in millisecs]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Method 2:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;SET STATISTICS TIME ON&lt;br /&gt; &lt;br /&gt;SELECT * FROM tblmastertable ORDER BY Insertion_time DESC&lt;br /&gt; &lt;br /&gt;SET STATISTICS TIME OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-5671407097128133358?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/5671407097128133358/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/03/calculate-execution-time-of-query.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/5671407097128133358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/5671407097128133358'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/03/calculate-execution-time-of-query.html' title='Calculate Execution Time of the Query'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-7034563805171878609</id><published>2011-03-15T02:30:00.000-07:00</published><updated>2011-03-15T02:30:50.750-07:00</updated><title type='text'>Default Update_Time on Every update on table</title><content type='html'>CREATE TABLE [tblBatch]&lt;br /&gt;(&lt;br /&gt;Batch_id int identity(1, 1) Primary key,&lt;br /&gt;Batch_Name nvarchar(255),&lt;br /&gt;Create_Time datetime NOT NUll default CURRENT_TIMESTAMP,&lt;br /&gt;Update_Time datetime Not Null default CURRENT_TIMESTAMP&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;By default Create_Time and Update_Time will have CURRENT_TIMESTAMP&lt;br /&gt;&lt;br /&gt;ALTER TRIGGER trgBatch_Modify_Time&lt;br /&gt;ON tblBatch&lt;br /&gt;AFTER  UPDATE &lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;UPDATE tblBatch&lt;br /&gt;SET Update_Time = GETDATE()&lt;br /&gt;WHERE Batch_ID = (SELECT Batch_ID From inserted)&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;Above define trigger will enable to update update_Time column with current date&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-7034563805171878609?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/7034563805171878609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/03/default-updatetime-on-every-update-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/7034563805171878609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/7034563805171878609'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/03/default-updatetime-on-every-update-on.html' title='Default Update_Time on Every update on table'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-4772909257282191959</id><published>2011-02-24T21:14:00.000-08:00</published><updated>2011-02-24T21:14:53.163-08:00</updated><title type='text'>Table Valued Parameters in SQL Server 2008</title><content type='html'>SQL Server 2008 introduces the ability to pass a table data type into stored procedures and functions. The table parameter feature can greatly ease the development process because you no longer need to worry about constructing and parsing XML data&lt;br /&gt;&lt;br /&gt;Practical Example of the Table Valued Parameter&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Creating table tblProductHistory to hold data of Products&lt;br /&gt;&lt;br /&gt;IF OBJECT_ID('tblProductHistory')&gt;0    &lt;br /&gt;  DROP TABLE tblProductHistory;&lt;br /&gt;  GO&lt;br /&gt;  CREATE TABLE [dbo].[tblProductHistory]&lt;br /&gt;  (          &lt;br /&gt;        [Product_ID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,          &lt;br /&gt;        [Product_Name] [varchar](250) NULL,                &lt;br /&gt;        [Intro_Date] [datetime] NULL,                &lt;br /&gt;        [Sale_Price] [money] NULL&lt;br /&gt;  )&lt;br /&gt;  GO&lt;br /&gt;  &lt;br /&gt;  -- Creating Type in Database engine to hold datatime as variable&lt;br /&gt;  &lt;br /&gt;  CREATE TYPE ProductHistoryTableType AS TABLE&lt;br /&gt;  (                     &lt;br /&gt;        [Product_Name] [varchar](250) NULL,                &lt;br /&gt;        [Into_Date] [datetime] NULL,                &lt;br /&gt;        [Sale_Price] [money] NULL&lt;br /&gt;  )&lt;br /&gt;  GO&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  -- Procedure will use the TableType define above as parameter&lt;br /&gt;  &lt;br /&gt;  ALTER PROCEDURE proc_InsertExportProducts&lt;br /&gt; (&lt;br /&gt;       @TableVariable ProductHistoryTableType READONLY&lt;br /&gt; )&lt;br /&gt; AS&lt;br /&gt; BEGIN&lt;br /&gt; &lt;br /&gt;        INSERT INTO [tblProductHistory]&lt;br /&gt;       (&lt;br /&gt;             Product_Name, Intro_Date, Sale_Price &lt;br /&gt;       )&lt;br /&gt;       SELECT&lt;br /&gt;             Product_Name, Into_Date, Sale_Price&lt;br /&gt;       FROM&lt;br /&gt;             @TableVariable&lt;br /&gt;       WHERE&lt;br /&gt;             Product_Name Like '%Export%' -- All product with Export text in their name    &lt;br /&gt;&lt;br /&gt; END&lt;br /&gt; GO&lt;br /&gt;  &lt;br /&gt;  -- Adding some test data in variable of Type 'ProductHistoryTableType'&lt;br /&gt;  &lt;br /&gt;  DECLARE @DataTable AS ProductHistoryTableType&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DECLARE @i SMALLINT&lt;br /&gt; SET @i = 1          &lt;br /&gt;&lt;br /&gt; WHILE (@i &lt;=1000)&lt;br /&gt; BEGIN                         &lt;br /&gt;&lt;br /&gt;     INSERT INTO @DataTable(Product_Name, Into_Date, Sale_Price)                      &lt;br /&gt; VALUES ('Semi-Connectors', DATEADD(mm, @i, '3/11/1997'), DATEPART(ms, GETDATE()) + (@i + 57))                &lt;br /&gt;&lt;br /&gt;     INSERT INTO @DataTable(Product_Name, Into_Date, Sale_Price)            &lt;br /&gt; VALUES('Export-SChips', DATEADD(mm, @i, '3/11/1956'), DATEPART(ms, GETDATE()) + (@i + 13))                     &lt;br /&gt;&lt;br /&gt;     INSERT INTO @DataTable(Product_Name, Into_Date, Sale_Price)                &lt;br /&gt; VALUES('Export-Diodes', DATEADD(mm, @i, '3/11/1975'), DATEPART(ms, GETDATE()) + (@i + 29))                            &lt;br /&gt;&lt;br /&gt;     SET @i = @i + 1&lt;br /&gt; END&lt;br /&gt; &lt;br /&gt; -- Execute the stored procedure with table variable - passing @DataTable&lt;br /&gt; &lt;br /&gt; EXECUTE proc_InsertExportProducts&lt;br /&gt; @TableVariable = @DataTable&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; -- Resultant of the procedure in the main table&lt;br /&gt; &lt;br /&gt; SELECT * FROM [tblProductHistory]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-4772909257282191959?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/4772909257282191959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/table-valued-parameters-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/4772909257282191959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/4772909257282191959'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/table-valued-parameters-in-sql-server.html' title='Table Valued Parameters in SQL Server 2008'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-5052162672568509093</id><published>2011-02-21T22:59:00.000-08:00</published><updated>2011-02-22T01:07:06.122-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Running Total'/><title type='text'>How to calculate running total in Sql Server</title><content type='html'>Example 1:&lt;br /&gt;&lt;br /&gt;SELECT SalesOrderID,&lt;br /&gt;OrderDate = CONVERT(date, OrderDate),&lt;br /&gt;O.TotalDue,&lt;br /&gt;(SELECT sum(TotalDue)&lt;br /&gt;FROM   AdventureWorks2008.Sales.SalesOrderHeader&lt;br /&gt;WHERE  SalesOrderID &lt;= O.SalesOrderID) 'Running Total'FROM   AdventureWorks2008.Sales.SalesOrderHeader OGO&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;/* results&lt;br /&gt;&lt;br /&gt;SalesOrderID      OrderDate   TotalDue    Running Total&lt;br /&gt;43659             2001-07-01  27231.5495  27231.5495&lt;br /&gt;43660             2001-07-01  1716.1794   28947.7289&lt;br /&gt;43661             2001-07-01  43561.4424  72509.1713&lt;br /&gt;43662             2001-07-01  38331.9613  110841.1326&lt;br /&gt;43663             2001-07-01  556.2026    111397.3352&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Example 2:&lt;br /&gt;&lt;br /&gt;CREATE TABLE tblAccounts &lt;br /&gt;( &lt;br /&gt;Trans_ID int IDENTITY(1,1), &lt;br /&gt;Trans_Date datetime, &lt;br /&gt;Balance float &lt;br /&gt;) &lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/1/2000',100) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/2/2000',101) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/3/2000',102) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/4/2000',103) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/5/2000',104) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/6/2000',105) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/7/2000',106) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/8/2000',107) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/9/2000',108) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/10/2000',109) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/11/2000',200) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/12/2000',201) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/13/2000',202) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/14/2000',203) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/15/2000',204) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/16/2000',205) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/17/2000',206) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/18/2000',207) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/19/2000',208) &lt;br /&gt;insert into tblAccounts(Trans_Date,Balance) values ('1/20/2000',209) &lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Appling Cross Join on tblAccounts&lt;br /&gt;&lt;br /&gt;SELECT A.Trans_ID AS ID,&lt;br /&gt;       B.Trans_ID AS BID, &lt;br /&gt;       B.Balance &lt;br /&gt;FROM tblAccounts A CROSS JOIN &lt;br /&gt;     tblAccounts B &lt;br /&gt;WHERE B.Trans_ID BETWEEN A.Trans_ID-0 AND A.Trans_ID &lt;br /&gt;     AND A.Trans_ID&gt;0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Getting running total by using cross-join  &lt;br /&gt;&lt;br /&gt;SELECT TRANS_ID, SUM(Balance) As Running_total&lt;br /&gt;&lt;br /&gt;FROM (SELECT A.Trans_ID AS TRANS_ID,&lt;br /&gt;B.Trans_ID AS BID, &lt;br /&gt;B.Balance &lt;br /&gt;FROM tblAccounts A CROSS JOIN &lt;br /&gt;tblAccounts B &lt;br /&gt;WHERE B.Trans_ID BETWEEN A.Trans_ID-0 AND A.Trans_ID &lt;br /&gt;AND A.Trans_ID&gt;0) K &lt;br /&gt;&lt;br /&gt;GROUP BY Trans_ID&lt;br /&gt;ORDER BY TRANS_ID&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-5052162672568509093?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/5052162672568509093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/how-to-calculate-running-total-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/5052162672568509093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/5052162672568509093'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/how-to-calculate-running-total-in-sql.html' title='How to calculate running total in Sql Server'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-259055953978113654</id><published>2011-02-08T04:33:00.000-08:00</published><updated>2011-02-08T04:33:40.269-08:00</updated><title type='text'>Custom Paging Data Procedure</title><content type='html'>CREATE PROCEDURE procGetCustomPagingData  &lt;br /&gt;      @PageIndex INT = 1  &lt;br /&gt;      ,@PageSize INT = 10  &lt;br /&gt;      ,@RecordCount INT OUTPUT  &lt;br /&gt;AS  &lt;br /&gt;BEGIN  &lt;br /&gt;      SET NOCOUNT ON;  &lt;br /&gt;      SELECT ROW_NUMBER() OVER  &lt;br /&gt;      (  &lt;br /&gt;            ORDER BY [ID] ASC  &lt;br /&gt;      )AS RowNumber  &lt;br /&gt;      ,[Sales_Accounts]  &lt;br /&gt;      ,[Other_Income]  &lt;br /&gt;      ,[Total_Revenue_A]  &lt;br /&gt;      ,[NetProfit]  &lt;br /&gt;     INTO #Results  &lt;br /&gt;      FROM [tblmastertable]  &lt;br /&gt;       &lt;br /&gt;      SELECT @RecordCount = COUNT(*)  &lt;br /&gt;      FROM #Results  &lt;br /&gt;             &lt;br /&gt;      SELECT * FROM #Results  &lt;br /&gt;      WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1  &lt;br /&gt;       &lt;br /&gt;      DROP TABLE #Results  &lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-259055953978113654?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/259055953978113654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/custom-paging-data-procedure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/259055953978113654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/259055953978113654'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2011/02/custom-paging-data-procedure.html' title='Custom Paging Data Procedure'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-6301837044615109261</id><published>2010-04-18T22:15:00.000-07:00</published><updated>2010-04-18T22:16:16.437-07:00</updated><title type='text'>Difference between Rollup and Cube</title><content type='html'>You can use the CUBE and ROLLUP operators to generate summary information in a query. A CUBE operator generates a result set that shows the aggregates for all combinations of values in the selected columns. A ROLLUP operator generates a result set showing the aggregates for a hierarchy of values in the selected columns. Both the CUBE and ROLLUP operators return data in relational form.&lt;br /&gt;&lt;br /&gt;The CUBE operator generates a multidimensional cube result set. A multidimensional cube is an expansion of fact data, or the data that records individual events.&lt;br /&gt;This expansion is based on columns that the user wants to analyze. These columns are called dimensions. A cube is a result set that contains a cross tabulation of all the possible combinations of the dimensions.&lt;br /&gt;&lt;br /&gt;The CUBE operator is specified in the GROUP BY clause of a SELECT statement. The select list contains the dimension columns and aggregate function expressions. The GROUP BY specifies the dimension columns by using the WITH CUBE keywords.&lt;br /&gt;The result set contains all possible combinations of the values in the dimension columns, together with the aggregate values from the underlying rows that match that combination of dimension values.&lt;br /&gt;&lt;br /&gt;The ROLLUP operator is useful in generating reports that contain aggregate values. The ROLLUP operator generates a result set that is similar to the result set generated by the CUBE operator.&lt;br /&gt;&lt;br /&gt;However, the difference between the CUBE and ROLLUP operator is that the CUBE generates a result set that shows the aggregates for all combinations of values in the selected columns. By contrast, the ROLLUP operator returns only the specific result set.&lt;br /&gt;The ROLLUP operator generates a result set that shows the aggregates for a hierarchy of values in the selected columns. Also, the ROLLUP operator provides only one level of summarization, for example, the cumulative running sum in a table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-6301837044615109261?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/6301837044615109261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2010/04/difference-between-rollup-and-cube.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/6301837044615109261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/6301837044615109261'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2010/04/difference-between-rollup-and-cube.html' title='Difference between Rollup and Cube'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-7966866507643069397</id><published>2009-09-22T05:36:00.000-07:00</published><updated>2009-09-22T05:40:02.936-07:00</updated><title type='text'>Trigger for Deletion of Child Records w.r.t. to Parent Table</title><content type='html'>Parent table:  tblProduct PK Product_code&lt;br /&gt;&lt;br /&gt;Child table 1: tblCategory FK Product_code&lt;br /&gt;&lt;br /&gt;Child table2: tblDelivery FK Prodcut_code&lt;br /&gt;&lt;br /&gt;Create TRIGGER [Delete_After_tblProduct]&lt;br /&gt;&lt;br /&gt;ON [dbo].[tblProduct]&lt;br /&gt;&lt;br /&gt;AFTER DELETE&lt;br /&gt;&lt;br /&gt;AS &lt;br /&gt;&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;Begin try&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;declare @product_code bigint;&lt;br /&gt;&lt;br /&gt;select @product_code=project_code from deleted;&lt;br /&gt;&lt;br /&gt;delete from tblcategory where product_code=@product_code;&lt;br /&gt;&lt;br /&gt;delete from tblDelivery where product_code=@product_code; &lt;br /&gt;&lt;br /&gt;end try&lt;br /&gt;&lt;br /&gt;begin catch&lt;br /&gt;&lt;br /&gt;end catch&lt;br /&gt;&lt;br /&gt;END&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-7966866507643069397?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/7966866507643069397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/09/trigger-for-deletion-of-child-records.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/7966866507643069397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/7966866507643069397'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/09/trigger-for-deletion-of-child-records.html' title='Trigger for Deletion of Child Records w.r.t. to Parent Table'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-228918842542886535</id><published>2009-07-13T23:30:00.000-07:00</published><updated>2009-07-13T23:31:49.300-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Temporary Stored Procedures'/><title type='text'>Temporary Stored Procedures</title><content type='html'>SQL Server provides the ability to create private and global temporary stored procedures.&lt;br /&gt;Temporary stored procedures are analogous to temporary tables in that they can be&lt;br /&gt;created with the # and ## prefixes added to the procedure name. The # prefix denotes a&lt;br /&gt;local temporary stored procedure; ## denotes a global temporary stored procedure. A local&lt;br /&gt;temporary stored procedure can be executed only by the connection that created it, and&lt;br /&gt;the procedure is automatically deleted when the connection is closed. A global temporary stored procedure can be accessed by multiple connections and exists until the connection&lt;br /&gt;used by the user who created the procedure is closed and any currently executing versions&lt;br /&gt;of the procedure by any other connections are completed.&lt;br /&gt;If a stored procedure not prefixed with # or ## is created directly in the tempdb database,&lt;br /&gt;the stored procedure exists until SQL Server is shut down. Procedures created directly in&lt;br /&gt;tempdb continue to exist even after the creating connection is terminated.&lt;br /&gt;Temporary stored procedures are provided for backward compatibility with earlier&lt;br /&gt;versions of SQL Server that did not support the reuse of execution plans for T-SQL statements&lt;br /&gt;or batches. Applications connecting to SQL Server 2000 and higher should use the&lt;br /&gt;sp_executesql system stored procedure instead of temporary stored procedures.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-228918842542886535?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/228918842542886535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/07/temporary-stored-procedures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/228918842542886535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/228918842542886535'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/07/temporary-stored-procedures.html' title='Temporary Stored Procedures'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-3605388021313369007</id><published>2009-07-06T23:38:00.000-07:00</published><updated>2009-07-06T23:40:10.339-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='What is SQL Injection'/><title type='text'>What is SQL Injection</title><content type='html'>SQL Injection happens when a developer accepts user input that is directly placed into a SQL Statement and doesn't properly filter out dangerous characters. This can allow an attacker to not only steal data from your database, but also modify and delete it. Certain SQL Servers such as Microsoft SQL Server contain Stored and Extended Procedures (database server functions). If an attacker can obtain access to these Procedures it may be possible to compromise the entire machine. Attackers commonly insert single qoutes into a URL's query string, or into a forms input field to test for SQL Injection. If an attacker receives an error message like the one below there is a good chance that the application is vulnerable to SQL Injection.&lt;br /&gt;&lt;br /&gt;SQL injection attacks take advantage of code that does not filter input that is being entered directly into a form. Susceptible applications are applications that take direct user input and then generate dynamic SQL that is executed via back-end code. For example say you have a logon form that accepts a user name and password. Once authenticated against the database, the application then sets a session value, or some other token for allowing the user to access the protected data.&lt;br /&gt;Take a logon form for example, here you have two basic form elements, a textbox for accepting a user name, and a password box for the password.&lt;br /&gt;&lt;br /&gt;Dim SQL As String = "SELECT Count(*) FROM Users WHERE UserName = '" &amp; _&lt;br /&gt;username.text &amp; "' AND Password = '" &amp; password.text &amp; "'"&lt;br /&gt;Dim thisCommand As SQLCommand = New SQLCommand(SQL, Connection)&lt;br /&gt;Dim thisCount As Integer = thisCommand.ExecuteScalar()&lt;br /&gt;In the previous code block it executes the built SQL script directly, if count is greater than one, then you know the values entered in for the user name and password were the ones matching the database.&lt;br /&gt;Now with that code in the previous example, suppose someone entered the following string into your username text box: &lt;br /&gt;' or 0=0 --&lt;br /&gt;The apostrophe will close the username value being sent to the SQL query, then pass another argument to the SQL query, after the last argument it then comments out the rest of the query using the "--". Since the second argument they entered into your texbox is an "or" statement, the first check on the user name doesn't matter, and since 0 is always going to equal 0 the script will execute successfully and return a positive logon. Guess what? Your intruder now has access to your application.&lt;br /&gt; Ok so maybe they can logon into your application, but what else can they do? Let's take another example of SQL injection, as in the previous example of using the apostrophe to terminate the value, and proceed on to another argument, lets do this, but using something that can really ruin your application's data and day:&lt;br /&gt;'; drop table users --&lt;br /&gt;Definitely something that can ruin your day. Of course this type of an attack you'll probably notice pretty quick. Other SQL commands can then be entered to determine your database's structure, and return all user names and passwords from the database. You make it even easier for the attacker if you do not provide some ambiguous error message and provide the error message returned from .NET. This error message can provide critical information they need to determine what to enter in your form in order to obtain information.&lt;br /&gt;SQL Injection Prevention&lt;br /&gt;One method of preventing SQL injection is to avoid the use of dynamically generated SQL in your code. By using parameterized queries and stored procedures, you then make it impossible for SQL injection to occur against your application. For example, the previous SQL query could have been done in the following way in order to avoid the attack demonstrated in the example:&lt;br /&gt;Dim thisCommand As SQLCommand = New SQLCommand("SELECT Count(*) " &amp; _&lt;br /&gt; "FROM Users WHERE UserName = @username AND Password = @password", Connection)&lt;br /&gt;thisCommand.Parameters.Add ("@username", SqlDbType.VarChar).Value = username&lt;br /&gt;thisCommand.Parameters.Add ("@password", SqlDbType.VarChar).Value = password&lt;br /&gt;Dim thisCount As Integer = thisCommand.ExecuteScalar()&lt;br /&gt;By passing parameters you avoid many types of SQL injection attacks, and even better method of securing your database access is to use stored procedures. Stored procedures can secure your database by restricting objects within the database to specific accounts, and permitting the accounts to just execute stored procedures. Your code then does all database access using this one account that only has access to execute stored procedures. You do not provide this account any other permissions, such as write, which would allow an attacker to enter in SQL statement to executed against your database. Any interaction to your database would have to be done using a stored procedure which you wrote and is in the database itself, which is usually inaccessible to a perimeter network or DMZ.&lt;br /&gt;So if you wanted to do the authentication via a stored procedure, it may look like the following:&lt;br /&gt;Dim thisCommand As SQLCommand = New SqlCommand ("proc_CheckLogon", Connection)&lt;br /&gt;thisCommand.CommandType = CommandType.StoredProcedure&lt;br /&gt;thisCommand.Parameters.Add ("@username", SqlDbType.VarChar).Value = username&lt;br /&gt;thisCommand.Parameters.Add ("@password", SqlDbType.VarChar).Value = password&lt;br /&gt;thisCommand.Parameters.Add ("@return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue&lt;br /&gt;Dim thisCount As Integer = thisCommand.ExecuteScalar()&lt;br /&gt; &lt;br /&gt;Finally, ensure you provide very little information to the user when an error does occur. If there is database access failure, make sure you don't dump out the entire error message. Always try to provide the least amount of information possible to the users. Besides, do you want them to start helping you to debug your code? If not, why provide them with debugging information?&lt;br /&gt;By following these tips for your database access you're on your way to preventing unwanted eyes from viewing your data.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-3605388021313369007?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/3605388021313369007/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/07/what-is-sql-injection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/3605388021313369007'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/3605388021313369007'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/07/what-is-sql-injection.html' title='What is SQL Injection'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-6836733174123187115</id><published>2009-05-07T03:09:00.001-07:00</published><updated>2009-05-07T03:09:54.195-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Store procedure'/><title type='text'>Call Views in Store procedure</title><content type='html'>Step1) Create a view with name “EmpTblView” as follows:&lt;br /&gt;&lt;br /&gt;create view EmpTblView &lt;br /&gt;as &lt;br /&gt;select EName,Sal &lt;br /&gt;from EmpTbl&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step2) Create procedure which calls the above View as follows:&lt;br /&gt;&lt;br /&gt;create procedure EmpTblSP&lt;br /&gt;as&lt;br /&gt;begin&lt;br /&gt;select * from EmpTblView&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step3) now run the stored procedure as follows:&lt;br /&gt;exec EmpTblSP&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-6836733174123187115?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/6836733174123187115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/05/call-views-in-store-procedure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/6836733174123187115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/6836733174123187115'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/05/call-views-in-store-procedure.html' title='Call Views in Store procedure'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4287412049591913125.post-4962221331202593569</id><published>2009-05-07T03:08:00.000-07:00</published><updated>2009-05-07T21:43:44.042-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Views in SQL Server'/><title type='text'>Views in SQL Server</title><content type='html'>Purpose of Views &lt;br /&gt;&lt;br /&gt;A view is a virtual table. A view serves as a security mechanism. If we have several tables in a database and we want to view only specific columns from specific tables we can go for views. Using view we can avoid the complex queries.&lt;br /&gt;&lt;br /&gt;Views advantages&lt;br /&gt;&lt;br /&gt;1.Change behavior without changing code. You can alter your application at runtime without worrying about breaking code or making a PHP syntax error. (Note: since views that are stored in the database do not have revision control, changes made like this cannot simply be undone... be warned) &lt;br /&gt;&lt;br /&gt;2.Many options for presentation. Different view types mean that you can change the presentation of the data you fetch. &lt;br /&gt;&lt;br /&gt;3.Black box. You don't need to write or read any PHP code to get started with Views. &lt;br /&gt;&lt;br /&gt;4.Data safety. Malicious users can do a lot of damage without proper data safety testing. Views goes through the trouble to scrub all data it presents, so you can feel assured that as long as the module providing the data properly implements the Views API, its data will be safe. &lt;br /&gt;&lt;br /&gt;5.Open architecture. If you are a developer, you can write to the Views API and add features, presentation styles and behaviors to Views in custom modules. These are then reusable in other views that you later create. &lt;br /&gt;&lt;br /&gt;6.Community benefit. You will be the recipient of an enormous amount of Views code that is being contributed and improved by the community. There will be Views features available tomorrow that weren't here today. There will be people fixing Views bugs while you sleep. This won't be the case for your custom code. &lt;br /&gt;&lt;br /&gt;7.Reuse views. Build a basic view that does something useful, export it, and then use it on the next site you build. &lt;br /&gt;&lt;br /&gt;8.Tight integration with CCK, Voting API, and many other modules that you might already be using. Every contrib module can potentially extend Views, so make sure and take inventory of what modules you plan to use when evaluating Views on its own. &lt;br /&gt;&lt;br /&gt;9.Panels integration. Panels 2 is especially cool, and the Views integration is spectacular. Do some research here before you decide against Views. &lt;br /&gt;&lt;br /&gt;10.Programmatic handling of views. You can instantiate views objects in PHP code and manipulate them in many ways. The Views API provides several points of access to the views object, so if you are really unhappy with what you can achieve with the Views UI, you can grab control of the object itself. &lt;br /&gt;&lt;br /&gt;11.Documentation. There is more documentation about Views than there is about your custom code. &lt;br /&gt;&lt;br /&gt;12.Page, menu and block integration. Views gives you page views and block views, and lets you instantiate menu items as well. &lt;br /&gt;&lt;br /&gt;13.Views 2. Super cool and way more flexible than Views 1. Research Views 2 before deciding against Views. &lt;br /&gt;&lt;br /&gt;14.Exposed filters: Views gives you a lot of control over creating form elements to filter your view. Writing FAPI code is bulky and verbose. Nothing against FAPI, but creating all those dropdown selects, autocomplete text fields and checkboxes is a lot of work. You can still use formalter to get to the exposed filters submission and validation handlers, so you don't lose any control by going with Views here. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Restrictions of View &lt;br /&gt;&lt;br /&gt;We cannot create a trigger or an index on a view. The only way to change the sort of the result set in a view is to use ORDER BY clauses in your select statement that runs against the view. A view contain up to 250 columns.&lt;br /&gt;&lt;br /&gt;We cannot use the UNION operators within a CREATE VIEW statement. But we can use the UNION operator to merge two views into a single result set.&lt;br /&gt;&lt;br /&gt;Modification statements (INSERT, UPDATE, DELETE) are allowed on multi table views if the statement affects only one base table at a time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4287412049591913125-4962221331202593569?l=kalitsqlserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kalitsqlserver.blogspot.com/feeds/4962221331202593569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/05/views-in-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/4962221331202593569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4287412049591913125/posts/default/4962221331202593569'/><link rel='alternate' type='text/html' href='http://kalitsqlserver.blogspot.com/2009/05/views-in-sql-server.html' title='Views in SQL Server'/><author><name>kalit</name><uri>http://www.blogger.com/profile/06926361249526760368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='25' height='32' src='http://1.bp.blogspot.com/_zpFefy31Gkc/SYKUiboDxmI/AAAAAAAAAAM/jjnmmi0D6m8/S220/NetSet.JPG'/></author><thr:total>0</thr:total></entry></feed>
