2

Is there a way to duplicate a table in SQL-Server? Not just the data like SELECT INTO does but also indexes and maybe keys as well? If I go script table as -> create to it leaves off my index.

If this functionality is not available, why not?

I'm sure this question must have been asked 1000 times but I couldn't find a SQL-Server duplicate, only MYSQL which has CREATE LIKE but SQL-Server doesn't seem to.

Dan
  • 45,079
  • 17
  • 88
  • 157

2 Answers2

1

First go to Tools-> Options. Then go to SQL Server Object Explorer, Scripting. From here you will see all of the scripting options, including creating indexes. Creating indexes is turned off by default for some reason but you can turn it on easily enough.

enter image description here

After this then you can right click on the Script Table - Create to ...

enter image description here

And you should now get your indexes.

Kenneth Fisher
  • 3,692
  • 19
  • 21
0

Just generate a CREATE script in SQL Server Management Studio. This will also include the indexes.

See this dba.se question

Community
  • 1
  • 1
Kermit
  • 33,827
  • 13
  • 85
  • 121
  • I mentioned in my question that I did exactly this (although someone edited it away for whatever reason, I guess they didn't understand). It doesn't create the index as far as I can see. It does create PK though. But not the index. – Dan Aug 02 '13 at 15:08