Wednesday, March 10, 2010 Register   Login   
   You Are Here: Scripts/Tools » SQL Server Scripts Categorized      

Submit Articles  Upload Scripts   Submit Tips   Start a Blog   Upload Tools   Post Job Openings   Submit Your Resume   About SQL Community

 Script Categories
  
  

To download resources, Please Login/Register

  

 

Search
DELETE OLD BACKUP FILES - VBS
Thumbnail

 

Dim DateLimit
Dim fso, flder, fs, f, backFolder
backFolder = "W:\SQLBackups\SQLLiteSpeed\FullBackup"
 
set fso = createObject("Scripting.FileSystemObject")
set flder = fso.getfolder(backFolder)
set fs = flder.files
 
for each f in fs
   if f.DateLastModified < DateAdd("d", -1, date) then
     f.delete
   end if
next
 
backFolder = "W:\SQLBackups\SQLLiteSpeed\DifferentialBackup"
 
for each f in fs
   if f.DateLastModified < DateAdd("d", -1, date) then
     f.delete
   end if
next
 
backFolder = "W:\SQLBackups\SQLLiteSpeed\TransactionalLogBackup"
 
for each f in fs
   if f.DateLastModified < DateAdd("h", -40, date) then
     f.delete
   end if
next
 
Set fs = nothing
Set flder = Nothing
Set fso = Nothing
Set fs = Nothing
Set f = Nothing
Set backFolder = Nothing
 


File size1 K
Downloads17
DateMon 11/09/2009 @ 04:31
AuthorChandran Babu Subramanian
EMailbabu_sql@yahoo.com
RATING:     

Searching Word in Database
Thumbnail
Hello all

This procedure will find the a particular word in Database.

Note:might be some other DBA's also published same kind of stuff.


File size2 K
Downloads157
DateMon 09/21/2009 @ 02:02
AuthorSreenivasarao ponguru
EMailsnivas4support@gmail.com
RATING:     

Grouping Sets in SQL Server 2008
Thumbnail

 



File size1 K
Downloads179
DateFri 08/07/2009 @ 03:38
AuthorAmol Rajmane
EMail
RATING:     

A script to select columns using wildcards
Thumbnail

sp_wcProject is a stored procedure designed to allow you to easily define the projection of columns used in a table, view, or table valued function and then optionally run the query. The column names may be specified using wildcards, hence the "wc" name prefix.  You can also specify to include all columns except the ones enumerated.

This procedure is particularly useful when making ad hoc queries against system objects, such as
sys.databases, which return a large number of columns, many of which are related via common substrings such as "ansi" or "is_", etc. You can also use it to display and/or capture the generated SQL query.  The displayed width of string variables, viz., CHAR, VARCHAR, etc. may be limited to a maximum size and the string data may be either right or left justified within the maximum specified size.

Run the proc with no arguments to view the full documentation and see the additional bells and whistles it provides as well as some examples. Also provided below is a set of sample queries using the proc to show how it can be used.

set nocount on
use master

declare @sql VARCHAR(8000)
set @sql=''
exec sp_wcProject 'sys.databases','name,database_id,reco%,%ansi%', @sql out
print @sql
exec (@sql)

exec sp_wcProject 'master.sys.database_principals',@maxWidth=18
exec sp_wcProject 'master.sys.database_principals','name,type%,%[_]id,%role%','P',@where='type=''S'''        -- 'P' means print the SELECT statement instead of running it

exec sp_wcProject 'sys.databases','name,database_id,%desc,%ansi%',@where='owner_sid<>1',@orderBy='name',@maxWidth=10
exec sp_wcProject 'sys.databases','name,database_id,%desc,%ansi%,-log%,-page%',@where='owner_sid<>1',@orderBy='name',@maxWidth=10
exec sp_wcProject 'sys.databases','-source%,-co%,-is%,-%sid,-%guid,-log%',@where='owner_sid<>1',@orderBy='name',@maxWidth=10
exec sp_wcProject 'sys.databases','name,is%,-%on'

