0

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.

bummi
  • 27,123
  • 14
  • 62
  • 101
Dels
  • 2,375
  • 9
  • 39
  • 59
  • [Generate script of All the indexes in a database](http://stackoverflow.com/questions/9089700/generate-script-of-all-the-indexes-in-a-database) – bummi Dec 02 '14 at 12:23
  • possible duplicate of [Generate CREATE INDEX statements in SQL Server](http://stackoverflow.com/questions/12672006/generate-create-index-statements-in-sql-server) – bummi Dec 02 '14 at 12:23

3 Answers3

1

Try this:

alt text

Or just right-click on an index in Management Studio and select "Script Index as - Create To -" and then as appropriate.

Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
  • yes i know that, infact i already use it... it generate all statement which included table, view(if any), stored procedure (if any), indexes, etc... what i need was only generate indexes – Dels Apr 22 '09 at 12:52
  • It provides a way to choose object types to script. – Anton Gogolev Apr 22 '09 at 13:43
  • yes but it need to create tables script before indexes, no indexes only script – Dels Apr 27 '09 at 03:29
0

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.

schooner
  • 3,047
  • 8
  • 30
  • 39
  • yeah but it's not free, mean another cost, i need this only for a fix (which is my mistake not creating INDEX in second dataase) – Dels Apr 22 '09 at 12:51
0

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.