Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

The Ultimate Column Searcher

By Jesse Roberge,

By Jesse Roberge -
Update - Fixed existance check for drop

Searches for columns with names containing @Colname that belong to tables with names containing @TableName (optional) or schemas with names containing @SchemaName (optional). Gives size and rowcount for tables.
LIKE wildcards are not automatic, which allows for easy 'begins with', 'ends with', and 'equal to' queries.
Requires the VIEW DATABASE STATE database permission.

Update 2009-01-14:
Fixed Rows Output - Was being erroneously multiplied by (1+#NonClusteredIndexes)
SUM(Rows) Should be SUM(CASE WHEN index_id BETWEEN 0 AND 1 THEN row_count ELSE 0 END)

Update 2009-09-21:
Fixed column_id sorting, now sorts correctly as an int rather than a (converted) string
Added searching of system tables

Update 2009-10-01:
Fixed system object searching (sys.columns is also split-in-two; DMV / Catelog views do not have sys.dm_db_partition_stats entries)
Added optional output of non-materialized virtual table objects
Size output columns will be NULL for these.
All system catelog views and DMVs are non-materialized.

Required Input Parameters
@ColumnName sysname Filters columns. Can use LIKE wildcards.

Optional Input Parameters
@SchemaName sysname='' Filters schemas. Can use LIKE wildcards. All schemas if blank.
@TableName sysname='' Filters tables. Can use LIKE wildcards. All tables if blank.
@VirtualTables TinyInt=0 Search virutal tables (views, table-valued functions) - Size output will be NULL for these
@UserOjbects TinyInt=1 Search user objects
@SystemObjects TinyInt=0 Search system objects
@Sort TinyInt=1 1=sort by SchemaName, TableName, ColumnID; 2=sort by SchemaName, TableName, ColumnName

EXECUTE Util_ColumnSearch '%price%'
EXECUTE Util_ColumnSearch @SchemaName='dbo', @Tablename='cart%', @Columnname='%price%'

Licensed under the L-GPL - a weak copyleft license - you are permitted to use this as a component of a proprietary database and call this from proprietary software.
Copyleft lets you do anything you want except plagarize, conceal the source, proprietarize modifications, or prohibit copying & re-distribution of this script/proc.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU Lesser General Public License for more details.

see <> for the license text.


Total article views: 1377 | Views in the last 30 days: 1
Related Articles

How to get schemaname, tablename, identity column, foreign key constraints

How to get schemaname, tablename, identity column, foreign key constraints


Full Text search option

Full Text search option


SQL Server 2000 and 2005 licensing



Serach option

Search option should include all topics


The Ultimate Precompiled Procedure Searcher

Searches precompiled procedures for the provided search string, optionally limiting to names matchin...

maintenance and management    
sql server 2005    

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones