Move DB/LOG files - Detach/Attach - Problemattach database - verify - detach from a script or a batch...

Does dual boot harm a laptop battery or reduce its life?

Summoning A Technology Based Demon

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

Is it okay for me to decline a project on ethical grounds?

What Marvel character has this 'W' symbol?

Unknown indication below upper stave

Prove if n is an odd integer, then 3n is odd.

Was Donald Trump at ground zero helping out on 9-11?

Blank spaces in a font

Self-deportation of American Citizens from US

How can Paypal know my card is being used in another account?

Do the books ever say oliphaunts aren’t elephants?

How to store my pliers and wire cutters on my desk?

How to efficiently shred a lot of cabbage?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

To find islands of 1 and 0 in matrix

Why did some Apollo missions carry a grenade launcher?

Why is softmax function used to calculate probabilities although we can divide each value by the sum of the vector?

What is more environmentally friendly? An A320 or a car?

Piece of chess engine, which accomplishes move generation

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

How to have poached eggs in "sphere form"?

Would people understand me speaking German all over Europe?

How does the Thief's Fast Hands feature interact with mundane and magical shields?



Move DB/LOG files - Detach/Attach - Problem


attach database - verify - detach from a script or a batch fileWhat Are the Log File Names?What are the risks of copying MDF/LDF files without detaching the DB first?Database cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recoveryCan we create a stored procedure to copy detached .mdf and .ldf files from original location to new location?What is the recommended method to move databases?Moving TempDB data and log filesMake a newer version of the LDF-file work with an older version of the MDF-fileDo I need to detach a database to attach it?Do NDF files move with Alter Database automatically






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I wanted to move the MDF/LDF file locations for a DB. From what I read I found I should use Detach/Attach and not just take the DB off line and relocate the files. I did just that and used the below to Re-Attach the DB.



CREATE DATABASE MyAdventureWorks   
ON (FILENAME = 'C:MySQLServerAdventureWorks2012_Data.mdf'),
(FILENAME = 'C:MySQLServerAdventureWorks2012_Log.ldf')
FOR ATTACH;
GO


Of course using my new file locations which used two separate volumes and not the location moving from.



BUUUT, all this did was put the files back on the original volume that I did not specify. It also put the DB in a READ ONLY state.



Any help would be appreciated.



Thanks



SQL Server 2016










share|improve this question









New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















  • I also had USE MASTER and GO at the beginning of the SQL Statement.

    – Dennis
    8 hours ago











  • Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

    – Dennis
    8 hours ago











  • You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

    – Aaron Bertrand
    8 hours ago




















1















I wanted to move the MDF/LDF file locations for a DB. From what I read I found I should use Detach/Attach and not just take the DB off line and relocate the files. I did just that and used the below to Re-Attach the DB.



CREATE DATABASE MyAdventureWorks   
ON (FILENAME = 'C:MySQLServerAdventureWorks2012_Data.mdf'),
(FILENAME = 'C:MySQLServerAdventureWorks2012_Log.ldf')
FOR ATTACH;
GO


Of course using my new file locations which used two separate volumes and not the location moving from.



BUUUT, all this did was put the files back on the original volume that I did not specify. It also put the DB in a READ ONLY state.



Any help would be appreciated.



Thanks



SQL Server 2016










share|improve this question









New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






















  • I also had USE MASTER and GO at the beginning of the SQL Statement.

    – Dennis
    8 hours ago











  • Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

    – Dennis
    8 hours ago











  • You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

    – Aaron Bertrand
    8 hours ago
















1












1








1








I wanted to move the MDF/LDF file locations for a DB. From what I read I found I should use Detach/Attach and not just take the DB off line and relocate the files. I did just that and used the below to Re-Attach the DB.



CREATE DATABASE MyAdventureWorks   
ON (FILENAME = 'C:MySQLServerAdventureWorks2012_Data.mdf'),
(FILENAME = 'C:MySQLServerAdventureWorks2012_Log.ldf')
FOR ATTACH;
GO


Of course using my new file locations which used two separate volumes and not the location moving from.



BUUUT, all this did was put the files back on the original volume that I did not specify. It also put the DB in a READ ONLY state.



Any help would be appreciated.



