From this Q+A I learned how to attach a database, i.e. a set of mdf/ldf files, to SQL Server.
Basically you have to put the files in a specific location, C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\
What is the rationale for this? How can you change it an why should or shouldn't you do this?
Surely this is not a big deal at all for small databases, but for large ones, is this good practice?
Related
I have .mdf files that are backups of several databases, and I would like to know if it is possible to attach these files at once.
If it is also possible, for example via PHP code, I also feel free to explore.
Does MS SQL Server Express save one database per file (like SQLite, which I cannot use)?
I am asking because I want the users of my app to be able to easily exchange databases.
So, several files would make the whole procedure too hard, which is why I would use another DB then.
SQL Express uses 2 files per database one with the extension MDF and another with the extension LDF. You'll need both for your database to work. I have never tried to copy the files from one machine to another. I normally backup the files from one machine and restore to another machine and overwrite a db that already exists.
That said it looks like you might be able to copy the files from machine A to machine B and then on machine B, with SQL manager
Connect to the SQL Server (localhost or whatever)
Right click Databases folder
Left click Attach, Add
Point to the MDF you want to start using
and you should be good to go.
SQL Server Express software is not in 1 file. However you could have the database data in a file. You may want to consider SQL Server CE. SQL CE databases reside in a single .sdf file which can be up to 4 GB in size. See more here: WIKI-Expres-CE.
In our company, we work under the Team Foundation server 2008. By default the databases destination is C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA.
The problem is that the C drive is small and we are always running out of space.
I am thinking to move the databases from the C drive to D drive, but I am not sure what are the consequences of such action.
Any help is very appreciated.
Moving the database to a different drive won't have any affect on how you access TFS through Visual Studio. You can simply detach and re-attach the database files in a different location. See these instructions for doing so.
Edit: Note that there are quite a few databases that need to be moved. Here's an additional resource that you'll want to refer to as well.
You should just be able to move them as you would move and other SQL database (probably best detaching, copying and re-attaching at their new location). I cannot think of any problems with moving them.
I don't have any experience in SQL databases.
I want to use Microsoft SQL server and i need to ask two questions:
I want to know what are the disadvantage and advantage of saving the data in the mdf file.
Is there some easy way to 'copy' the data that i saved in the mdf file to the regular table ?
1) Question doesn't make sense: All data is stored in .mdf or .ndf data files (in reality the extension doesn't matter, it's just a convention)
2) You seem to be mixing the concept of a table and a data file. Backups are used to create safe copies of your data. The tables you see in SSMS are stored in data files (via filegroups).
If you don't know anything about SQL Server, you should start by finding a good book (and go to a good training course) to understand the basic concepts. The documentation is very extensive, but it's really a reference and not a learning tool.
Having said that, have you read the documentation on files and filegroups in SQL Server? All data in SQL Server is stored in .mdf (and possibly .ndf) files. Unless you're using SQL Server Compact, I believe.
And what are "regular tables"? Are you perhaps using Access as a front-end to SQL Server?
My system is for development, and I run a local copy of sql server 2005. I want to move all the database files out of program files, and put in a better location on another partition. To do this would you simply detach all the databases in SSMS, move the .mdf and .ldf files with windows explorer, then reattach?
That should work.
http://support.microsoft.com/kb/224071
Yes, detach and re-attach them. If you are going to move the system databases also, that will take some special effort. Instructions for that can be found on MSDN.
http://msdn.microsoft.com/en-us/library/ms345408(SQL.90).aspx
Probably this is what you are looking for. I would want to write my answer here but I am too lazy to do that, but I am sending you to my blog post regarding Moving Data File in SQL Server;
http://dbalink.wordpress.com/2008/11/06/how-to-moving-data-files/