Some SQL Code that I've written that have helped me in the past:
Count Rows in a Flat File Table
cpColumnRowCounts
I used the procedure to count rows within the flat file table. Columns that had repeating groups or a very low distinct row count were columns that needed to be seperated into their own table. I like using cp, for custom procedure, to prefix my stored procedure names. This way they appear at the top of the list, before any system procedures and most other procedures, in SQL Studio Manager.
Automatically defrag indexes
sp_IndexDefrag
This procedure automates checking for index fragmentation and defrags when below a threshold parameter. Logical Scan Fragmentation and, to a lesser extent, Extent Scan Fragmentation values give the best indication of a table's fragmentation level. Both these values should be as close to zero as possible (although a value from 0% through 10% may be acceptable). It should be notedthat the Extent Scan Fragmentation value will be high if the index spans multiple files. I prefixed the procedure with sp_ because I wanted to be able to store it once in the Master database and be able to run it from any database.
Batch Grant Permissions
This code will quickly grant execute rights to either an object or all objects for a particular user or all users in that database. I prefixed the procedure with sp_ because I wanted to be able to store it once in the Master database and be able to run it from any database.