Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Information of all Tables and all columns in a dat

Author  Topic 

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2012-03-05 : 22:25:09


I am trying to get all the columns in all the tables underlying in a database.

I have used this query but getting no rows.


sp_MSForEachDB @command1='USE ?;

SELECT Table_Catalog, Table_Schema, Table_Name, Column_Name, Data_Type, Character_Maximum_Length
FROM INFORMATION_SCHEMA.COLUMNS
WHERE Data_Type = '''' AND COLUMN_NAME like ''%%'''

Any Solution thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-06 : 10:07:51
What's the name of the database?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-06 : 10:22:29
Maybe this is what you want



SET NOCOUNT ON

SELECT * INTO ##my_INFO_SCHEMA_Cols
FROM INFORMATION_SCHEMA.COLUMNS
WHERE 1=0

DECLARE myCursor99 CURSOR
FOR
SELECT name FROM sys.databases WHERE state_desc = 'ONLINE'

DECLARE @name varchar(256), @sql varchar(8000)

OPEN myCursor99

FETCH NEXT FROM myCursor99 INTO @name
SET @sql = 'SET NOCOUNT ON; INSERT INTO ##my_INFO_SCHEMA_Cols SELECT * FROM ' + @name + '.information_schema.columns;'
EXEC(@sql)

WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM myCursor99 INTO @name
SET @sql = 'INSERT INTO ##my_INFO_SCHEMA_Cols SELECT * FROM ' + @name + '.information_schema.columns;'
EXEC(@sql)
END

CLOSE myCursor99
DEALLOCATE myCursor99

SELECT * FROM ##my_INFO_SCHEMA_Cols

DROP TABLE ##my_INFO_SCHEMA_Cols
GO




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

dbalearner
Constraint Violating Yak Guru

272 Posts

Posted - 2012-03-06 : 16:02:24
Thanks Brett, I made a little change to get the desired database by making Offline to those database which are not required and thereafter Online.

Many thanks.
Go to Top of Page
   

- Advertisement -