Listing a specified field in a database
Sometimes you know the field name, but forget about in which table it is.
This small procedure will help you ;).
USE AdventureWorks — the database must be specified
GO
CREATE PROCEDURE procAllTableswithField(@columnname nvarchar(400)='%')
AS
SELECT OBJECT_NAME(sys.columns.object_id) AS "Table",
RTRIM(sys.columns.name) AS "Column"
FROM sys.columns INNER JOIN sys.objects
ON sys.columns.object_id = sys.objects.object_id
WHERE sys.columns.name Like @columnname AND sys.objects.type = 'u'
--- list all tables with specified field
EXEC procAllTableswithField 'CustomerID'
EXEC procAllTableswithField 'cust%'
EXEC procAllTableswithField
You can download it here ;)
| Print article | This entry was posted by Torsten Schuessler on 2006-12-14 at 09:37:10 . Follow any responses to this post through RSS 2.0. |
Tag cloud
backup «best practices» books ctp «cumulative update» datetime denali dmv ebook «failover cluster» humor i/o index indexoptimize integrity links loginproperty maintenance «ms sql server 2008» performance php profiler «reporting services» reviews «ross mistry» rtm serverproperty «service pack» «service pack 3» sharepoint sp_msforeachdb «sql 2012» «sql pass» «sql server» «sql server 2005» «sql server 2008 r2» «sql server 2012» «sql server builds» sqlcat «sqlpass franken» ssms ssmstoolspack «stacia misner» t-sql technet «technical note» tools troubleshooting whitepapers «windows server 2003»






