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 (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 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
Right there with Babe
Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)Right there with Babe (755 reputation)

Group: General Forum Members
Points: 755 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
SSC-Addicted
SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)SSC-Addicted (495 reputation)

Group: General Forum Members
Points: 495 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
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1093 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-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38704 Visits: 886
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