join the MSSQLTips community

MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

 
SQL Script Generation Programmatically with SMO - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

SQL Script Generation Programmatically with SMO

Last post 09-11-2009 2:21 AM by arshad0384. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 09-09-2009 12:30 AM

    SQL Script Generation Programmatically with SMO

    This post is related to this tip: SQL Script Generation Programmatically with SMO

    http://www.mssqltips.com/tip.asp?tip=1833

  • 09-09-2009 4:58 AM In reply to

    • manish
    • Top 50 Contributor
    • Joined on 12-25-2008
    • India
    • Posts 10

    Re: SQL Script Generation Programmatically with SMO

    Hi Arshad,

    Thank you so much for this valuable information, I tried and its working well for me.

    But I would like to know, how should I do to have the 'USE DATABASE' statement on the top of my script.

     

  • 09-09-2009 7:01 AM In reply to

    Re: SQL Script Generation Programmatically with SMO

    Thanks manish for your nice words and encouragements.

    You can use IncludeDatabaseContext property like this for your requirement.

    scriptOptions.IncludeDatabaseContext = true;

    And result will be like this.

    USE [AdventureWorks]
    SET ANSI_NULLS ON
    SET QUOTED_IDENTIFIER ON
    CREATE TABLE [HumanResources].[EmployeeAddress](
            [EmployeeID] [int] NOT NULL,
            [AddressID] [int] NOT NULL,
            [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
            [ModifiedDate] [datetime] NOT NULL
    ) ON [PRIMARY]

    Hope it helps.

  • 09-11-2009 1:16 AM In reply to

    • ESL
    • Top 200 Contributor
    • Joined on 07-23-2008
    • Posts 3

    Re: SQL Script Generation Programmatically with SMO

    Hi,

    thank's for this article but, do you have the same examples using powershell script please ?

     

    many thank's.

    ESL

  • 09-11-2009 2:21 AM In reply to

    Re: SQL Script Generation Programmatically with SMO

    Hi,

    I think these tips will be helpful for you.

    Using PowerShell with SQL Server Management Objects (SMO)

    http://www.mssqltips.com/tip.asp?tip=1745

    Retrieve a List of SQL Server Databases and their Properties using PowerShell

    http://www.mssqltips.com/tip.asp?tip=1759 

     

Page 1 of 1 (5 items)