Alter database

  • Hi i have written a code for dynamically taking the path to tempdb files.

    DECLARE @name1 VARCHAR(50)---Instance name

    DECLARE @path VARCHAR(50)----path for temp db

    DECLARE @fileName VARCHAR(256)----File name for destination

    DECLARE @temp varchar(50)

    set @temp='data\'

    DECLARE @temp1 varchar(100)

    set @temp1='tempdb'

    SET @path ='t:\'

    declare @name char(100)

    set @name= cast(( select SERVERPROPERTY('instancename')) AS char)

    set @filename=@path+@name1+'\'+@temp+@temp1

    print @filename

    But i want the changes to be done on the databse.

    Help me out plz.

  • Are you trying to dynamically move the files?

    Why assume the files are in a default location, when you can query sys.database_files to get the exact data?

    - 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

  • Hi,

    Actually when am creating an .ndf file in tempdb..the path is taking the default one but i want the path to be same as that of .mdf and .ldf path.

    So i have written a script for the location as shown above and is succesfull but now i want to make changes to the databse..

    And my question now is How can i make the above changes to the database.

  • Add the Alter Database commands to your string in the variable, and then execute the string.

    declare @Cmd varchar(8000);

    select @Cmd = 'alter database MyDB add file ...' -- put the rest of the command you want in here, including the path

    exec(@Cmd);

    - 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

Viewing 4 posts - 1 through 3 (of 3 total)

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