2

If I save a table in Management Studio's Table Designer for example, I believe it runs DDL SQL in the background. Is it possible for me to grab this SQL so that I can save it to a file?

  • In SQL Server 2012, once you've changed a table in the designer, you can go to Table Designer > Generate Change Script. Not sure if that option is there on previous versions. – Aaron Bertrand Oct 17 '12 at 0:44
  • Ah, excellent and its in 2008. Please write this up as an answer. – Ian Warburton Oct 17 '12 at 0:50
  • 2
    The long term answer is to become well-versed with T-SQL so you don't rely on GUI. – Thomas Stringer Oct 17 '12 at 0:54
4

Modern versions of SSMS (2008+ at least) allow you to generate a change script once you have made changes to a table using the graphical designer. You go to the menu item Table Designer > Generate Change Script.

enter image description here

That said, I agree with Thomas. In the long term, you should be proficient at T-SQL so that you can write ALTER TABLE scripts without the help of the wizard / graphical designers. They often do things you don't want to do.

  • Yes.. hopefully seeing the scripts will help reduce my dependence on the designer. – Ian Warburton Oct 17 '12 at 1:08
0

You can just go to the table after it is created in SSMS and right click and then select the Script options in the menu.

  • I don't think you can get ALTER statements like that, say, if I add a new column. – Ian Warburton Oct 17 '12 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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