Finding a Particular string in a Database in the most Optimized way

 Hi All,
          Below is the query to find  a Particular String in the entire database tables,I have a Database of about 500 + tables and each contains many data's .In these tables i want to find a particular
string but didn't know the column name and table name.so i did as below,but for executing this it almost take 40 - 45 minutes.Is there any other way to Optimize this and make the Query execution Faster.I am copying the code below.Please comment
DECLARE
    @search_string  VARCHAR(100),
    @table_name     SYSNAME,
    @table_id       INT,
    @column_name    SYSNAME,
    @sql_string     VARCHAR(2000),
 @TableCount    INT,
 @ColumnCount   INT
SET @search_string = 'Developer'
DECLARE   @Tables TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
DECLARE   @Columns TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
INSERT INTO @Tables
SELECT name, object_id FROM sys.objects WHERE type = 'U'
SELECT @TableCount=COUNT(1) FROM @Tables
WHILE (@TableCount >0)
BEGIN
  SELECT TOP(1)
     @table_name=name
    ,@table_id=id
  FROM  @Tables ORDER BY Rownumber
INSERT INTO @Columns
SELECT name,object_id FROM sys.columns WHERE object_id = @table_id AND system_type_id IN (167, 175, 231, 239)
SELECT @ColumnCount=COUNT(1) FROM @Columns
  WHILE (@ColumnCount >0)
  BEGIN
    SELECT TOP(1)
       @column_name=name
    FROM  @Columns
    WHERE id= @table_id
     ORDER BY Rownumber
     --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''%' + @search_string + '%'') PRINT ''' + @table_name + ', ' + @column_name + ''''
      SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''' + @search_string + '%'') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
+ ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
     --select (@sql_string);
      --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] = ''' + @search_string + ''') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
+ ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
     EXECUTE(@sql_string)
   SET @ColumnCount=@ColumnCount-1
   DELETE FROM @Columns WHERE  Name =   @Column_Name
  END
SET @TableCount=@TableCount-1
DELETE FROM @Tables WHERE Name= @Table_Name
END

You may also try the below :
http://gallery.technet.microsoft.com/c0c57332-8624-48c0-b4c3-5b31fe641c58

Similar Messages

  • The most efficient way to search a large String

    Hi All,
    2 Quick Questions
    QUESTION 1:
    I have about 50 String keywords -- I would like to use to search a big String object (between 300-3000 characters)
    Is the most efficient way to search it for my keywords like this ?
    if(myBigString.indexOf("string1")!=1 || myBigString.indexOf("string2")!=1 || myBigString.indexOf("string1")!=1 and so on for 50 strings.)
    System.out.println("it was found");
    QUESTION 2:
    Can someone help me out with a regular expression search of phone number in the format NNN-NNN-NNNN
    I would like it to return all instances of that pattern found on the page .
    I have done regular expressions, in javascript in vbscript but I have never done regular expressions in java.
    Thanks

    Answer 2:
    If you have the option of using Java 1.4, have a look at the new regular expressions library... whose package name I forget :-/ There have been articles published on it, both at JavaWorld and IBM's developerWorks.
    If you can't use Java 1.4, have a look at the jakarta regular expression projects, of which I think there are two (ORO and Perl-like, off the top of my head)
    http://jakarta.apache.org/
    Answer 1:
    If you have n search terms, and are searching through a string of length l (the haystack, as in looking for a needle in a haystack), then searching for each term in turn will take time O(n*l). In particular, it will take longer the more terms you add (in a linear fashion, assuming the haystack stays the same length)
    If this is sufficient, then do it! The simplest solution is (almost) always the easiest to maintain.
    An alternative is to create a finite state machine that defines the search terms (Or multiple parallel finite state machines would probably be easier). You can then loop over the haystack string a single time to find every search term at once. Such an algorithm will take O(n*k) time to construct the finite state information (given an average search term length of k), and then O(l) for the search. For a large number of search terms, or a very large search string, this method will be faster than the naive method.
    One example of a state-search for strings is the Boyer-Moore algorithm.
    http://www-igm.univ-mlv.fr/~lecroq/string/tunedbm.html
    Regards, and have fun,
    -Troy

  • What is the most efficient way to turn an array of 16 bit unsigned integers into an ASCII string such that...?

    What is the most efficient way to turn a one dimensional array of 16 bit unsigned integers into an ASCII string such that the low byte of the integer is first, then the high byte, then two bytes of hex "00" (that is to say, two null characters in a row)?
    My method seems somewhat ad hoc. I take the number, split it, then interleave it with 2 arrays of 4095 bytes. Easy enough, but it depends on all of these files being exactly 16380 bytes, which theoretically they should be.
    The size of the array is known. However, if it were not, what would be the best method?
    (And yes, I am trying to read in a file format from another program)

    My method:
    Attachments:
    word_array_to_weird_string.vi ‏18 KB

  • How to find a specific string in Entire database?

    Well i know this question is posted numerous times here but i m complete noob understanding the solution given on the net.
    Let me introduce the entire scenario .
    We have an application, which keeps on sending emails from an X employees account.
    We are using Oracle 11g as database .But the problem is we don't know which table to search for the value.
    All we have is Database credentials and x employee's name.
    Is there any way we can find out which table contains the name so that we can change it accordingly.
    I m using plsql developer to connect to the database.
    One solution that we got from internet goes as below.
    Ref:
    [http://www.club-oracle.com/articles/oracle-find-all-tables-with-column-value-154/ |http://www.club-oracle.com/articles/oracle-find-all-tables-with-column-value-154/ ]
    As per the solution i had to create a procedure as below .
    create or replace
    procedure find_string( p_str in varchar2 )
    authid current_user
    as
    l_query long;
    l_case long;
    l_runquery boolean;
    l_tname varchar2(30);
    l_cname varchar2(30);
    type rc is ref cursor;
    l_cursor rc;
    begin
    dbms_application_info.set_client_info( '%' || upper(p_str) || '%' );
    for x in (select * from user_tables )
    loop
    l_query := 'select distinct ''' || x.table_name || ''', $$
    from ' || x.table_name || '
    where ( 1=0 ';
    l_runquery := FALSE;
    l_case := NULL;
    for y in ( select *
    from user_tab_columns
    where table_name = x.table_name
    and data_type in ( 'VARCHAR2', 'CHAR' )
    loop
    l_runquery := TRUE;
    l_query := l_query || ' or upper(' || y.column_name ||
    ') like userenv(''client_info'') ';
    l_case := l_case || '||'' ''|| case when upper(' || y.column_name ||
    ') like userenv(''client_info'') then ''' ||
    y.column_name || ''' else NULL end';
    end loop;
    if ( l_runquery )
    then
    l_query := replace( l_query, '$$', substr(l_case,8) ) || ')';
    begin
    open l_cursor for l_query;
    loop
    fetch l_cursor into l_tname, l_cname;
    exit when l_cursor%notfound;
    dbms_output.put_line
    ( 'Found in ' || l_tname || '.' || l_cname );
    end loop;
    close l_cursor;
    end;
    end if;
    end loop;
    end;
    Well i have copied the code to sql window in plsql and executed .But whenever i compile the procedure it says there is an error .
    Not sure what kind of error hidden in the procedure.
    If any 1 has any better idea please share.
    Edited by: Milind on Apr 12, 2012 8:45 PM

    Girish Sharma wrote:
    Milind,
    I am not sure what / which error about your talking, but there is no error/issue at my end when I ran your procedure code :
    1.I just pasted the code in sqlplus window, it showed me Procedure created. message.
    2.I just checked with show errors command, it showed me No errors.
    3.I just tried to run it with :
    SQL> SET SERVEROUTPUT ON;
    SQL> exec find_string('SCOTT');
    Found in EMP.ENAMENo issue error.
    But whenever i compile the procedure it says there is an error .
    SQL> alter procedure find_string compile;
    Procedure altered.
    SQL> exec find_string('SCOTT');
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on;
    SQL> exec find_string('SCOTT');
    Found in EMP.ENAME
    PL/SQL procedure successfully completed.
    SQL>So, there is no error at my end 11.2.0.1 windows box.
    Regards
    Girish Sharma
    Edited by: Girish Sharma on Apr 13, 2012 11:20 AMThanks it worked for me.

  • When looking for a document, there used to be a "Today" tab on the left side of the Finder window. After updating my computer with the most recent update (I think it was Mountain Lion, but I could be wrong...), the "Today" tab seems to have disappeared.

    I really prefer using the "Today" tab instead of the "All My Files" tab, because it loads much faster and only shows me the documents that I want to see. Is there any possible way to get the "Today" tab back?

    In Finder, go command - F. On the top left set "Kind" to Date Created, finish selecting the criteria and hot "Save" on the top right. You'll get a new smart folder with an option to add it to the sidebar.

  • Partitioning the database from the most recent to the last partitioned

    Hi everyone
    We have a huge database which is partitioned based on datetime column and for each month. The last partition that we have on it was for 12/1/2013. And since then we have accumulated data with millions of rows already till 3/1/2015.
    We want to continue to add partitions for the next two years to it now.
    Since splitting the last partition from 12/1/2013 to 1/1/2014 is pretty painful and then to split 1/1/2014 to 2/1/2014, We were thinking if there is a way to split from the back. Like add a partition for 2/1/2015 so that data for Feb only
    goes there and the 1/1/2015 and then making our way back to 1/1/2014.
    So far I have a script for going from 12/1/2013 to 1/1/2014 and the 1/1/2014 to 2/1/2014. Something like this
    ALTER
    PARTITION SCHEME MonthlyPartitionScheme
    NEXT
    USED [PRIMARY]
    GO
    ALTER
    PARTITION
    FUNCTION PartitionByMonth()
    SPLIT
    RANGE
    ('1/1/2014')
    Go
    ALTER
    PARTITION SCHEME MonthlyPartitionScheme
    NEXT
    USED [PRIMARY]
    GO
    ALTER
    PARTITION
    FUNCTION PartitionByMonth()
    SPLIT
    RANGE
    ('2/1/2014')
    Go
    How can I change to make it work backwards from 2/1/2015 to 1/1/2015 and then 1/1/2015 to 12/1/2014 and so on. I am looking at more resources online, any help with this would be appreciated.
    Thanks much
    -Sarah

    yes, i also think merge partition maybe can help you solve problem, you want to move some data to a new partition, so i also suggest you to use this one way, because splitting partition is time-consuming. Once i read one article, which can do this task,
    more information click here:
    how to merge partitions. It seems some partition software can do this, some reviews like:  http://dottech.org/95676/windows-best-free-partition-and-disk-manager-review  among them, i used aomei partition assistant, its server version is supported
    in server OS, maybe it is useful for you.You also can use another partition manager, merge partitions instead of splitting partition. 

  • How to use GREP to find one particular word with automatic hyphen?

    I know I have in my text a word with automatic hyphen on the end of line, say Wo-rd.
    How can I find it?
    Thanks.

    I think you might do better to edit the hyphenation in the Dictionary.
    One reason words hyphenate incorrectly is the wrong language has been applied. Both spell checking and hyphenation rules are governed by the language selected for the text, and language is a character-level attribute so that you can select inidvidual words and assign a different language to them if you like.
    If that's the probelm here, you can look for the word using find/change (without worying about the hyphen) and change the language for all instances.
    In either case you will be far better off fixing the problem on a global scale in the document than you will be finding a particular instance of that word at the end of a line. Any editing you do in the future may cause the problem to reappear somewhere else.

  • PowerShell - what is the most efficient/fastest way to find an object in an arraylist

    Hi
    I Work with a lot of array lists in PowerShell when working as a sharepoint administrator. I first used arrays but found them slow and jumped over to array lists.
    Often i want to find a specific object in the array list, but the respons-time varies a lot. Does anyone have code for doing this the most efficient way?
    Hope for some answers:-)
    brgs
    Bjorn

    Often i want to find a specific object in the array list, but the respons-time varies a lot. Does anyone have code for doing this the most efficient way?
    As you decided to use an ArrayList, you must keep your collection sorted, and then use the method BinarySearch() to find the objects your looking for.
    Consider using a dictionary, and if your objects are string type, then a StringDictionary.
    You stil fail to understand that he slowness is no in the arraylist.  It is in the creating of the arraylist which is completely unnecessary.  Set up a SharePoint servefr and create a very large list and test..  You will see. An arraylist
    with 10000 items takes forever to create. A simple SharePoint search can be done in a few milliseconds.
    Once created the lookup in any collection is dependent on the structure of the key and the type of collection.  A string key can be slow if it is a long key.
    The same rules apply to general database searches against an index.
    The main point here is that SharePoint IS a database and searching it as a database is the fastesst method.
    Prove me wrong devil!    Submit!  Back to your cage! Fie on thee!
    ¯\_(ツ)_/¯
    You seem to be making a lot of assumptions about what he's doing with those arraylists that doesn't seem justified based on no more information than there is in the posted question.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Most efficient way to do some string manipulation

    Greetings,
    I need to cleanse some data in a string by replacing unsafe characters with encoded equivalents. (FYI, this is for the purpose of transforming "unsafe" characters into encoded values as data inside an XML document).
    The following code accomplishes the task:
    Note that a string "currentValue" contains the data to be cleansed.
    A string, "encodedValue" contains the result.
      for (counter = 0; counter < currentValue.length(); counter++)
        addChar = (currentValue.substring(counter,counter+1));
        if (addChar.equals("<"))
          addChar = "#60;";
        if (addChar.equals(">"))
          addChar = "#62;";
        if (addChar.equals("="))
          addChar = "#61;";
        if (addChar.equals("\""))
          addChar = "#34;";
        if (addChar.equals("'"))
          addChar = "#39;";
        if (addChar.equals("'"))
          addChar = "#39;";
        if (addChar.equals("/"))
          addChar = "#47;";
        if (addChar.equals("\\"))
          addChar = "#92;";
        encodedValue += addChar;
      } // forI'm sure there is a way to make this more efficient. I'm not exactly "new" to java, but I am learning on my own with no formal training and often take a "brute force" approach with my initial effort.
    What would be the most efficient way to re-do the above?
    TIA,
    --Paul Galvin
    Integrated Systems & Services Group

    im a c++ programmer so im not totally up on these java classes either but...from a c++ stand point you might want to consider using the if else statment.
    by using if else, you only test the character until you find the actual "violating" character and skip the rest of the tests.
    also, you might trying using something to check for alphaNumeric cases first and use the continue keyword when you find one. since more of your characters are probably safe than unsafe you can skip all the ifs/if else statement and only do one test on the good characters. (i just looked for a way to test that and i didnt find one. c++ has a function that does that by checking the ascii number range. dont think that works in java. but maybe you can find one, it would reduce the number of tests probably.)
    happy hunting,
    txjump :)

  • Find all tables in db with column name of a particular string?

    I'm looking for all tables in a db that have a certain column name. How can I find this?

    John,
    thanks for your answer.
    John Mcginnis wrote:
    The quick search field in the schema browser is doing client-side filtering of the list of objects. This means we can only filter on things that we already have fetched from the database, like the object name. We have no current plans to extend the types of information that can filter on, although it is possible we might add the ability to filter based on a few other types of information that we generally fetch with the object name. However, filtering by column name would require pre-fetching the lists of columns for all tables and as such is not likely to be added to the schema browsers search field.
    I'm sure you guys had a Toad review to understand how things are done there.....so
    My 2 cents are: instead of pre-fetching the columns of all tables why don't you add a button below the table drop-down list which should fetch the tables based on the filter columns condition - exactly like Toad.
    Thanks,
    Dani

  • Why is it that when I go to the search screen to find a particular message in a conversation it comes up with the message but when I click on it it takes me to the conversation where the most recent message was sent and not the message I wanted

    Why is it that when I go to the search screen and type in a particular message I want to view, my iPhone finds it but when I click on it it only takes me to the conversation at the most recently thing texted and not the particular message I clicked on?

    Never occurred to me you can search messages that way, thanks.
    Another way to do it is to scroll from the most recent message to the top of the screen and tap load more messages, repeatedly till you reach the one you want.
      I like your method better, but with both methods it refreshes to the most recent message.

  • PLEEEEEEEZE!!!!! HELP!!! I am trying to find this particular product/microph

    I have a particular microphone that is about 8-0 inches in length...it sits on a very small stand, and just plugs into the back of the PC where the mic jack is. I think it is to be used with a web cam, so people can hear the person on the other side of the camera. On the stand it has the Creative Logo, however, when I go to the Creative web site I can not find it anywhere!! It is in the normal "computer off whiteish color, with the platform of about3-3 /2" wide&4" or so long, then the chord comes out the end of the mic, which is a very skinny flexible, bendable tube, and at the very tip(the actual mic) is just a little bit bigger around, and that part is probably about an inch&/2 long...i hope I've actually done a good job explaining this, and not completely confused everyone!!! LOL!!! Anyways, my problem is this... I can not find it online to download any software (if I actually need to, and if I don't than I'm hoping someone will let me know that too)If I do need to download the software, can someone kindly tell me where to go, also, I need to know if there is something special I need to do to make it work. PLEEEEEEEEEEZE!!!!! ANYONE OUT THERE..... I'D BE FOREVER GRATEFUL IF SOMEONE CAN HELP ME GET THIS WORKING BEFORE MY MOM WHO LIVES IN TEXAS 2,700 MILES AWAY, KILLS ME...CUZ SHE WANTS TO BE ABLE TO SEE AND HEAR ME&HER GRANDKIDS!!! I succesfully downloaded the web cam, but am not sure if I got this darn mic working!! You can email me at [email protected] or [email protected] or yahoo instant msg at screen name kimmyann07 Hope to hear from someone ANYONE SOON!!! Thank you and Merry Christmas!!!
    Thanks Again!
    Kim
    Marysville Washington

    1. test online or
    2. adjust your local security settings, http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.htm l
    if that does not solve your 2060, post the url to your embedding html.
    you also have other errors that you'll need to fix including defining all your functions and using embedding code compatible with externalinterface.

  • How to find a particular word in a file using java

    Program how to find a particular word in a file

    SirivaniG wrote:
    Program how to find a particular word in a fileOkay, I finished it. Now what?

  • How to find out who is locking my database account ?

    Hi,
    Which dynamic view can help me to find out who is locking my database account ?
    Thanks

    Yoav wrote:
    Hi,
    Which dynamic view can help me to find out who is locking my database account ?
    Thanksdoes account have PROFILE?
    if so, repeated failed logons can result in locked account.
    enable AUDIT to see from where logins originate.

  • Connect String for the front end app to access Lite Database in the Client

    Hi,
    I have been using an app developed in VB.net for accessing the Oracle Lite Database from the client machine. Can anyone please help me out how to set the Connect String in the config file of my front end app to access the Oracle Lite Database from my client machine. Do anyone have the syntax of the connect string to access the lite database in client machine.
    Thanks a lot in advance.

    Hi...
    -->Select example
    create or replace procedure get_emp(rc out sys_refcursor)
    is
    begin
    open rc for select * from emp;
    end;
    -->DML example
    create or replace procedure do_dml_emp(pempid in number,
    pempname varchar2,
    result out number)
    is
    begin
    insert into emp(empid,empname) values(pempid,pempname) returning empid into result;
    exception
    when others then
    result:=-1;
    end;
    -->DDL example
    create or replace procedure ddl_emp(colname varchar2,
    coltype varchar2,
    result out number)
    is
    begin
    result:=-1;
    execute immediate 'alter table emp add column ' || colname || ' ' || coltype ;
    result:=1;
    end;

Maybe you are looking for

  • Business partner number Issue in Service Groups

    Hi , In My Current Business process we are creating Manual Organizational Unit  Service Groups,  at the time of creation system should generate Business partner number with ROLE Organization.      Recently we are updated system windows to UNIX . from

  • Using PowerShell to set Custom Access Rights on a Calendar Does not set Free/Busy Permissions

    We recently discovered an issue where, if you use Exchange Management Shell to configure custom access rights, the Free/Busy permissions do not get set at all (they remain as "None"): $temp = [Microsoft.Exchange.Management.StoreTasks.MailboxFolderAcc

  • Using attchment capability

    HI Experts, I have created the custom tables in ECC6.0 and also created rfc's for getList, getDetails and attachmentPic. The DO, header node is created in NetWeaver Mobile7.1(SDOE_WB), then backend adapters are also created there based on rfcs. All a

  • Partner number 2821xx for customer 2022821xx ,partner function WE not exist

    Hi Guys, I have problem with partner convertion for Inbound ORDERS to SAP. <u>Receiver :</u> port - SAPID Partner - DEVSTF200 Type    - LS Sender: Port - SAPXID Partner - XIDSTF100 type - LS receive IDOC with status 51 with error - Partner number 282

  • SSCRFIELD : ONLI : Variant creation not possible

    Hi all,   I have Selection Screen with pushbutton.  And i have the User Command ONLI assigned to the Push Button. Since this allows me to reach Start of Selection. At the Selection Screen Event, I am Capturing the ONLI when the User presses the Push