views:

23

answers:

2

It works well if I write the query like this:

ALTER DATABASE [test] MODIFY FILE ( 
  NAME = N'test_log', SIZE = 3456KB, 
  MAXSIZE = 6789999KB, FILEGROWTH = 2345KB)

But it is a problem, if I try to use parameters:

ALTER DATABASE [@DbName] MODIFY FILE ( 
  NAME = N'@LogFileName', SIZE = @InitialSize,
  MAXSIZE = @MaxSize , FILEGROWTH = @FileGrowth)

I know that MS SQL 2008 has auto-convert, but when i use parameters occurs an error. So, my question is: From which type must be the declared parameters, which I use to set the size in MB(@InitialSize, @MaxSize, @FileGrowth)?

A: 

See ALTER DATABASE File and Filegroup Options:

The value can be specified in MB, KB, GB, TB, or percent (%). If a number is specified without an MB, KB, or % suffix, the default is MB.

Bill Karwin
+1  A: 

N'@LogFileName' is incorrect, it represents a string with the value @LogFileName, not a variable.

The default for sizes is MB, but I don't think you can pass in variables. Few DDL statements accept variables. When they do the documentation specifies variable_literal, like in the case of CREATE/ALTER ASSEMBLY, which accepts variables for the assembly bits argument.

Remus Rusanu

related questions