Thanks



SQL Server 2016










share|improve this question









New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I wanted to move the MDF/LDF file locations for a DB. From what I read I found I should use Detach/Attach and not just take the DB off line and relocate the files. I did just that and used the below to Re-Attach the DB.



CREATE DATABASE MyAdventureWorks   
ON (FILENAME = 'C:MySQLServerAdventureWorks2012_Data.mdf'),
(FILENAME = 'C:MySQLServerAdventureWorks2012_Log.ldf')
FOR ATTACH;
GO


Of course using my new file locations which used two separate volumes and not the location moving from.



BUUUT, all this did was put the files back on the original volume that I did not specify. It also put the DB in a READ ONLY state.



Any help would be appreciated.



Thanks



SQL Server 2016







sql-server sql-server-2016






share|improve this question









New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 9 hours ago









Randi Vertongen

7,2553 gold badges10 silver badges31 bronze badges




7,2553 gold badges10 silver badges31 bronze badges






New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 9 hours ago









DennisDennis

61 bronze badge




61 bronze badge




New contributor



Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Dennis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • I also had USE MASTER and GO at the beginning of the SQL Statement.

    – Dennis
    8 hours ago











  • Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

    – Dennis
    8 hours ago











  • You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

    – Aaron Bertrand
    8 hours ago





















  • I also had USE MASTER and GO at the beginning of the SQL Statement.

    – Dennis
    8 hours ago











  • Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

    – Dennis
    8 hours ago











  • You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

    – Aaron Bertrand
    8 hours ago



















I also had USE MASTER and GO at the beginning of the SQL Statement.

– Dennis
8 hours ago





I also had USE MASTER and GO at the beginning of the SQL Statement.

– Dennis
8 hours ago













Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

– Dennis
8 hours ago





Did not do anything prior to detaching the DB. Detached DB, copied and relocated files, renamed original files, used the SQL Statement to attach, specifying the new file locations.

– Dennis
8 hours ago













You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

– Aaron Bertrand
8 hours ago







You should use backup/restore with replace/move, or modify/offline/online, not detach/attach, IMHO.

– Aaron Bertrand
8 hours ago












3 Answers
3






active

oldest

votes


















3














The correct (and preferred) way in my opinion should be




  1. Use alter database....MODIFY FILE - This will update system catalog.

  2. Offline the database

  3. Physically move the files to the new location that you specified in step 1.

  4. Online the database


I have written a script to rename a database - db name and the files -logical and physical and you can use that logic to adjust it as per your requirements.



Note: Before doing any detach/attach, you should take a full backup of the database. See Bad Habits: Using MDF/LDF Files .. from Aaron Bertrand.






