473,490 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

search for a string in the entire database

ameesh1109
1 New Member
hi,
i want to search for a string in all the coloumns of all the tables in the database, i.e. i have a select query with a where clause but without a table name and without a coloumn name.

can anybody help?
Apr 6 '07 #1
3 19249
ysivareddy
1 New Member
Hi Ameesh,
Create the below stored procedure in the required database and here is how you run it:

step1:Copy paste the below code and run in SQL server query analyzer under appropriate database.

CREATE PROC SearchAllTables
(
@SearchStr nvarchar(100)
)
AS
BEGIN

CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = ''
SET @TableName =
(
SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
AND OBJECTPROPERTY(
OBJECT_ID(
QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
), 'IsMSShipped'
) = 0
)

WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
BEGIN
SET @ColumnName =
(
SELECT MIN(QUOTENAME(COLUMN_NAME))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = PARSENAME(@TableName, 2)
AND TABLE_NAME = PARSENAME(@TableName, 1)
AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
AND QUOTENAME(COLUMN_NAME) > @ColumnName
)

IF @ColumnName IS NOT NULL
BEGIN
INSERT INTO #Results
EXEC
(
'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
FROM ' + @TableName + ' (NOLOCK) ' +
' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
)
END
END
END

SELECT ColumnName, ColumnValue FROM #Results
END

step2 : To run the above procedure:
-- To search all columns of all tables in a database say:
database name = Pubs
keyword to search = Computer
Select the database in Query analyzer and run the following command:

EXEC SearchAllTables 'Computer'
GO

Thatz all!!!!!!. Hope this helps.

hi,
i want to search for a string in all the coloumns of all the tables in the database, i.e. i have a select query with a where clause but without a table name and without a coloumn name.

can anybody help?
Oct 16 '07 #2
debasisdas
8,127 Recognized Expert Expert
hi,
i want to search for a string in all the coloumns of all the tables in the database, i.e. i have a select query with a where clause but without a table name and without a coloumn name.

can anybody help?
Kindly mention the database that you are using with version .

also post what you have tried so far.
Oct 17 '07 #3
rzijlstra
1 New Member
I have a PL/SQL script on my website to search a string in a database schema. Please visit http://www.renetta.nl/kennisbank/ora...search?lang=en to download view and download it.

Cheers,

Rene
Mar 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
3597
by: Freddie | last post by:
Happy new year! Since I have run out of alcohol, I'll ask a question that I haven't really worked out an answer for yet. Is there an elegant way to turn something like: > moo cow "farmer john"...
19
2712
by: Andy B | last post by:
Hello, Sorry for this newbish question. Briefly, my problem: ------------------ I expect the database I'm working on to reach something in the order of 12-16 Gigabytes, and I am interested...
5
2484
by: Martien van Wanrooij | last post by:
I have been using phpdig in some websites but now I stored a lot of larger texts into a mysql database. In the phpdig search engine, when you entered a search word, the page where the search word...
1
11655
by: atl10spro | last post by:
Hello Everyone, I am new to MS Access and although I have created several different databases I lack the VB knowledge to code a search function. I am turning to your expertise for assistance. ...
2
2114
by: AboutJAV | last post by:
Hi, I read alot of articles on how to read 1 table to a dataset. How do you read and entire database to a dataset, do a fill, and update it after modification. Thanks
5
6433
by: TC | last post by:
I use Visual Studio 2005 v8.0 on two different computers. On one, the "Find and Replace" dialog gives me the option to look in the "Entire Solution". On the other computer, the "Find and Replace"...
4
1284
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is there a way to find a textbox id with a search string in the code-behind? thanks, rodchar
9
16276
by: ischwartz88 | last post by:
Hi, I am not a computer programmer. I have been learning VBA along the way of making this script. I know Access and SQL. I have a very large database with many tables and queries. My goal is to...
7
7395
by: nurmaiza | last post by:
HI all, I'm using $content = str_ireplace($search, $replace, $var3); to search and replace value in $var3. My problem is i want to take out all the table attribute found in $var3. For example ...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.