SQLServer 2005 生成所有 INDEX 作为 CREATE 语句?
我有两个具有相同结构的数据库,但其中一个缺少索引(我想我已经错过了),我的意思是该表还没有任何索引。
我计划为具有索引的数据库生成 CREATE INDEX,但在 Management Studio 中找不到任何可用的方法,是的,我们可以为表、视图等生成脚本,但我只需要编写 INDEXES 脚本,而不是其他任何内容。
我知道如果我们使用 IF EXIST 生成脚本可以解决,所以如果对象已经存在,它不会重新创建,但再次为了简单起见,我只想编写索引的脚本。
I have two database with same structures, but one of them is missing INDEXES (i think i've missed out), i mean the table didn't have any INDEXES yet.
I was plan to generate CREATE INDEX for the database which have indexes but can't found any method available in Management Studio, yes we can generate script for tables, view, etc, but i was only need to script the INDEXES not anything else.
I know if we generate a script using IF EXIST can be solution, so if object already exist it doesn't recreate, but again for simplicity shake, i just want script the INDEXES.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
或者只是右键单击 Management Studio 中的索引,然后选择“将索引脚本编写为 - 创建到 -”,然后根据需要选择。
Try this:
Or just right-click on an index in Management Studio and select "Script Index as - Create To -" and then as appropriate.
不仅仅满足您对索引的需求,但保持多个数据库同步结构的一个好方法是使用 Redgate 的 SQL Compare、AdeptSQL Diff 或类似工具。 这些将向您显示两个数据库之间的差异,并生成甚至运行所需的脚本以使它们同步。 比尝试手动执行此操作要容易得多。
Not specific to just your need for Indexes, but a good way to keep multiple DBs in sync structure wise is to use a tool such as Redgate's SQL Compare, or AdeptSQL Diff, or similar. These will show you the differences between 2 databases and generate and even run the required scripts to get them into sync. Much easier than trying to do this manually.
查看 http://samsudeenb.blogspot .com/2007/11/scripts-to-drop-and-recreate-indexes-in.html - 我认为这就是您正在寻找的。
或者 - 正如另一个答案也表明的那样 - 您可能想投资 Redgate 这样的工具。
Check out http://samsudeenb.blogspot.com/2007/11/scripts-to-drop-and-recreate-indexes-in.html - I think that is what you're looking for.
Or - as another answer also suggests - you might want to invest in a tool like Redgate.