share|improve this answer

































    1














    Usually the steps are:




    1. ALTER DATABASE MyAdventureWorks SET OFFLINE WITH ROLLBACK IMMEDIATE


    2. Move the files to the new location


    3. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks',filename=N'D:SQLHomeDBDataMyAdventureWorks.mdf')

    4. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks_log',filename=N'D:SQLHomeDBDataMyAdventureWorks_log.ldf')

    5. ALTER DATABASE MyAdventureWorks SET ONLINE


    Just change the path to the new location and replace if needed name='MyAdventureWorks', and name='MyAdventureWorks_log', as they are the database logical files names.



    Check out this reference.






    share|improve this answer










    New contributor



    osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















    • Result of step 3 tells me DB does not exist.

      – Dennis
      7 hours ago











    • you cannot offline a database and then change system catalog. See my answer for correct sequence.

      – Kin Shah
      7 hours ago











    • Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

      – osiris_v6
      7 hours ago





















    0














    The code you pasted in your question looks like you just copied/pasted the whole statement from the docs. You indicate later that you used "new file locations", but it's unclear if you actually did everything you needed to, especially since what you're doing doesn't seem to be working. Try posting your exact code, with specifics as much as possible.



    Microsoft's SQL Docs do cover this topic, as I'm sure you know.



    In particular, though, they specifically offer ALTER DATABASE as the standard intra-DB relocation method:




    In SQL Server, you can move the data, log, and full-text catalog files
    of a user database to a new location by specifying the new file
    location in the FILENAME clause of the ALTER DATABASE statement. This
    method applies to moving database files within the same instance SQL
    Server. To move a database to another instance of SQL Server or to
    another server, use backup and restore or detach and attach
    operations.




    It sounds like you're NOT moving between instances or servers, so ALTER DATABASE should suffice - anything else is just overkill.



    To re-summarize the docs:




    1. Take database offline


    2. Move files to new location


    3. Run SQL statement(s) telling SQL server the new file location ex. ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_pathos_file_name' );


    4. Bring database back online






    share








    New contributor



    sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "182"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      Dennis is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244146%2fmove-db-log-files-detach-attach-problem%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      The correct (and preferred) way in my opinion should be




      1. Use alter database....MODIFY FILE - This will update system catalog.

      2. Offline the database

      3. Physically move the files to the new location that you specified in step 1.

      4. Online the database


      I have written a script to rename a database - db name and the files -logical and physical and you can use that logic to adjust it as per your requirements.



      Note: Before doing any detach/attach, you should take a full backup of the database. See Bad Habits: Using MDF/LDF Files .. from Aaron Bertrand.






      share|improve this answer






























        3














        The correct (and preferred) way in my opinion should be




        1. Use alter database....MODIFY FILE - This will update system catalog.

        2. Offline the database

        3. Physically move the files to the new location that you specified in step 1.

        4. Online the database


        I have written a script to rename a database - db name and the files -logical and physical and you can use that logic to adjust it as per your requirements.



        Note: Before doing any detach/attach, you should take a full backup of the database. See Bad Habits: Using MDF/LDF Files .. from Aaron Bertrand.






        share|improve this answer




























          3












          3








          3







          The correct (and preferred) way in my opinion should be




          1. Use alter database....MODIFY FILE - This will update system catalog.

          2. Offline the database

          3. Physically move the files to the new location that you specified in step 1.

          4. Online the database


          I have written a script to rename a database - db name and the files -logical and physical and you can use that logic to adjust it as per your requirements.



          Note: Before doing any detach/attach, you should take a full backup of the database. See Bad Habits: Using MDF/LDF Files .. from Aaron Bertrand.






          share|improve this answer













          The correct (and preferred) way in my opinion should be




          1. Use alter database....MODIFY FILE - This will update system catalog.

          2. Offline the database

          3. Physically move the files to the new location that you specified in step 1.

          4. Online the database


          I have written a script to rename a database - db name and the files -logical and physical and you can use that logic to adjust it as per your requirements.



          Note: Before doing any detach/attach, you should take a full backup of the database. See Bad Habits: Using MDF/LDF Files .. from Aaron Bertrand.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 8 hours ago









          Kin ShahKin Shah

          55.2k4 gold badges85 silver badges198 bronze badges




          55.2k4 gold badges85 silver badges198 bronze badges




























              1














              Usually the steps are:




              1. ALTER DATABASE MyAdventureWorks SET OFFLINE WITH ROLLBACK IMMEDIATE


              2. Move the files to the new location


              3. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks',filename=N'D:SQLHomeDBDataMyAdventureWorks.mdf')

              4. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks_log',filename=N'D:SQLHomeDBDataMyAdventureWorks_log.ldf')

              5. ALTER DATABASE MyAdventureWorks SET ONLINE


              Just change the path to the new location and replace if needed name='MyAdventureWorks', and name='MyAdventureWorks_log', as they are the database logical files names.



              Check out this reference.






              share|improve this answer










              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















              • Result of step 3 tells me DB does not exist.

                – Dennis
                7 hours ago











              • you cannot offline a database and then change system catalog. See my answer for correct sequence.

                – Kin Shah
                7 hours ago











              • Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

                – osiris_v6
                7 hours ago


















              1














              Usually the steps are:




              1. ALTER DATABASE MyAdventureWorks SET OFFLINE WITH ROLLBACK IMMEDIATE


              2. Move the files to the new location


              3. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks',filename=N'D:SQLHomeDBDataMyAdventureWorks.mdf')

              4. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks_log',filename=N'D:SQLHomeDBDataMyAdventureWorks_log.ldf')

              5. ALTER DATABASE MyAdventureWorks SET ONLINE


              Just change the path to the new location and replace if needed name='MyAdventureWorks', and name='MyAdventureWorks_log', as they are the database logical files names.



              Check out this reference.






              share|improve this answer










              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






















              • Result of step 3 tells me DB does not exist.

                – Dennis
                7 hours ago











              • you cannot offline a database and then change system catalog. See my answer for correct sequence.

                – Kin Shah
                7 hours ago











              • Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

                – osiris_v6
                7 hours ago
















              1












              1








              1







              Usually the steps are:




              1. ALTER DATABASE MyAdventureWorks SET OFFLINE WITH ROLLBACK IMMEDIATE


              2. Move the files to the new location


              3. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks',filename=N'D:SQLHomeDBDataMyAdventureWorks.mdf')

              4. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks_log',filename=N'D:SQLHomeDBDataMyAdventureWorks_log.ldf')

              5. ALTER DATABASE MyAdventureWorks SET ONLINE


              Just change the path to the new location and replace if needed name='MyAdventureWorks', and name='MyAdventureWorks_log', as they are the database logical files names.



              Check out this reference.






              share|improve this answer










              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              Usually the steps are:




              1. ALTER DATABASE MyAdventureWorks SET OFFLINE WITH ROLLBACK IMMEDIATE


              2. Move the files to the new location


              3. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks',filename=N'D:SQLHomeDBDataMyAdventureWorks.mdf')

              4. ALTER DATABASE MyAdventureWorks MODIFY FILE (name='MyAdventureWorks_log',filename=N'D:SQLHomeDBDataMyAdventureWorks_log.ldf')

              5. ALTER DATABASE MyAdventureWorks SET ONLINE


              Just change the path to the new location and replace if needed name='MyAdventureWorks', and name='MyAdventureWorks_log', as they are the database logical files names.



              Check out this reference.







              share|improve this answer










              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              share|improve this answer



              share|improve this answer








              edited 8 hours ago





















              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.








              answered 8 hours ago









              osiris_v6osiris_v6

              193 bronze badges




              193 bronze badges




              New contributor



              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




              New contributor




              osiris_v6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.


















              • Result of step 3 tells me DB does not exist.

                – Dennis
                7 hours ago











              • you cannot offline a database and then change system catalog. See my answer for correct sequence.

                – Kin Shah
                7 hours ago











              • Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

                – osiris_v6
                7 hours ago





















              • Result of step 3 tells me DB does not exist.

                – Dennis
                7 hours ago











              • you cannot offline a database and then change system catalog. See my answer for correct sequence.

                – Kin Shah
                7 hours ago











              • Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

                – osiris_v6
                7 hours ago



















              Result of step 3 tells me DB does not exist.

              – Dennis
              7 hours ago





              Result of step 3 tells me DB does not exist.

              – Dennis
              7 hours ago













              you cannot offline a database and then change system catalog. See my answer for correct sequence.

              – Kin Shah
              7 hours ago





              you cannot offline a database and then change system catalog. See my answer for correct sequence.

              – Kin Shah
              7 hours ago













              Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

              – osiris_v6
              7 hours ago







              Check database logical file names. This should help: USE MyAdventureWorks GO SELECT [Name] AS LogicalName, [filename] AS PhysicalFile FROM sys.sysfiles

              – osiris_v6
              7 hours ago













              0














              The code you pasted in your question looks like you just copied/pasted the whole statement from the docs. You indicate later that you used "new file locations", but it's unclear if you actually did everything you needed to, especially since what you're doing doesn't seem to be working. Try posting your exact code, with specifics as much as possible.



              Microsoft's SQL Docs do cover this topic, as I'm sure you know.



              In particular, though, they specifically offer ALTER DATABASE as the standard intra-DB relocation method:




              In SQL Server, you can move the data, log, and full-text catalog files
              of a user database to a new location by specifying the new file
              location in the FILENAME clause of the ALTER DATABASE statement. This
              method applies to moving database files within the same instance SQL
              Server. To move a database to another instance of SQL Server or to
              another server, use backup and restore or detach and attach
              operations.




              It sounds like you're NOT moving between instances or servers, so ALTER DATABASE should suffice - anything else is just overkill.



              To re-summarize the docs:




              1. Take database offline


              2. Move files to new location


              3. Run SQL statement(s) telling SQL server the new file location ex. ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_pathos_file_name' );


              4. Bring database back online






              share








              New contributor



              sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.


























                0














                The code you pasted in your question looks like you just copied/pasted the whole statement from the docs. You indicate later that you used "new file locations", but it's unclear if you actually did everything you needed to, especially since what you're doing doesn't seem to be working. Try posting your exact code, with specifics as much as possible.



                Microsoft's SQL Docs do cover this topic, as I'm sure you know.



                In particular, though, they specifically offer ALTER DATABASE as the standard intra-DB relocation method:




                In SQL Server, you can move the data, log, and full-text catalog files
                of a user database to a new location by specifying the new file
                location in the FILENAME clause of the ALTER DATABASE statement. This
                method applies to moving database files within the same instance SQL
                Server. To move a database to another instance of SQL Server or to
                another server, use backup and restore or detach and attach
                operations.




                It sounds like you're NOT moving between instances or servers, so ALTER DATABASE should suffice - anything else is just overkill.



                To re-summarize the docs:




                1. Take database offline


                2. Move files to new location


                3. Run SQL statement(s) telling SQL server the new file location ex. ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_pathos_file_name' );


                4. Bring database back online






                share








                New contributor



                sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.
























                  0












                  0








                  0







                  The code you pasted in your question looks like you just copied/pasted the whole statement from the docs. You indicate later that you used "new file locations", but it's unclear if you actually did everything you needed to, especially since what you're doing doesn't seem to be working. Try posting your exact code, with specifics as much as possible.



                  Microsoft's SQL Docs do cover this topic, as I'm sure you know.



                  In particular, though, they specifically offer ALTER DATABASE as the standard intra-DB relocation method:




                  In SQL Server, you can move the data, log, and full-text catalog files
                  of a user database to a new location by specifying the new file
                  location in the FILENAME clause of the ALTER DATABASE statement. This
                  method applies to moving database files within the same instance SQL
                  Server. To move a database to another instance of SQL Server or to
                  another server, use backup and restore or detach and attach
                  operations.




                  It sounds like you're NOT moving between instances or servers, so ALTER DATABASE should suffice - anything else is just overkill.



                  To re-summarize the docs:




                  1. Take database offline


                  2. Move files to new location


                  3. Run SQL statement(s) telling SQL server the new file location ex. ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_pathos_file_name' );


                  4. Bring database back online






                  share








                  New contributor



                  sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  The code you pasted in your question looks like you just copied/pasted the whole statement from the docs. You indicate later that you used "new file locations", but it's unclear if you actually did everything you needed to, especially since what you're doing doesn't seem to be working. Try posting your exact code, with specifics as much as possible.



                  Microsoft's SQL Docs do cover this topic, as I'm sure you know.



                  In particular, though, they specifically offer ALTER DATABASE as the standard intra-DB relocation method:




                  In SQL Server, you can move the data, log, and full-text catalog files
                  of a user database to a new location by specifying the new file
                  location in the FILENAME clause of the ALTER DATABASE statement. This
                  method applies to moving database files within the same instance SQL
                  Server. To move a database to another instance of SQL Server or to
                  another server, use backup and restore or detach and attach
                  operations.




                  It sounds like you're NOT moving between instances or servers, so ALTER DATABASE should suffice - anything else is just overkill.



                  To re-summarize the docs:




                  1. Take database offline


                  2. Move files to new location


                  3. Run SQL statement(s) telling SQL server the new file location ex. ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_pathos_file_name' );


                  4. Bring database back online







                  share








                  New contributor



                  sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.







                  share


                  share






                  New contributor



                  sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  answered 6 mins ago









                  sp88sp88

                  1




                  1




                  New contributor



                  sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




                  New contributor




                  sp88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                      Dennis is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      Dennis is a new contributor. Be nice, and check out our Code of Conduct.













                      Dennis is a new contributor. Be nice, and check out our Code of Conduct.












                      Dennis is a new contributor. Be nice, and check out our Code of Conduct.
















                      Thanks for contributing an answer to Database Administrators Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244146%2fmove-db-log-files-detach-attach-problem%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...