Blog Stats
  • Posts - 8
  • Articles - 0
  • Comments - 4
  • Trackbacks - 0

 

Monday, June 16, 2008

In SQL Server, search ALL objects for text

Persons familiar with TOAD for Oracle know about the fairly elaborate search function that lets you search for particular text in procedures, functions, views, column names, triggers, pretty much anything.

There’s a way to do that in SQL Server as well, though you kind of have to "do it yourself." 

Use the query below.  Make sure that you are "in" the database that you mean to search before you run this query.

select * from sysobjects o, syscomments c where o.id=c.id

and c.text like '%your search text here%'

You can also limit your search by object type.  For example:

select * from sysobjects o, syscomments c where o.id=c.id

and c.text like '%mysearchstring%'

and xtype='P' --search stored procedures only

The complete list of types is below.  For more information, see:

http://articles.techrepublic.com.com/5100-9592_11-6142579.html

  • C: Check constraint
  • D: Default constraint
  • F: Foreign Key constraint
  • L: Log
  • P: Stored procedure
  • PK: Primary Key constraint
  • RF: Replication Filter stored procedure
  • S: System table
  • TR: Trigger
  • U: User table
  • UQ: Unique constraint
  • V: View
  • X: Extended stored procedure
  • posted @ Monday, June 16, 2008 3:55 PM | Feedback (0)

    Tricky OO: When 'isa' isn't

    This is something that a friend brought to me out of a Java book. It’s an interesting question that appears subtle at first but it’s obvious (I think) when you think about what’s really going on in the context of OO. I’ve seen this question also on BrainBench tests. It may even come up in an interview – trust me.

    The question goes something like this.

    "The below will compile but will give a runtime casting error. Why? Assume that class MyDerived is derived from class MyBase."

    MyBase theBase = new MyBase();

    MyDerived theDerived = (MyDerived)theBase;

    Give up?

    The reason is because while MyDerived "isa" MyBase, the reverse isn’t true -- MyBase "isn’t" MyDerived.

    If you try to do the opposite -- cast theDerived into an object of type MyBase -- that will work. This is because, due to the inherited relationship of MyDerived from MyBase, theDerived contains within it methods and data members that conform fully to the definition of MyBase.

    The reverse is not true. If you try to cast theBase into an object of type MyDerived, this will NOT work. This is because theBase does not contain within it ANY of the methods or data members that make MyDerived different from MyBase. Since those members are missing, there’s no way to successfully cast an object of type MyBase to a variable of type MyDerived. Hence the invalid-cast exception.

    posted @ Monday, June 16, 2008 3:05 PM | Feedback (0)

     

     

    Copyright © Edward Buatois