January 7, 2010 at 9:04 am
Restoring database from backup or moving it to another server resets all the creation_date fields (in sys.databases, msdb..backupset etc').
Is there a way i can list creation date of all databases in my sql server?
January 7, 2010 at 9:15 am
sys.objects for a system table in each database? So something like:
SELECT create_date
FROM sys.objects
WHERE name = 'sysrowsets'
Run for each db?
January 7, 2010 at 9:17 am
is there a way i can get dbname,size and original creation date of all databases in the server ?
January 7, 2010 at 9:46 am
You could use a cursor, which is what I might recommend. You could get a list of dbs.
declare mycursor Cursor
FOR
SELECT NAME
FROM sys.databases
DECLARE @name varchar(20)
, @cmd VARCHAR(200)
OPEN Mycursor
FETCH NEXT FROM Mycursor INTO @name
WHILE @@fetch_status = 0
BEGIN
SELECT @cmd = 'select '''+ @name + ''', f.size, o.create_date from ' + @name+'.sys.database_files f inner join ' + @name + '.sys.objects o on f.type_desc = ''rows'' and o.name = ''sysrowsets'''
--SELECT @cmd
EXEC(@cmd)
FETCH NEXT FROM mycursor INTO @name
end
DEALLOCATE mycursor
-- SELECT * FROM sys.database_files
-- SELECT * FROM sysobjects
that's quick and dirty, but it should help. You could insert the data into a temp table inside the cursor, then select it at the end.
January 7, 2010 at 9:54 am
Borrowing Steve's query the below will return DB name and create date
exec sp_msforeachdb 'select ''?'', create_date FROM sys.objects where name = ''sysrowsets'''
Gethyn Elliswww.gethynellis.com
January 7, 2010 at 10:22 am
I dont see any difference, how can i get this in a single list, may be inserting in a temp table ?
Is this date original creation date, does it change when its moved to another server or restored ? The reason i am asking is from this query i am getting 80% of the databases with same date and time.
January 7, 2010 at 10:36 am
The dates for the objects should remain the same across a restore. It does on my test instance.
You can use a temp table to insert the data insert of selecting it in the execute.
January 7, 2010 at 11:25 am
I dont think the date is correct, i get 2005-10-14 01:36:06.690
for all the dataabses in my server. even for the database which i created yesterday.
January 7, 2010 at 12:07 pm
Use this.
select [NAME],CREATE_DATE from master.sys.databases
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
January 7, 2010 at 12:49 pm
Bru
that is not the original date it gets updated when i restore or move it from another server.
July 26, 2011 at 10:07 am
small correction to SSC Eights's script. Adding "use ?"
exec sp_msforeachdb 'use ? select ''?'', create_date FROM sys.objects where name = ''sysrowsets'''
This should give you create date for each database.
July 27, 2011 at 11:05 am
I used this script, and I know from hard notes on the histories, these create dates I see on my server are not correct. Sql 2008 STD RTM.
July 27, 2011 at 11:18 am
Side note: I put [] around the ? like [?] in case there are any dashes or other characters in db names. We have a couple such as My-Database and the code will fail without it.
July 27, 2011 at 11:46 am
Thanks. I use that also in cases like you mentioned, but I see no errors, just really wromng dates. Like most are all the same date and time, with a few different, but with years before the servers even existed, etc.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply