Posts

Showing posts from January, 2010

Find Nth max/min Salary in SQL server

SELECT * FROM temp1 t1 WHERE n - 1 = ( SELECT COUNT(DISTICNT ( sal )) FROM temp1 t2 WHERE t2.sal < t1.sal ) SELECT TOP 1 * FROM ( SELECT DISTINT TOP n sal FROM temp1 ORDER BY sal DESC) AS t ORDER BY t.sal ASC In sql server 2005 WITH MyCTE AS(  SELECT t_id,   sal,   DENSE_RANK() OVER(ORDER BY sal DESC) as rank1  FROM temp1  ) SELECT TOP 1 t_id, sal, rank1 FROM MyCTE WHERE rank1 = n Any updates/comments are appreciated.

Triggers

Definitions: It is special kind of Stored Procedure which is executed whenever specific event is occurred in/on a table or database 2 types in Sql server 2000: 1. DML Trigger Instead of triggers After triggers 3 types in Sql server 2005: •  DML Triggers Instead of triggers After triggers •  DDL Triggers •  CLR Triggers 2 types in Oracle: Row Level Triggers Statement Triggers

Data Integrity

Data Integrity falls into 1. Entity Integrity 2. Domain Integrity 3. Referential integrity 4. User defined integrity Entity Integrity: Defines row as unique instance of an entity for a particular table Domain Integrity: Is the validity of entries for a given column enforced by i. restricting Type ii. format iii. Range of possible E.g.: CHECK constraints, UNIQUE constraints, and DEFAULT constraints Referential Integrity: Preserves defined relationships between tables when altered or deleted. E.g.: Check, Foreign key User defined Integrity: Business rules can be enforced using triggers and stored procedures. Reference: http://odetocode.com/Articles/79.aspx

Sortings

Selection Sort : 1. Find the minimum value in the list 2. Swap it with the value in the first position 3. Repeat the steps above for the remainder of the list (starting at the second position and advancing each time) Eg: 64 25 12 22 11 11 25 12 22 64 11 12 25 22 64 11 12 22 25 64 11 12 22 25 64 Bubble sort Let us take the array of numbers "5 1 4 2 8", and sort the array from lowest number to greatest number using bubble sort algorithm. In each step, elements written in bold are being compared. First Pass: ( 5 1 4 2 8 ) ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps them. ( 1 5 4 2 8 ) ( 1 4 5 2 8 ), Swap since 5 > 4 ( 1 4 5 2 8 ) ( 1 4 2 5 8 ), Swap since 5 > 2 ( 1 4 2 5 8 ) ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. Second Pass: ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) ( 1 2 4 5 8 ), Swap since 4 > 2 ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) ( 1 ...

Delete vs Truncate in SQL SERVER

SQL Server commands Delete vs Truncate Delete Command: 1.We can delete all or specific rows using WHERE clause in a table 2. Logs are maintained for deleted records 3. Slower than Truncate because of logging 4. Identity column value wouldn’t be reset after deleting all the records 5. We can rollback the deleted records, since logs are maintained in the temp db. Eg: DELETE "table name" Truncate Command: 1.We can not use WHERE clause in a table 2.Logs are not maintained for deleted records 3.Faster than Delete because of logging is not done 4.Identity column value will be reset after truncating records 5. We can't roll back records which are truncated Eg: TRUNCATE TABLE "table name"

Assembly in .NET

http://articles.techrepublic.com.com/5100-10878_11-5032712.html

MOSS 2007 Installations

Follow up this link for MOSS 2007 Installation for a trial version http://www.codeproject.com/KB/sharepoint/Setup_Virtual_SharePoint.aspx http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=67f93dcb-ada8-4db5-a47b-df17e14b2c74