• Increase font size
  • Default font size
  • Decrease font size
Home T-SQL Column in a database search

Search in a database column

E-mail Print
(1 vote)




database_1_search_128 Looking for a particular column name in one of your tables in your SQL Server database, but it does not find here. This can be a time consuming job if you do not know the following trick. In SQL Server 2005 lacks a search function to quickly find a column in databases. This can sometimes still be useful if you are looking for a particular column but do not know what table this is. The solution is a relatively simple query.



  O. NAME Tabelnaam, SELECT O. NAME Table Name,
  Kolomnaam C. NAME Column Name
  sys. columns C FROM sys. Columns C
  sys. objects O ON C. OBJECT_ID = O. OBJECT_ID INNER JOIN sys. Objects O ON C. OBJECT_ID = O. OBJECT_ID
  C. NAME LIKE '%DebiteurNaam%' C. WHERE NAME LIKE '%% Customer Name "
  O. NAME , ORDER BY O. NAME,
  C. NAME




Result


Obviously it is not very useful for every time you examine this entire column in typing queries, so there is the following Stored Procedure, the task very straightforward process:
  [ dbo ] . [ pcdGetColumns ] CREATE PROCEDURE [dbo]. [PcdGetColumns]
  ( 256 ) @ Column name nvarchar (256)
  - Search for a column name in a database
  - EXECUTE pcdGetColumns'% name% "
  AS
  BEGIN

  O. NAME Tabelnaam, SELECT O. NAME Table Name,
  Kolomnaam C. NAME Column Name
  sys. columns C FROM sys. Columns C
  sys. objects O ON C. OBJECT_ID = O. OBJECT_ID INNER JOIN sys. Objects O ON C. OBJECT_ID = O. OBJECT_ID
  C. NAME LIKE @kolomnaam WHERE C. NAME LIKE @ Column name
  O. NAME , C. NAME ORDER BY O. NAME, C. NAME

  END



Copyright 2008. All Rights Reserved.

Trackback (0)

TrackBack URI for this post

Comments (2)

RSS feed Comments
...
0
You might also be able to use the INFORMATION_SCHEMA's:

Code:
SELECT COLUM_NAME, TABLE_NAME FROM WHERE INFORMATION_SCHEMA.COLUMNS
COLUMN_NAME LIKE '%%'


Or is this not always useful?
, november 15, 2008 Arjan Fraaij , November 15, 2008
  • Report abuse
  • 1
  • Report abuse
  • Report abuse
...
63
I know your statement yet but I still prefer a stored procedure, purely for convenience. You do not text that complete lap every time to enter!
, november 15, 2008 kraaitje , November 15, 2008
  • Report abuse
  • 0
  • Report abuse
  • Report abuse

Write comment

bold italicize underline strike url image quote smile wink laugh grin angry sad shocked cool tongue kiss cry
| groter smaller | bigger
security image
Write the displayed characters

busy