| Author |
Topic |
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 10:15:37
|
| I have some very large tables i'm working with (hundreds of columns). Is there a way to search for a column by name in SSMS, just to verify the column exists in the table?thanksjames |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 10:16:45
|
| disregard. Found this:USE AdventureWorks GO SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%EmployeeID%' ORDER BY schema_name, table_name; |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-16 : 10:53:24
|
i prefer using INFORMATION_SCHEMA.COLUMNS viewSELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = <your column name> ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 11:04:50
|
| anytime i can avoid using a join, i will.thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-03-16 : 11:08:49
|
quote: Originally posted by WJHamel anytime i can avoid using a join, i will.thanks.
I prefer it for that reason and also that it gives all required names directly without using any other functions like object_name,schema_name etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 11:24:50
|
| How about something like the above to seek out the column for each table with an IDENTITY property? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 12:27:01
|
| select TABLE_NAME + '.' + COLUMN_NAME, TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'dbo' and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 order by TABLE_NAME |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2012-03-16 : 13:12:21
|
| and bonus - no joins |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|