-2

I'm trying to select column names in our database and I'm unsure how. I tried some solutions I found on Stack Social but I haven't been able to make them work.

Is it even possible given the schema? I feel like it should be but my limited understanding in how to change the FROM clause is preventing me from doing this on my own. Below is a picture to help elaborate on the difficulty I'm having. Picture of schema and attempts to return table and column names

EDIT: The problem is unique in that the overall layout of our database seems largely different from the norm. There seems to be nested databases and I wasn't sure how to use a specific DB.

The Use function worked well for this but its not intuitive from other answers. At least the picture can help someone in the future if they have a similar problem.

  • Use Sys.Columns. Every database doesn't have its own Columns table. – Tab Alleman Apr 27 '16 at 14:47
  • Possible duplicate of [Getting list of tables, and fields in each, in a database](http://stackoverflow.com/questions/420741/getting-list-of-tables-and-fields-in-each-in-a-database) – Tab Alleman Apr 27 '16 at 14:48
  • It may be do-able with sys.columns but its not very intuitive. I tired a basic query .. Select c.name as c, t.name as t from sys.COLUMNS JOIN sys.tables t on c.object_id = t.object_id but got 2 errors: The multi-part identifier "c.object_id" could not be bound. The multi-part identifier "c.name" could not be bound. If there is an online resource that can better elaborate how to interpret the solution to the other problems, I would greatly appreciate the link. – laxpro2001 Apr 27 '16 at 15:07

1 Answers1

0
Use RatManreport
GO

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%CD%'
SQLChao
  • 7,709
  • 1
  • 17
  • 32
  • Thank you very much! I will accept the answer once it lets me (3 minutes need to pass). Do you by chance have a link to an online resource where I can learn more about this on my own? I hate asking others for help as I feel I come off lazy. Thanks again! – laxpro2001 Apr 27 '16 at 14:57
  • @Richard Hansell Thanks. I see that the above solution can be re-written to not require the Use statement if the FROM statement is written as follows: FROM DatabaseName.INFORMATION_SCHEMA.COLUMNS – laxpro2001 Apr 27 '16 at 15:12