How to rename a database including db files

ta5ta5 SwitzerlandPosts: 1,164Member
edited 2011-10-26 in SQL Tips & Tricks
Hi
After renaming a sql db in the ssms, the data files are not affected. What is the best approach do rename also the data files. In our case, it wouldnt be a problem if the database is not online during the rename.
Thanks in advance
Thomas

Answers

  • krikikriki Posts: 8,848Member, Moderator
    Best is:
    -detach DB
    -rename files
    -attach DB using new name (you will need to give the new names because SQL won't find them anymore).
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • ta5ta5 SwitzerlandPosts: 1,164Member
    Thanks Alain, this works. After detach/attach I also changed manually in ssms the name of the filegroups. After that db name, files and filegroups are consistent concerning the name again. Voilà :)
    Regards
    Thomas
  • David_SingletonDavid_Singleton Posts: 5,456Member
    Easier though is to just go to SSMS, right click on the Database and select COPY database. And use the Detach method. There is an option to move or copy. Basically it does the same as Alain is suggesting, except its all automatic and you don't have to think about it.
    David Singleton
  • krikikriki Posts: 8,848Member, Moderator
    Easier though is to just go to SSMS, right click on the Database and select COPY database. And use the Detach method. There is an option to move or copy. Basically it does the same as Alain is suggesting, except its all automatic and you don't have to think about it.
    SSMS keeps surprising me with its hidden treasures!

    [Topic moved from 'SQL General' forum to 'SQL Tips & Tricks' forum]
    Regards,Alain Krikilion
    Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2019: 21 & 22 November 2019, Antwerp (Belgium)
  • David_SingletonDavid_Singleton Posts: 5,456Member
    kriki wrote:
    Easier though is to just go to SSMS, right click on the Database and select COPY database. And use the Detach method. There is an option to move or copy. Basically it does the same as Alain is suggesting, except its all automatic and you don't have to think about it.
    SSMS keeps surprising me with its hidden treasures!

    [Topic moved from 'SQL General' forum to 'SQL Tips & Tricks' forum]

    I found it out yesterday (Thanks Frank). \:D/
    David Singleton
Sign In or Register to comment.