Advertisement

07.22.2008 at 06:23PM PDT, ID: 23587133
[x]
Attachment Details

Query all tables and columns in a db

Asked by tanman2k in MS SQL Server

Tags: mssql

I'm trying to query all the tables and all their columns in a db for a particular search string.  I got the example below from someone elses post, but I get an "invalid object name 'sys.tables' along with other errors related to anything referencing sys. in the query .  Here's the example I was trying to use in query analyzer:

USE AdventureWorks
 
DECLARE @find_this VARCHAR(50)
SET @find_this = 'Adventure'
SELECT
'SELECT [' + C.[name] + '] FROM [' + S.[name] + '].['  + tbl.[name] + '] WHERE [' + C.[name] + '] LIKE ' + char(39) + '%' + @find_this + '%' + char(39)
      FROM  sys.tables tbl
      INNER JOIN sys.schemas S ON tbl.schema_id = S.schema_id
      INNER JOIN sys.columns C ON C.object_id = tbl.Object_id
      INNER JOIN sys.types T ON T.user_type_id = C.user_type_id
      WHERE T.[name] LIKE '%varchar%'
order by tbl.[name], C.column_idStart Free Trial
[+][-]07.22.2008 at 06:25PM PDT, ID: 22065309

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 06:32PM PDT, ID: 22065339

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 06:35PM PDT, ID: 22065351

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 06:37PM PDT, ID: 22065362

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 06:38PM PDT, ID: 22065365

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 06:42PM PDT, ID: 22065380

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:06PM PDT, ID: 22065460

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:21PM PDT, ID: 22065515

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 08:45PM PDT, ID: 22065819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.12.2008 at 11:09AM PDT, ID: 22215501

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: mssql
Sign Up Now!
Solution Provided By: chapmandew
Participating Experts: 3
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628