3

I have create script which is automatically generated by Scripter.Script() method. But if want to get rid of file paths included in the script. Which property is need to be set while using Scripter class to generate script ?

SQL Script:

CREATE DATABASE [ContactManager] ON  PRIMARY 
( NAME = N'ContactManager', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\ContactManager.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'ContactManager_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\ContactManager.ldf' , SIZE = 5184KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

but now I want to generate script without primary statement like below:

CREATE DATABASE [ContactManager] GO 
2
  • CREATE DATABASE ContactManager; is a valid statement. The primary statement is optional. If you dont specify the file names SQL will just use the database name. Commented Jan 25, 2013 at 6:00
  • @NathanSkerl kindly refer the edited question Commented Jan 25, 2013 at 7:08

1 Answer 1

4

ScriptingOptions.NoFileGroup should suppress the additional filegroup clauses.

More info here.

Also, it seems that simply calling db.Script() without the property enabled omits the filegroup anyways, so I am not positive this will work for you without seeing your code.

See my example below:

Microsoft.SqlServer.Management.Smo.Server srv = new Server(".");
Microsoft.SqlServer.Management.Smo.Database db = new Database(srv, "Yak");       

System.Collections.Specialized.StringCollection statements = db.Script();

Console.WriteLine(statements);

ScriptingOptions so = new ScriptingOptions();
so.NoFileGroup = false;


foreach (string s in db.Script(so))
{
      Console.WriteLine(s);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.