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!
BlakeMcKennaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
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.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Not that I'm aware of in SQL 2008, but using Visual Studio 2010 you can create a SQL Data Project
Visual Studio 2010, SQL Server Database Project
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.
0
ZberteocCommented:
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?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

BlakeMcKennaAuthor Commented:
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.
0
BlakeMcKennaAuthor Commented:
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.
0
ZberteocCommented:
In Management Studio Object Explorer:

Right Click on the database name > Tasks > Generate Scripts > Next > Leave on "Select Entire Database and all database objects" (if you choose the other oprion you can specify group and/or individual objects) > Next > Leave on "Save to File" and "Single File", choose a file name and location > Next Next> Finish or Close.

Done.

You may want to go into Advance settings before you save that file and under the table preferences make sure the indexes, unique keys, triggers are set to True.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
Wow...that was awesome!!!!

Thanks so much!
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Right Click on the database name > Tasks > Generate Scripts > Next > ...

Very handy... thanks for posting this.
0
BlakeMcKennaAuthor Commented:
It sure helped me!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.