How to rename a database including db files

ta5ta5 SwitzerlandMember Posts: 1,164
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 Member, Moderator Posts: 8,929
    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
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2020: 19 & 20 November 2020, Antwerp (Belgium)
  • ta5ta5 SwitzerlandMember Posts: 1,164
    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 Member Posts: 5,456
    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 Member, Moderator Posts: 8,929
    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
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
    NAV TechDays 2020: 19 & 20 November 2020, Antwerp (Belgium)
  • David_SingletonDavid_Singleton Member Posts: 5,456
    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.