SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Make a list of all tables in all data bases with creation date


Make a list of all tables in all data bases with creation date

Author
Message
kamel Gazzah
kamel Gazzah
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 7
Comments posted to this topic are about the item Make a list of all tables in all data bases with creation date
thadeushuck
thadeushuck
Old Hand
Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)Old Hand (361 reputation)

Group: General Forum Members
Points: 361 Visits: 164
DECLARE @db_name sysname, @SQL nvarchar(max)
--
IF OBJECT_ID('tempdb..#Results') IS NOT NULL
DROP TABLE #Results;
IF OBJECT_ID('tempdb..#Databases') IS NOT NULL
DROP TABLE #Databases;
--
CREATE TABLE #Results (DatabaseName sysname, TableName NVARCHAR(128), crdate datetime);
CREATE TABLE #Databases (databaseName sysname);
--
INSERT INTO #Databases
SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'msdb', 'model');
WHILE (SELECT COUNT(*) FROM #Databases) > 0
BEGIN
SET @db_name = (SELECT TOP 1 databaseName FROM #Databases);
SET @SQL = 'USE ['+@db_name+'];
INSERT INTO #Results Select '''+@db_name+''' as [dbname], name as [tblname], crdate from sysobjects'
--
EXEC (@SQL)
--
DELETE #Databases
WHERE databaseName = @db_name
END;
--
SELECT * from #Results;


just another cursor rewrite for fun..
Dave Vroman
Dave Vroman
Old Hand
Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)Old Hand (335 reputation)

Group: General Forum Members
Points: 335 Visits: 727
Change the statement
DECLARE c CURSOR  FOR


to
DECLARE c CURSOR LOCAL FAST_FORWARD READ_ONLY FOR


and test the speed difference.
Mahmood.BilalB
Mahmood.BilalB
SSC Eights!
SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)SSC Eights! (885 reputation)

Group: General Forum Members
Points: 885 Visits: 163
I have tested the code and it is giving an error. I think end statement is not required at the last line, just comment that out and it works
Iwas Bornready
Iwas Bornready
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21926 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search