Solved

find a needle in a haystack using sql lite

Posted on 2013-11-16
7
373 Views
Last Modified: 2013-11-24
using sql lite want to find a needle in a haystack

many tables and many columns in those tables

I want to find 'bob'

Is there a query or query tool to do this search

I do not want to do a large task that involves copy paste.

I have done this task with one query in sql server
0
Comment
Question by:rgb192
  • 3
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:David
ID: 39653965
Conceptually, if you were using all XML or SQLText (binary) columns, my guess is that it's doable.  With OLTP, B-tree traditional systems (unindexed varchar datatypes), that becomes an exercise in futility.  IMHO, your results may vary.  

You're in effect asking, for 1..n tables in 1..n schemas, each having 1..n columns, make a pass each time through all rows in a given schema.table.column, searching for "%X%".
Then there's the possibility that the desired tuple exists but in a schema.table to which you are denied access.
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 333 total points
ID: 39654050
If this is a single database it should be doable.

I'm not familiar with SQL Lite but the general idea is that there is going to be some sort of central table that lists off the rest of the tables in the DB. And you can write to a temporary table.

So it would be some sort of create temp table:
create #temptable(
     TableName as varchar(100),
     ColumnName as varchar(100),
     ColUmnValue as varchar(500))

Open in new window


Then create some sort cursor/wrapper from the system table:
cursor = select TableName from SysTables

Open in new window


Then some sort of tracking that it goes through the columns looking for 'bob':
While I < TableNameColumn.Count
RecExists = select count(*) from Cursor.TableName where Column(I) like '%' + 'bob' + '%'
     if RecExists >0 then
          INSERT INTO #temptable select TableNameColumn, Column(I).Name, Column(I).Value  from Cursor.TableName where Column(I) like '%' + 'bob' + '%'
     end if
Next I

Open in new window


Then you present the  #temptable to the user. This is the concept behind how to do it.
0
 
LVL 23

Expert Comment

by:David
ID: 39655014
Jimkin, assuming that this query ran as a sys level user, what kind of resource consumption do you think this would take?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 333 total points
ID: 39655120
I have a similar script for SQL Server DB's. Running it as the SA user on 40GB DB with about 150 tables average of 30K rows it took about 4-5 minutes.

I wouldn't want to run it in major hours for a large DB online. But it shouldn't be too horrible.
0
 

Author Comment

by:rgb192
ID: 39656153
http://www.experts-exchange.com/Database/Miscellaneous/Q_28295935.html#a39654050

I do not understand syntax of step2:
cursor = select TableName from SysTables


I do not understand the other comments.
More data:
I am looking at main.db which skype uses.
I have used sql lite to view/modify tables.
Could I use another database?
0
 
LVL 23

Accepted Solution

by:
David earned 167 total points
ID: 39656420
The pseudo-syntax says, take a one-dimensional temporary array in memory, and populate it with n number of table names from a schema.  Then, loop through the array: for each table name, perform some dependent transaction (query).

It's my opinion that jimpen may be simplifying his/her process for your clarity.  I observe that the logic does not handle multiple schemas (accounts that own database objects).  In one of my systems, the number of schemas is 3-4 thousand,  The SYS schema owns over fifty thousand tables.

My point is, if you're looking for 'bob' in one or two schemas, the search is indeed doable, beyond that it is not scalable.
0
 

Author Closing Comment

by:rgb192
ID: 39673566
Thank you for a blueprint of what to do in sql lite.  I will use this information.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Data quality checks 2 72
Display multiple images in report 12 118
Distinct values from all columns in a table?? PL SQL 4 37
Exchange 2007 standard - defrag (eseutul /d) 10 42
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question