December 2, 2004 at 1:35 pm
I do this:
Begin CREATE TABLE
tempdb.dbo.DbGrowth ([Servername] [varchar](128),[Databasename] [varchar](128),
[timestamps] [datetime],[fileid] [smallint] NOT NULL ,
[groupid] [smallint] NOT NULL , [int] NOT NULL ,
[maxsize] [int] NOT NULL ,[growth] [int] NOT NULL ,[status] [int] NOT NULL ,
[perf] [int] NOT NULL ,[name] [nchar] (128) ,[filename] [nchar] (260) )
END
BEGIN exec master.dbo.sp_msforeachdb
"insert tempdb.dbo.DbGrowth select @@servername as Servername,'?' as Databasename,getdate() as TimeStams, * from ?.dbo.sysfiles"
END
begin
Create table tempdb.dbo.DiskSpace
(Servername varchar(128), timestamps datetime, Drive varchar(2), MBFree int)
end
begin insert tempdb.dbo.diskspace (Drive,MBFree) exec master.dbo.xp_fixeddrives
end
begin update tempdb.dbo.diskspace set servername = @@servername, timestamps =getdate() end
And get this: (can anybody explain)
Line 1: Incorrect syntax near '-'.
December 2, 2004 at 2:54 pm
I just tried the code you posted and did not receive an error. The message was display after I created the table.
(3 row(s) affected)
(3 row(s) affected)
December 3, 2004 at 4:46 am
Yep,
Ran perfectly first time.
Results in message window:
(4 row(s) affected)
(4 row(s) affected)
Steve
We need men who can dream of things that never were.
December 3, 2004 at 6:01 am
Ron,
Do you have any database with a "-" in it's name ? If yes, you should use from [?].dbo.sysfiles instead of from ?.dbo.sysfiles
Razvan
December 6, 2004 at 7:09 am
Actually, sp_msforeachdb changes the database context to each database as it is processed, so you can do this instead:
exec master.dbo.sp_msforeachdb
"insert tempdb.dbo.DbGrowth select @@servername as Servername, DB_NAME() as Databasename, getdate() as TimeStams, * from sysfiles"
As each database is processed, the equivalent of "USE databasename" is issued. So, you can refer to sysfiles without further qualification.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply