[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


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?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 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