Everyone: Thanks for all the post and comments, some of them are good, but some of them are better.
The first big script is good because it delivers only what you need. The fastest and most detailed is one suggestion for choosing from INFORMATION_SCHEMA.COLUMNS ..
I needed to find all the erroneous columns with approximately the same name and several databases .. Sooo, I made my versions of both (see below) ... Any of the two below script works and delivers the goods in seconds.
The assumption in other posts on this link is that the first code sample can be successfully used for each database, which is undesirable for me. This is due to the fact that the information is within a specific database, and the simple use of "fedb" does not give the correct results, it simply does not give access. SOOO, so I use CURSOR to collect databases and ignore those that are Off-line, which in this case is a script utility, it's good to use.
Bottom Line, I read all the messages, included all the corrections from the messages, and did what two very eloquent scenarios from other good work. I listed both below, and also placed the script file in my shared folder on OneDrive.com, with which you can access this link: http://1drv.ms/1vr8yNX
Enjoy it! Hank freeman
Senior Level - SQL Server DBA - Data Architect
Try them separately ...
--------------------------- --- 1st example (works) --- --------------------------- Declare @DBName sysname ,@SQL_String1 nvarchar(4000) ,@SQL_String2 nvarchar(4000) ,@ColumnName nvarchar(200) --set @ColumnName = 'Course_ID' -------- Like Trick -------- -- IF you want to add more the @ColumnName so it looks like Course_ID,CourseID -- then add an additional pairing of +''','''+'NewColumnSearchIDValue' ---------------------------- set @ColumnName = 'Course_ID' +''','''+'CourseID' --select @ColumnName ----- Declare @Column_Info table ( [DatabaseName] nvarchar(128) NULL, [ColumnName] sysname NULL, [ObjectName] nvarchar(257) NOT NULL, [ObjectType] nvarchar(60) NULL, [DataType] nvarchar(151) NULL, [Nullable] varchar(8) NOT NULL, [MiscInfo] nvarchar(MAX) NOT NULL ) -------------- Begin set @SQL_String2 = 'SELECT DB_NAME() as ''DatabaseName'', s.name as ColumnName ,sh.name+''.''+o.name AS ObjectName ,o.type_desc AS ObjectType ,CASE WHEN t.name IN (''char'',''varchar'') THEN t.name+''(''+CASE WHEN s.max_length<0 then ''MAX'' ELSE CONVERT(varchar(10),s.max_length) END+'')'' WHEN t.name IN (''nvarchar'',''nchar'') THEN t.name+''(''+CASE WHEN s.max_length<0 then ''MAX'' ELSE CONVERT(varchar(10),s.max_length/2) END+'')'' WHEN t.name IN (''numeric'') THEN t.name+''(''+CONVERT(varchar(10),s.precision)+'',''+CONVERT(varchar(10),s.scale)+'')'' ELSE t.name END AS DataType ,CASE WHEN s.is_nullable=1 THEN ''NULL'' ELSE ''NOT NULL'' END AS Nullable ,CASE WHEN ic.column_id IS NULL THEN '''' ELSE '' identity(''+ISNULL(CONVERT(varchar(10),ic.seed_value),'''')+'',''+ISNULL(CONVERT(varchar(10),ic.increment_value),'''')+'')=''+ISNULL(CONVERT(varchar(10),ic.last_value),''null'') END +CASE WHEN sc.column_id IS NULL THEN '''' ELSE '' computed(''+ISNULL(sc.definition,'''')+'')'' END +CASE WHEN cc.object_id IS NULL THEN '''' ELSE '' check(''+ISNULL(cc.definition,'''')+'')'' END AS MiscInfo into ##Temp_Column_Info FROM sys.columns s INNER JOIN sys.types t ON s.system_type_id=t.user_type_id and t.is_user_defined=0 INNER JOIN sys.objects o ON s.object_id=o.object_id INNER JOIN sys.schemas sh on o.schema_id=sh.schema_id LEFT OUTER JOIN sys.identity_columns ic ON s.object_id=ic.object_id AND s.column_id=ic.column_id LEFT OUTER JOIN sys.computed_columns sc ON s.object_id=sc.object_id AND s.column_id=sc.column_id LEFT OUTER JOIN sys.check_constraints cc ON s.object_id=cc.parent_object_id AND s.column_id=cc.parent_column_id -------------------------------------------- --- DBA - Hank 12-Feb-2015 added this specific where statement -- where Upper(s.name) like ''COURSE%'' -- where Upper(s.name) in (''' + @ColumnName + ''') -- where Upper(s.name) in (''cycle_Code'') -- ORDER BY sh.name+''.''+o.name,s.column_id order by 1,2' -------------------- Declare DB_cursor CURSOR FOR SELECT name FROM sys.databases --select * from sys.databases WHERE STATE = 0 -- and Name not IN ('master','msdb','tempdb','model','DocxPress') and Name not IN ('msdb','tempdb','model','DocxPress') Open DB_cursor Fetch next from DB_cursor into @DBName While @@FETCH_STATUS = 0 begin --select @DBName as '@DBName'; Set @SQL_String1 = 'USE [' + @DBName + ']' set @SQL_String1 = @SQL_String1 + @SQL_String2 EXEC sp_executesql @SQL_String1; -- insert into @Column_Info select * from