Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Automatically create scripts for Tables & Stored Procedures in SQL Server 2008?

I know when making modifications to Tables or SP's, you generally right click on the entity and select Modify. There is also a menu option in the popup menu that says "Script Table as..." or "Script Stored Procedure as..." and then the sub-menu item of "Create In...". When you select "Create In...", it creates an editable SQL script. Is it possible to automate that for each Table/SP rather than doing it one at a time for each one?

Thanks!
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Yes. Instead of right-click on the table, try it on the database, then chose Tasks / Generate Scripts...
Now you can chose which objects you want to be scripted. Just follow the wizard.
Not that I'm aware of in SQL 2008, but using Visual Studio 2010 you can create a SQL Data Project
User generated image
Then go to Schema Compare, point to any database as a source, then point to any other database as a destination, and you can with one button-click script out all objects from source to destination.
What do you mean by automate? Do you want to do this at some interval and save the output in some files? Is it for some kind of source control purpose?
Avatar of BlakeMcKenna

ASKER

Let's say you right click on a Table Object and the menu pops up. You select "Script Table as"/"Create To"/"File". That will produce SQL Code to a file of your choice. Instead of doing that for each object, is there a way to be able to do that for all Objects within a specific Database?

It's essentially scripting out all the Tables, Stored Procedures, etc. into a File, Clibboard, etc.
Hi Jim,

I think I've almost got it. My problem is that there are no other DB's I can choose as a destination and I don't have "Create" privileges to create one.
ASKER CERTIFIED SOLUTION
Avatar of Zberteoc
Zberteoc
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow...that was awesome!!!!

Thanks so much!
>Right Click on the database name > Tasks > Generate Scripts > Next > ...

Very handy... thanks for posting this.
It sure helped me!!!