exec sp_wcProject 'dbo.authors','%name%'  -- This will fails unless there is an "authors" object in the master db
exec sp_wcProject 'pubs.dbo.authors','au%',@orderby='au_lname,au_fname'
exec sp_wcProject 'northwind.sys.sysfiles','%name%,%id','p'        -- 'p' means print the SELECT statement instead of running it

exec sp_wcProject 'sys.master_files','%name%,%desc,is%',@orderbyname=0
exec sp_wcProject 'sys.master_files','%name%,%desc,is%',@orderbyname=0,@maxwidth=20
exec sp_wcProject 'sys.master_files','%name%,%desc,is%',@orderbyname=1,@maxwidth=20
exec sp_wcProject 'sys.master_files','%name%,%desc,is%,-%only',@orderbyname=1,@maxwidth=20

exec sp_wcProject 'pubs.sys.fn_dblog(null,null)',
                  'current_lsn,operation,page_id,slot_id%row%,Checkpoint%,M%LSN,spid,Tran%Begin%,lock%,%contents%'
exec sp_wcProject 'pubs.sys.fn_dblog(null,null)',
                  'current_lsn,operation,page_id,slot_id%row%,Checkpoint%,M%LSN,spid,Tran%Begin%,lock%,%contents%',
                  @maxWidth='-22B'    -- To add a trailing "B" to convert binary to char you must pass a string value
exec sp_wcProject 'pubs.sys.fn_dblog(null,null)',
                  'current_lsn,operation,page_id,slot_id%row%,Checkpoint%,M%LSN,spid,Tran%Begin%,lock%,%contents%',
                  @maxWidth=-15

exec sp_wcProject 'pubs.dbo.discounts'
exec sp_wcProject 'pubs.dbo.discounts','-%qty',@maxWidth=10

exec sp_wcProject 'pubs.dbo.authors'
exec sp_wcProject 'pubs.dbo.authors',@maxWidth=5
exec sp_wcProject 'pubs.dbo.authors',@maxWidth=-5



File size15 K
Downloads119
DateThu 07/30/2009 @ 06:20
AuthorAnthony Zackin
EMail
RATING:     

Index size
Thumbnail

DECLARE

 

@IndexId INT,
@IndexSize BIGINT,
@TableName NVARCHAR(256),
@IndexName VARCHAR(256) @TableName = ''
SET @IndexName = ''
SET @IndexSize = 0

SELECT

@IndexId = index_id
FROM sys.indexes
WHERE object_id = OBJECT_ID(@TableName) AND name = @IndexName

SELECT

@IndexSize = @IndexSize + (avg_record_size_in_bytes * record_count)
FROM sys.dm_db_index_physical_stats (DB_ID(), OBJECT_ID(@TableName), @IndexId , NULL, 'DETAILED')

SELECT

@IndexSize as IndexSizeBytes

 

 

SET

-- Replace with actual table name and with index name



File size1 K
Downloads98
DateTue 07/28/2009 @ 07:57
AuthorAmol Rajmane
EMailrajmane@live.com
RATING:     

< PREVIOUS PAGE

  1 of 14  

NEXT PAGE >

Share

Disclaimer: This script, is provided for informational purposes only and SQL Server Community (aka: WWW.SQLCOMMUNITY.COM) or the author of this script makes no warranties, either express or implied. This script, scenarios and other external web site references, is subject to change without notice. The entire risk of the use or the results of the use of this script remains with the user.

     SQL Server Tips Home          SQL Server Articles Home         SQL Server Scripts Home

SQL Server  |  SQL Server Forums  |  Articles  |  Scripts/Tools  |  Tips & Tricks  |  Blogs  |  Job Board  |  Videos
Copyright 2007 by www.sqlcommunity.com    Terms Of Use   Privacy Statement