I have a current database with few hundred tables, say, tables A,B,C... and I want to create the same tables with the same constraints,triggers,indexes, and stats as the original tables.

I know I could use generate script to do this but is there a faster way?

Do I have to rename the "new" tables with different names as well as their constraints,indexes etc?

  • Not that I know of. As for changing the table names, you can perform a substiution over the entire script changing CREATE TABLE my_table to CREATE TABLE prefix_my_table change BLE (BLE + space to BLE + space + prefix). On*nix I'd use sed - doesn't windows have that these days?
    – Vérace
    Commented Sep 28, 2017 at 5:48

1 Answer 1


Right mouse click on your database -> Tasks -> Generate scripts -> Tables:

enter image description here

On the next page select if you want to generate a single file or single file per object and go to Advanced:

enter image description here

Here select constraints, triggers, indexes and what else you want to script

  • sepupic, is this the way to do it? I found another solution here, dba.stackexchange.com/questions/65734/… Does both ways work as well?
    – Lord Jesus
    Commented Sep 28, 2017 at 5:50
  • @CookieMan The link you posted describes how to generate a script for ONE table. You asked how to generate it for ALL your tables. The option described there is applied to another context menu for single table script generation
    – sepupic
    Commented Sep 28, 2017 at 6:25
  • @CookieMan - Also, of course (based on what seems like a follow-up question) using "Script Table as" -> "Create Table" does not appear to have an option to also script the data in the current table; it sounds like that's something you needed.
    – RDFozz
    Commented Sep 28, 2017 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.