Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

« Dynamic column names and fields in SSRS (Custom Matrix)Adding time offsets passed in to a datetime to generate localized datetime »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

There seems to be a little bit of confusion on how to script out the database. The correct answer is of course: just run all the scripts you have in source control :-)

So for those who do not use/have source control I will show you how to do it

Logically you would think that this would be the way: Right click on the database --> Script Database As --> CREATE To and then pick your choice. See also image below


Script database

What that will do is just create the database and not much else, here is what the script might look like

  1. USE [master]
  2. GO
  3.  
  4. /****** Object:  Database [AdventureWorks]    Script Date: 06/30/2009 15:04:19 ******/
  5. CREATE DATABASE [AdventureWorks] ON  PRIMARY
  6. ( NAME = N'AdventureWorks_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks_Data.mdf' , SIZE = 174080KB , MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB )
  7.  LOG ON
  8. ( NAME = N'AdventureWorks_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\AdventureWorks_Log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 16384KB )
  9. GO
  10.  
  11. ALTER DATABASE [AdventureWorks] SET COMPATIBILITY_LEVEL = 100
  12. GO
  13.  
  14. IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
  15. BEGIN
  16. EXEC [AdventureWorks].[dbo].[SP_FULLTEXT_DATABASE] @ACTION = 'enable'
  17. END
  18. GO

What you have to do is actually this: Right click on your database-->Tasks-->Generate Scripts


Script Wizard

Select the database you want to script and make sure you check the option at the bottom that says Script all objects in the selected database. See image below


Script all objects in the selected database

That is all, click next a couple of times and review your options and you are set




*** If you have a SQL related question try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum

About the Author

User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
Social SitingsTwitterFacebookLinkedInHomePageLTD RSS Feed
1040 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

4 comments

Comment from: Nate [Visitor]
Thanks for the tip! Do you know if this can be scripted or if it has to be done through the SQL Management Studio GUI?
07/01/09 @ 10:28
Comment from: SQLDenis [Member] Email
Nate, you can use Server Management Objects (SMO) to script it out also (that is what the GUI uses behind the scenes anyway)
07/01/09 @ 10:31
Comment from: onpnt [Member] Email
*****
Nate, You can also see an example of SMO in action here
http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/MSSQLServerAdmin/smo-script-index-and-fk-s-on-a-database

What Denis showed is really a task that would take a bit of effort in development in SMO though. I recommend and perform the same types of automated scripts like you are thinking of on specific objects and manually make script backups with exactly the same steps Denis shows. Developing that much in SMO is very time consuming but if you did it, might be worth it in the long run and future usage

07/01/09 @ 16:56
Comment from: TSQLDeveloper [Member] Email
*****
Hi Denis,
With SQl2008 users can script data as well which is a great easiness for developers.

Have a look at :
http://www.kodyaz.com/articles/sql-server-script-data-with-generate-script-wizard.aspx
07/14/09 @ 04:25

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)