简体   繁体   English

SQL Server MDF文件

[英]SQL Server MDF file

I am working on a website that has access data from a database (sql server). 我正在一个从数据库(sql server)访问数据的网站上工作。 It will also be adding, updating deleting records in the database. 它还将添加,更新删除数据库中的记录。 It seems like there is an MDF file that gets created containing the database schema and all the records I guess? 好像有一个MDF文件被创建,包含数据库模式和我猜的所有记录? Once development is complete and I want to move this database to a real server then all I need to do is move this MDF file to the real server and that is it? 一旦开发完成并且我想将这个数据库移动到一个真实的服务器,那么我需要做的就是将这个MDF文件移动到真实的服务器上,就是这样吗? is it that simple? 这么简单吗? or not really? 还是不是真的?

Also, I hope the MDF file is not a read-only file and can be updated/modified or is it? 另外,我希望MDF文件不是只读文件,可以更新/修改或是吗?

Yes, the MDF data file (and the associated *.LDF transaction log file) contains all the database objects that make up your system. 是的,MDF数据文件(以及关联的* .LDF事务日志文件)包含组成系统的所有数据库对象。

And yes, you can definitely detach a database (an .MDF/.LDF file pair) from your (dev) SQL Server, copy it onto another "real" Production SQL Server, and re-attach it there, without loss of data or information. 是的,您绝对可以从(de​​v)SQL Server分离数据库(.MDF / .LDF文件对),将其复制到另一个“真正的”生产SQL Server,并在那里重新附加,而不会丢失数据或信息。

Yes, the MDF file is modifyable - through the SQL Server commands and methods. 是的,MDF文件是可修改的 - 通过SQL Server命令和方法。 You should never tamper with the file yourself, directly (flipping bits). 你不应该自己直接篡改文件(翻转位)。 Use SQL Server and its official interfaces (T-SQL, ADO.NET etc.) to work with your data. 使用SQL Server及其官方接口(T-SQL,ADO.NET等)来处理您的数据。

Yes you can do that. 是的,你可以这么做。 Right click the database and click "detach". 右键单击数据库,然后单击“分离”。 Make sure you click the drop connections box and click ok (if you don't do this some errors could occur). 确保单击“删除连接”框并单击“确定”(如果不这样做,可能会发生一些错误)。 You can now move the mdf and ldf files. 您现在可以移动mdf和ldf文件。

However, there is a better way imho. 然而,有一个更好的方式imho。 Instead, create a full backup of the database, copy the backup file, and restore from the backup on the new server. 而是创建数据库的完整备份,复制备份文件,并从新服务器上的备份还原。 Now you have two copies of the database, a development version and a production version. 现在您有两个数据库副本,一个开发版本和一个生产版本。

You will need to take .MDF file as well as .LDF file which will have your logs. 您将需要获取.MDF文件以及将包含您的日志的.LDF文件。 You have to take both mdf and ldf files and attach on the real server. 您必须同时获取mdf和ldf文件并附加到真实服务器上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM