Syndicate

Object search in MSSQL 2005 Print E-mail
Written by Stanislav Duben   
Friday, 20 July 2007
Object search in MSSQL 2005In query analyzer for Microsoft SQL 2000 you can search objects easily, just open Query Analyzer and press F4. In Microsoft SQL Server Management Studio for SQL 2005, this search functionality has been removed. (Microsoft said that nobody uses this function so it's useless), no comment for this reason. We need this functionality, so how to do it?
You need to use a script for searching in system objects. Basic script for all common objects is below.

DECLARE @SEARCHSTRING VARCHAR(255), @notcontain Varchar(255)
SELECT @SEARCHSTRING = 'Text I am searching', @notcontain = ''
SELECT DISTINCT sysobjects.name AS [Object Name] , case when sysobjects.xtype = 'C' then 'CHECK constraint' when sysobjects.xtype = 'D' then 'Default or DEFAULT constraint' when sysobjects.xtype = 'F' then 'Foreign Key' when sysobjects.xtype = 'FN' then 'Scalar function' when sysobjects.xtype = 'P' then 'Stored Procedure' when sysobjects.xtype = 'PK' then 'PRIMARY KEY constraint' when sysobjects.xtype = 'S' then 'System table' when sysobjects.xtype = 'TF' then 'Function' when sysobjects.xtype = 'TR' then 'Trigger' when sysobjects.xtype = 'U' then 'User table' when sysobjects.xtype = 'UQ' then 'UNIQUE constraint' when sysobjects.xtype = 'V' then 'View' when sysobjects.xtype = 'X' then 'Extended stored procedure' end as [Object Type] FROM sysobjects WHERE sysobjects.type in ('C','D','F','FN','P','K','S','TF','TR','U','V','X') AND sysobjects.category = 0 AND CHARINDEX(@SEARCHSTRING,sysobjects.name)>0 AND ((CHARINDEX(@notcontain,sysobjects.name)=0 or CHARINDEX(@notcontain,sysobjects.name)<>0))

@SEARCHSTRING is text in name we are searching. If we want exclude some text we can fill @notcontain variable.

For restriction on some requested objects we need to comment some parts of code, in WHEN part and change condition sysobjects.type in ('C','D','F','FN','P','K','S','TF','TR','U','V','X').

List of type objects, we can use:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
IF = Inlined table-function
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
R = Rule
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
V = View
X = Extended stored procedure

Quote this article on your site | Views: 4792 | Print

  Comments (2)
RSS comments
 1 Written by This e-mail address is being protected from spam bots, you need JavaScript enabled to view it website, on 24-09-2007 16:41
Funny, I know many dba's who used to rely on the SQL 2000 Object Search. Guess all these MCDBA's are "nobody" in Microsoft's eyes. Yes, there are better tools and scripts out there but it was nice to be able to use object search for quick searches.
 2 Written by This e-mail address is being protected from spam bots, you need JavaScript enabled to view it website, on 21-04-2008 09:15
I'm agree with you.

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Personal verbal attacks will be deleted.
  • Please don't use comments to plug your web site. Such material will be removed.
  • Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
  • Keep in mind that the above process only applies if you simply entered the wrong security code.
Name:
E-mail
Homepage
BBCode:Web AddressEmail AddressBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
Comment:

MathGuard security question, please solve:

TKW          R       
I 4    W    WN    FOW
F 6   YMF    C       
X C    P     6    86P
774         3RA      

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved

Tag it:
Delicious
Digg
YahooMyWeb
Technorati
 
< Prev   Next >