I want to find all column names in all tables in all databases. Is there a query that can do that for me? The database is Microsoft SQL Server 2000.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
Minor refinement on KM's solution for those like me who've got collation fun on their DB server....
(Still living in hope that we'll find a way to do this that can be wrapped into a view.)
To all: Thanks for all the post and comments some are good, but some are better.
The first big script is good because it is delivers just what is needed. The fastest and most detailed is the one suggestion for selecting from INFORMATION_SCHEMA.COLUMNS..
My need was to find all the errant columns of approximately the same name and Several databases.. Sooo, I made my versions of both (see below) ...Either of these two below script work and deliver the goods in seconds.
The assumption in other posts on this link, is that the first code example can be used successfully with for-each-database, is to me, not desirable. This is because the information is within the specific database and the simple use of the "fedb" doesn't produce the correct results, it simply doesn't give access. SOOO to that is why I use a CURSOR to collect the databases and ignore those that are Off-line, which in this case, a utility script, it is a good use of same.
Bottom Line, I read everyone's post, incorporated all the correction from the posts and made what are two very eloquent scripts from others good works. I listed both below and have also placed the script file on my public folder at OneDrive.com which you can access with this link: http://1drv.ms/1vr8yNX
Enjoy ! Hank Freeman
Senior Level - SQL Server DBA - Data Architect
Try them separately...
user @KM say best Answer.
I Use This :
I just realized that the following query would give you all column names from the table in your database (SQL SERVER 2017)
OR SIMPLY
If you do not care about duplicated names.
Another option is SELECT Column names from
INFORMATION_SCHEMA
It is usually more interesting to have the TableName as well as the ColumnName ant the query below does just that.
And the results would look like
You must set your current database name with
USE [db_name]
before this query.