Scripts

Technical Article

Find Nth Max-Min Record - The Efficient Way!

It is quite often that we need to find Nth (5th or 8th or 10th) maximum or minimum number of record from the record set. The solution is different in MS SQL than in Oracle because we have RowNum in Oracle. Some time ago I got the same problem with a massive table of more […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2005-07-22 (first published: )

1,077 reads

Technical Article

Deleting Sets of Rows in huge table

There was a problema user was reflecting http://groups.yahoo.com/group/sqlcon/message/1119What I did was following steps1. Divide the count of table into segments for divide2. Then use the even Odd functionality for smooth looping3. Use a simple while loop and SET ROWCOUNT functionality for further deletions across table with checkpoint4. It saved the log swell up and resources […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2005-07-20 (first published: )

303 reads

Technical Article

Sproc to get First Day of the Month,First Weekday ETC

First Day of the Month, First Weekday, Total Days in this Month, Days In First WeeK, Days In Last Week,Total Weekend Days sample output: Given Date:Jul 16 2005 12:00AM First Day of the Month:7/1/2005 First Weekday (sun=1,sat=7):6 Total Days in this Month:31 Days In First Week:2 Days In Last Week:1 Total Weekend Days:10

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2005-07-15 (first published: )

235 reads

Technical Article

Drop and Add Foreign Keys

Have you tried using DTS to load a database and those pesky foreign keys mess you up? This is actually two scripts, one to generate the SQL needed to drop all the Foreign Keys in a database and another to Add the Foreign Keys back when you are done. I've thrown in Disabling and Enabling […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(9)

You rated this post out of 5. Change rating

2005-07-13 (first published: )

3,089 reads

Technical Article

Shrink Log file for all Databases

I use this script to shrink the log files for development databases. The intention is keep the log files as small as possible when the database is not in use. By scheduling this script I can control when it happens as oppose to using auto shrink.

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(2)

You rated this post out of 5. Change rating

2005-07-08 (first published: )

2,541 reads

Technical Article

Search All Fields in db for a Specific String

forums question came up where someone needed to search every varchar/char field in the database, and find any table/field that had a specific value (ie ip address, email, servername) we all agree that a monster scan like this is bad, but bad or not, sometimes you need to do it.it returns results that look something […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2005-07-07 (first published: )

283 reads

Technical Article

Import databases using backups v 2

Import database from source server using full and transaction log backups as recorded in msdb. Use it to import one or more databases to your development environment, to test your backups regularly or to move databases to a new server. To move to a new server, take a transaction log backup and put all in […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2005-07-04 (first published: )

242 reads

Blogs

Architecting Zero Downtime Deployments–Day of Data Boston

By

Here are the resources for my talk at Day of Data Boston. Slides –...

The Book of Redgate:A Prehistory

By

I’ve covered the values in a number of previous posts on the Book of...

Evidence-bound: what AgentDBA will and won’t link

By

When the evidence names the database, it says so. When it doesn’t, it stops....

Read the latest Blogs

Forums

Alamat BCA KCP Tanah Abang 2 Telp:08218520154

By R4nt4u

WhatsApp CS 628218520154 Jl. Tanah Abang II No.49 & 51, RT.1/RW.4, Petojo Sel., Kecamatan...

ALAMAT BCA KCU GUNSA 45 Telp:08218520154

By m4rt1n4

WhatsApp CS 628218520154 Jl. Gn. Sahari No.45, RT.7/RW.5, Gn. Sahari Utara, Kecamatan Sawah Besar,...

SQL Server Storage Optimization: Multiple Files in a Filegroup vs Dedicated File

By abdalah.mehdoini

Hello, I would like to get some feedback regarding the best storage optimization strategy...

Visit the forum

Question of the Day

Finding Trailing Spaces

I have some data in a SQL Server 2025 database. It looks like this for the dbo.Customer table:

CustomerID CustomerName PreferredName
1          Steve        Steve               
2          Andy         Andy               
3          Brian        Brian               
4          Allan        Allan               
5          Devin        Devin               
6          Steve        Steve               
7          Sally        Sally
I want to detect which names have a single trailing space. The CustomerName is a varchar() and the PreferredName is a CHAR(). Does this query detect the problem rows?
SELECT 
       CustomerID,
       CustomerName,
       PreferredName
FROM Customer
WHERE CustomerName <> RTRIM(CustomerName)
OR PreferredName <> RTRIM(PreferredName);

See possible answers