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 tosc on 2006-12-14 at 09:37:10 . Follow any responses to this post through RSS 2.0. |
Tag cloud
administration backup «best practices» books bug ctp «cumulative update» datetime demo dmv ebook humor index indexoptimize integrity kbfix links maintenance «ms sql server 2008» pass performance php «reporting services» reviews rtm serverproperty «service pack» «service pack 2» «service pack 3» «service packs» sharepoint sp_msforeachdb «sql server» «sql server 2005» «sql server 2008 r2» «sql server 2012» «sql server 2014» «sql server builds» sqlcat sqlpass «sqlpass franken» ssms ssmstoolspack «system views» t-sql «technical note» tempdb tools version whitepapers