我在共享托管服务器上有一个实时数据库。 我正在对我的网站代码进行一些重大更改,并且我想修复我在最初设计数据库时犯的一些愚蠢错误。 这些更改涉及更改大量字段的大小,以及正确执行表之间的引用完整性。 如果可能的话,我想在本地测试服务器和远程服务器上进行更改。
我应该指出,虽然我对编写复杂的查询来处理数据相当满意,但我在没有图形界面的情况下修改数据库结构的经验很少。
我可以在 Visual Studio 数据库资源管理器中访问远程数据库,但除了数据操作之外不能将其用于任何其他用途。 我昨晚安装了 Sql Management Studio Express,在 40 多次崩溃之后我放弃了 - 我什至无法修补这个该死的东西。
远程服务器是 SQL 2005 / MyLittleAdmin Web 界面可用。
所以我的问题是完成这些改变的最佳方法是什么。 我可以在远程服务器上使用图形界面吗? 如果没有,是否有一种简单的方法可以将数据库复制到本地计算机,修复它,然后重新上传? 最后,如果以上都不可行,是否有人有关于通过查询修复引用完整性的不错信息的链接?
抱歉,这个问题有些笼统——我觉得我让这件事变得比应有的困难得多,但经过整晚的搜索/尝试,我什么也没得到。 先谢谢您的帮助。 对此,我真的非常感激。
……还有谁有时间机器可以借给我吗——我需要为此痛斥过去的自己。
I have a live database on a shared hosting server. I am making some major changes to my site's code and I would like to fix some stupid mistakes I made in initially designing the database. These changes involve altering the size of a large number of fields, and enforcing referential integrity between tables properly. I would like to make the changes on both my local test server and the remote server if possible.
I should note that while I'm fairly comfortable with writing complex queries to handle data, I have very little experience modifying database structure without a graphical interface.
I can access the remote database in the visual studio database explorer but I can not use that for anything other than data manipulation. I installed Sql Management Studio express last night and after 40+ crashes I gave up - I couldn't even patch the damn thing.
The remote server is SQL 2005 / The MyLittleAdmin web interface is available.
So my question is what is the best way to accomplish these changes. Is there a graphical interface I can use on the remote server? If not is there an easy way to copy the database to my local machine, fix it, and re upload? Finally if none of the above are viable does anyone have links to a decent info on fixing referential integrity via query?
Sorry for the somewhat general question - I feel like I am making this far harder than it should be but after searching / trying all night i haven't gotten anywhere. Thanks in advance for the help. I really appreciate it.
...Also does anyone have a time machine I can borrow- I need to go kick my past self's ass for this.
发布评论
评论(1)
通常托管提供商允许您备份和恢复数据库,因此完成移动的最简单方法是备份实时数据库,下载备份文件,在本地恢复,执行所有更改,备份本地数据库,上传然后在实时服务中恢复它。 在此期间,您的站点应处于管理关闭状态,以便在您执行此操作时它不会继续更新数据。 您必须确保您的本地 SQL 实例与托管提供商完全相同的构建版本 (@@version),否则您的本地 SQL 可能会升级数据库结构,并且您将无法将其恢复回托管提供商 (否则,如果您的版本早于主机,您将无法在本地服务器上恢复)。 MSDN BOL 有关于如何使用备份/恢复复制数据库。
备份/恢复的替代方法是分离/附加数据库,但我不建议这样做,因为您需要移动两个 MDF和 LDF 同步,而且它们的大小也比备份大。
这假设您可以以向导的方式对本地副本进行所有架构更改,即。 快速且正确。 当然,这并不容易。 推荐的方法是及时准备一个脚本,该脚本应用达到新模式所需的所有转换。 有一些工具,例如 SQL Diff、SQL 比较, SQL Delta 等可以生成这样的脚本。 Visual Studio 数据库版也可以做到这一点。
我将如何执行此操作,如下所示:
在我的项目中,我总是依赖脚本来部署和升级数据库。 事实上,我使用数据库扩展属性来存储应用程序部署模式的“版本”,并且在我的代码中,我只需前滚将模式带到我的最新版本的所有脚本。 我的博客上有一篇文章描述了这种技术: 版本控制和您的数据库。
Usually hosting providers allow you to backup and restore your database, so the easiest way to accomplish the move is to backup your live DB, download the backup file, restore it locally, do all the changes, do a backup of the local db, upload it, then restore it in the live service. Your site should be placed on an administrative shutdown during this time so it does not continue to update the data while you're doing this operations. You have to make sure your local SQL instance is exactly at the same build version (@@version) like the hosting provider, otherwise your local SQL may upgrade the database structure and you'll be unable to restore it back on the hosting provider (or you'll be unable to restore in on your local server if your version is earlier than the host's). The MSDN BOL has a detailed guid on how to Copy Databases using Backup/Restore.
An alternative to backup/restore is to detach/attach the database, but I do not recommend this because you need to move both the MDF and the LDF in sync, and they're also larger in size than a backup.
This assumes you can do all the schema changes on your local copy in a wizardly manner, ie. fast and correct. Of course, that is not easy. The recommended way is to prepare in time a script that applies all the transformations needed to reach the new schema. There are tools like SQL Diff, SQL Compare, SQL Delta and other that can generate such a script. Also Visual Studio Database Edition can do this.
How I would do this would be like this:
In my projects I always rely on scripts to deploy and upgrade the database. In fact I use the database extended properties to store a 'version' of my application deployed schema and in my code I simply roll forward all the scripts that bring the schema to my last version. I have an article on my blog describing this technique: Version Control and your Database.