My Thoughts & Views

Archive for the ‘SQL’ Category

How To: Delete Duplicate Rows from a Table

Posted by: intelbot on: August 15, 2009

Problem: You have a table (table1) & values as above, and it contains the duplicate records as shown, how will you delete the duplicates? Solution: Use following query, the records shown in the below image will be deleted delete from table1 where empid not in (select max(empid) from table1 group by empName,empEmail,empCity);

Online SQL Formatter Tool

Posted by: intelbot on: July 22, 2008

I came across a wonderful online tool from my Team Lead,which helps to format the SQL queries. Its very handy and very useful. http://www.sqlinform.com

Protecting your Enterprise databases

Posted by: intelbot on: July 15, 2008

SQL Server has a SQL Profiler tool, which helps Security Administrators to have a complete view of users who have logged in or out of the server.This information can be used for legal purposes to document activity & for technical purposes to track security policy violations. For more information please go through the documentation provided [...]

Sequence Generator Function in SQL

Posted by: intelbot on: May 2, 2008

Here is the sequence generator function written in SQL, which when passed starting and end numbers will generate the rest sequence automatically. CREATE FUNCTION fn_p( @exp int)RETURNS @result TABLE (id int)ASBEGIN DECLARE @pow int SET @pow = POWER(10, @exp) INSERT @result SELECT 0 id UNION ALL SELECT 1 * @pow UNION ALL SELECT 2 * [...]

nth Highest Record using SQL

Posted by: intelbot on: January 10, 2008

The following query gives 3rd highest records from SQL. SELECT TOP(1) salary FROM ( SELECT TOP(3) salary FROM Emp ORDER BY salary DESC) Keywords: getting nth highest record, nth highest record, TOP

How to: Get Table names and column names in SQL Server

Posted by: intelbot on: December 28, 2007

1. Following Query displays all the table names. Query : select name from sys.objects where type=‘u’ ; 2. Following Query displays all the columns in a table Query : select Table_Name,Column_Name from INFORMATION_SCHEMA.COLUMNS ;

Reindexing the entire sql server database

Posted by: intelbot on: December 13, 2007

How To: Re index Entire database Applies to : SQL Server 2000/ 2005 Recently i moved some database to new server and wanted to reindex entire Sql Server database, as people were complaining about slow response for our .NET WinForms application. I thought it might save some body’s hours of time who is searching for [...]


Follow

Get every new post delivered to your Inbox.