2

I would like to have all the tables having one column called XXX

I've tried the following query but it's not working.

SELECT object_id
FROM sys.columns 
WHERE name = 'XXX';
Revious
  • 7,816
  • 31
  • 98
  • 147

2 Answers2

6
SELECT table_schema
     , table_name
     , column_name
FROM   information_schema.columns
WHERE  column_name LIKE '%test%'

You've mentioned in your question comments that "it's not working" =

pressing F5 is aking me to create a report file

In Management Studio you have a few options for what to do with your query results:

enter image description here

  1. Results to Text CTRL + T
  2. Results to Grid (default) CTRL + D
  3. Results to File CTRL + SHIFT + F

Sounds like you've hit the "Results to File" button (or key combination).

gvee
  • 16,732
  • 35
  • 50
2

Here's one that will grab both the column and the table it belongs to:

SELECT DISTINCT so.name AS tablename, sc.name AS columnname 
FROM syscolumns sc
INNER JOIN sysobjects so
ON so.id=sc.id
WHERE sc.name LIKE '%XXX%'
ORDER BY so.name, sc.name
Bensonius
  • 1,501
  • 1
  • 15
  • 39