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.
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 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-03-06 : 10:22:29
|
Maybe this is what you wantSET NOCOUNT ONSELECT * INTO ##my_INFO_SCHEMA_Cols FROM INFORMATION_SCHEMA.COLUMNS WHERE 1=0DECLARE myCursor99 CURSORFORSELECT name FROM sys.databases WHERE state_desc = 'ONLINE'DECLARE @name varchar(256), @sql varchar(8000)OPEN myCursor99FETCH NEXT FROM myCursor99 INTO @nameSET @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) ENDCLOSE myCursor99DEALLOCATE myCursor99SELECT * FROM ##my_INFO_SCHEMA_Cols DROP TABLE ##my_INFO_SCHEMA_ColsGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
|
|
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. |
|
|
|
|
|