Removing Duplicates through SQL Query
Suppose we have a table in SQL Server, that has duplicates in it. CREATE TABLE T1 ( ProductName varchar(50) ) INSERT INTO T1 VALUES (‘Computer’), (‘Computer’), (‘Printer’), (‘Printer’), (‘Printer’), (‘Scanner’), (‘Scanner’), (‘Scanner’), (‘Scanner’), (‘Camera’), (‘Flash Drive’), (‘Flash Drive’) now use the following query, that will remove duplicates in the temporary table that we just created: [...]
SqlBulkCopy – Bulk Insertion in SQL Server from .NET
November 5, 2009 by Nauman · Leave a Comment
Many a times there come a scenario when you have to insert large number of records in sql server. There are number of ways to implement this scenario: through looping techniques to call insert statements for one record at a time. Serialize the data in CSV or XML format and send them as a parameter [...]
Write a Custom SQL Scripter (Generating bulk insert, update statements)
There are always some static tables in our database that needs to always have some default values in them, for our custom application development. Usually a huge amount of data resides in these tables because they are slowly changing dimension fields. So when it is time to transfer this data the question arises how to [...]
Validating string for numeric values in SQL Server
November 5, 2009 by Nauman · Leave a Comment
What to do when you have a large string and you have to validate whether this string only contain digits or not. A straight thing that comes in our mind is to use a looping technique to traverse all the characters in the string and validate each character to be a digit. But how could [...]
SQL Server permissions
November 1, 2009 by Nauman · Leave a Comment
Permissions on data are one of the most critical aspects of database administration. If you’re too strict as a database administrator then your users will not be able to do their jobs. If you’re not lenient, then data can be compromised or even leaked. It is a very fine balance to control. The ability to [...]
How To Calculate the Number of Week Days Between two Dates
If the start date and end date are both week days, then the total number of week days in between is simply: (total difference in days) – (total difference in weeks) * 2 DateDiff(dd, @start, @end) – DateDiff(ww, @start, @end)*2 … since the DateDiff() function with weeks returns the number of week "boundaries" that are [...]
SQL Server Version
November 1, 2009 by Nauman · Leave a Comment
If you need to know the version you are currently running of SQL Server you can easily get it by running the following query. SELECT ‘ SQL Server ‘ + CONVERT ( varchar ( 100 ),SERVERPROPERTY( ‘ productversion ‘ )) + ‘ – ‘ + CONVERT ( varchar ( 100 ),SERVERPROPERTY( ‘ productlevel ‘ )) [...]
Simple script to backup all SQL Server databases
November 1, 2009 by Nauman · Leave a Comment
Problem Sometimes things that seem complicated are much easier then you think and this is the power of using T-SQL to take care of repetitive tasks. One of these tasks may be the need to backup all databases on your server. This is not a big deal if you have a handful of databases, but [...]
Demand Paging (Custom Paging) in ASP.NET with SQL Server
November 1, 2009 by Nauman · Leave a Comment
Many a times we need to present bulk data to the user in our day to day application development. Loading all data at one shot is okay when we have few hundreads data but when it comes to thousands of thousands records, it hardly work. In scenario like this we need to go for custom [...]
Tracking object (Table, SP etc) changes in SQL Server 2005
November 1, 2009 by Nauman · Leave a Comment
DBA’s often need to track the changes being made to database objects such as tables, user defined functions and store procedures etc. Following article aims at providing the readers on how the changes being made to the database can be tracked with minimal effort. To get into details, i would first give preferrance to the [...]