How can i increase datafile dynamically

  • Declare @requied_size as int

    set @requied_size=256

    alter database test modify file(name =test,size=@requied_size MB

    Unfortunately this is not working.What i need to change here?I would like to put variable in Size parameter..

    Thnks,

    Litu

  • Try using dynamic sql.

  • Thanks for your reply.

    Could you give me some example.

  • Do a search on how to use dynamic sql and you should quickly find out how to do it 🙂

  • declare @cmd varchar(max)

    select @cmd = 'alter database text ( size = ' + @required_size

    exec( @cmd)

  • Steve: That looks like it's missing a close-paren on the string. Or am I missing something?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Yes, sorry, was providing the idea there.

    The code should look like:

    declare @cmd varchar(max)

    select @cmd = 'alter database test modify file ( size = ' + @required_size + ' MB)'

    exec( @cmd)

    The idea is that you just build the executable string that you would normally put in code and then execute it.

  • Thnks a lot. 🙂

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply