473,811 Members | 3,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List of columns from tables across databases.

Hey guys,

Couldn't find this anywhere in google.

I want a list of all database column names for a specific table/view
from across database.

I tried this...
-----------------------------------------------------
Select *
From Information_Sch ema.Columns

-----------------------------------------------------

I also tried this...

-----------------------------------------------------
select syscolumns.name , sysobjects.name , * from syscolumns, sysobjects
where
sysobjects.id = syscolumns.id
and (sysobjects.xty pe='U' or sysobjects.xtyp e='S')
-----------------------------------------------------

These queries return information about the CURRENT database.

But, if I want to do it ACROSS database or across servers.. how can I
do this?

I will express my gratitude to everyone who is kind enough to answer
this question. (I've been stuck with this problem for a while now.)

Thanks!

OhMyGaw!

Jul 23 '05 #1
6 13229
Query other databases using the three-part name:

SELECT *
FROM database_name.i nformation_sche ma.columns

SELECT C.name, O.name, *
FROM database_name.d bo.syscolumns AS C,
database_name.d bo.sysobjects AS O
WHERE O.id = C.id
AND (O.xtype='U' OR O.xtype='S')

Assuming you have set up a linked server you can query other servers with
the four-part name:

SELECT *
FROM server_name.dat abase_name.info rmation_schema. columns

SELECT C.name, O.name, *
FROM server_name.dat abase_name.dbo. syscolumns AS C,
server_name.dat abase_name.dbo. sysobjects AS O
WHERE O.id = C.id
AND (O.xtype='U' OR O.xtype='S')

In each case the tables are distinct objects so if you want to combine
results from multiple databases either use a UNION or write a loop that
cycles through each DB. There is actually an undocumented proc that will
access each DB in turn:

EXEC sp_msforeachdb 'USE ? SELECT DB_NAME()'

This is something you should avoid in persistent code because it won't
necessarily be supported in future but it may help you if this is just a
one-off exercise.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2
Query other databases using the three-part name:

SELECT *
FROM database_name.i nformation_sche ma.columns

SELECT C.name, O.name, *
FROM database_name.d bo.syscolumns AS C,
database_name.d bo.sysobjects AS O
WHERE O.id = C.id
AND (O.xtype='U' OR O.xtype='S')

Assuming you have set up a linked server you can query other servers with
the four-part name:

SELECT *
FROM server_name.dat abase_name.info rmation_schema. columns

SELECT C.name, O.name, *
FROM server_name.dat abase_name.dbo. syscolumns AS C,
server_name.dat abase_name.dbo. sysobjects AS O
WHERE O.id = C.id
AND (O.xtype='U' OR O.xtype='S')

In each case the tables are distinct objects so if you want to combine
results from multiple databases either use a UNION or write a loop that
cycles through each DB. There is actually an undocumented proc that will
access each DB in turn:

EXEC sp_msforeachdb 'USE ? SELECT DB_NAME()'

This is something you should avoid in persistent code because it won't
necessarily be supported in future but it may help you if this is just a
one-off exercise.

--
David Portas
SQL Server MVP
--
Jul 23 '05 #3
David,

Thanks for your response. This is exactly what I was looking for.

SELECT *
FROM database_name.i nformation_sche *ma.columns

I was trying the following

SELECT *
FROM database_name.d atabase_owner.i nformation_sche *ma.columns

BTW, where is this information_sch ema table? I couldn't find it when
I looked for it.

Thanks a bunch.

Jul 23 '05 #4
David,

Thanks for your response. This is exactly what I was looking for.

SELECT *
FROM database_name.i nformation_sche *ma.columns

I was trying the following

SELECT *
FROM database_name.d atabase_owner.i nformation_sche *ma.columns

BTW, where is this information_sch ema table? I couldn't find it when
I looked for it.

Thanks a bunch.

Jul 23 '05 #5
Information_sch ema is a "schema" rather than a table. You can find the
definitions of the info schema views in Master.

In SQL Server 2000 "schema" is synonymous with "owner" and the
information_sch ema is implemented as a sort of virtual owner name that
points to the views in Master. SQL Server 2005 implements schemas
properly in a way that's consistent with other products and with the
SQL definition of the term.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #6
Information_sch ema is a "schema" rather than a table. You can find the
definitions of the info schema views in Master.

In SQL Server 2000 "schema" is synonymous with "owner" and the
information_sch ema is implemented as a sort of virtual owner name that
points to the views in Master. SQL Server 2005 implements schemas
properly in a way that's consistent with other products and with the
SQL definition of the term.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
7391
by: Nikola Pecigos | last post by:
Hi, I have the following problem: We have an Oracle 9.2 with one table "document" which contains a path to the filesystem. If I want to index these files (HTML, PDF, World, Excel, etc.), I have to use the datastore type "FILE_DATASTORE". Another table "lng_text" stores the titles and descriptions for multiple languages for each row in table "document".
5
3502
by: newtophp2000 | last post by:
I have been using the following query to identify the IDENTITY columns in a given table. (The query is inside an application.) select column_name from information_schema.columns where table_schema = 'user_a' and table_name = 'tab_a' and columnproperty(object_id(table_name), column_name, 'IsIdentity') = 1 This works. When "user_a" performs the query, everything is OK.
0
398
by: OhMyGaw | last post by:
Hey guys, Couldn't find this anywhere in google. I want a list of all database column names for a specific table/view from across database. I tried this... ----------------------------------------------------- Select *
8
4339
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
3
2552
by: gregory.sharrow | last post by:
I need to secure a datawarehouse table at the row level based on 1 to many keys on that table. A user should only see the rows they have access to. I need to be able to figure out which rows they have access to using a single sql statement and it cannot be dynamic SQL or a stored procedure (this is a limitation based on the reporting tool we use). The conditions can be any combination of "and" and "or" operators. I have seen posts (and...
2
7873
by: Patrick Fisher | last post by:
I am using the following module code to display in a List Box all attached tables that start with tblProducts i.e. tblProductsSpain or tblProductsFrance etc I have other code which enables the user to enter a new table name, the code then creates the table in the attached back end database and automatically links it to the front end. My problem is that the list box does not display the new tables until I close the program and restart...
13
2495
by: scorpion53061 | last post by:
Very urgent and I am very close but need a little help to get me over the edge........ I need to write these columns to a html file with each row containing these columns (seperated by breaks). Currently this code write all columns to a single row which works but is not what the boss wants. If anyone has suggestions how you would do a report like this I very much would like to hear them as well. vb.net windows app. ...
0
1406
by: JB | last post by:
Hi All, I'm writing an application that connects to various databases via ODBC. I'd like to get a list of all the available Schemas and Tables in a Database. It looks like the GetSchema function is what I need, however there seem to be slight differences between various drivers. For instance when calling GetSchema("Tables") the SQL Server ODBC driver returns the following columns:
1
1156
by: Shrek | last post by:
I have a stored sript that works across a number of different databases at the clients sites. In order for this to work the script creates a global temporary table that is calibrated according to the servers/databases regional settings SET @DatabaseCollation = convert(sysname,DatabasePropertyEx(db_name(),'Collation')) SET @SQL = 'CREATE TABLE ##TableStructure (TableName varchar(100) COLLATE ' + @DatabaseCollation + ....... ) EXECUTE...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9214
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5565
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3879
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3027
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.