find a needle in a haystack using sql lite

Posted on 2013-11-16
Medium Priority
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
Question by:rgb192
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 23

Expert Comment

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.
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 1332 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.
LVL 23

Expert Comment

ID: 39655014
Jimkin, assuming that this query ran as a sys level user, what kind of resource consumption do you think this would take?
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 1332 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.

Author Comment

ID: 39656153

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?
LVL 23

Accepted Solution

David earned 668 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.

Author Closing Comment

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

762 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