Long Database name when attaching MDF file

286 Views Asked by At

I'm attaching an MDF file to my local SQL server for my tests that I'm running with MSTEST and it is creating a database with a really long and annoying name that looks something like this

7E7051D0DEE46DEE6531EF012DC110F4_ORK\MYPROJECT.OBJECTS\TESTRESULTS\MYNAME_MYCOMPUTERNAME 2011-03-01 15_46_50\OUT\DATABASE.MDF

Is there a way to specify how this database will be named? Not that it should be the same every test, but I want to make these names more meaningful.

Ideas?

Thx in advance!

2

There are 2 best solutions below

0
On BEST ANSWER

I can't recall the syntax for attaching a database (nor can I generate it on this PC :(.), but in SSMS you can use the Attach database dialog and select a new database name, then click the "Script" button to generate the SQL, you should be able to modify that to your needs.

0
On

The reason it looks like that is that its using the filepath as the database name and the filepath is greater than 128 characters. The name can only be at 128 characters as that is the max limit for an identifier in SQL Server.